import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
abstract class AbstractSubmoduleStatementSupport
extends BaseStatementSupport<UnqualifiedQName, SubmoduleStatement, SubmoduleEffectiveStatement> {
@Override
public final void onPreLinkageDeclared(
final Mutable<UnqualifiedQName, SubmoduleStatement, SubmoduleEffectiveStatement> stmt) {
- stmt.setRootIdentifier(RevisionSourceIdentifier.create(stmt.coerceStatementArgument().getLocalName(),
+ stmt.setRootIdentifier(RevisionSourceIdentifier.create(stmt.coerceRawStatementArgument(),
StmtContextUtils.getLatestRevision(stmt.declaredSubstatements())));
}
@Override
public final void onLinkageDeclared(
final Mutable<UnqualifiedQName, SubmoduleStatement, SubmoduleEffectiveStatement> stmt) {
- final SourceIdentifier submoduleIdentifier = RevisionSourceIdentifier.create(
- stmt.coerceStatementArgument().getLocalName(),
+ final SourceIdentifier submoduleIdentifier = RevisionSourceIdentifier.create(stmt.coerceRawStatementArgument(),
StmtContextUtils.getLatestRevision(stmt.declaredSubstatements()));
final StmtContext<?, SubmoduleStatement, SubmoduleEffectiveStatement>
@Override
protected final SubmoduleStatement createDeclared(final StmtContext<UnqualifiedQName, SubmoduleStatement, ?> ctx,
final ImmutableList<? extends DeclaredStatement<?>> substatements) {
- return new SubmoduleStatementImpl(ctx, substatements);
+ return new SubmoduleStatementImpl(ctx.coerceRawStatementArgument(), ctx.coerceStatementArgument(),
+ substatements);
}
@Override
protected final SubmoduleStatement createEmptyDeclared(
final StmtContext<UnqualifiedQName, SubmoduleStatement, ?> ctx) {
- throw noBelongsTo(ctx);
+ throw noBelongsTo(ctx.getStatementSourceReference());
}
@Override
- protected final SubmoduleEffectiveStatement createEffective(
- final StmtContext<UnqualifiedQName, SubmoduleStatement, SubmoduleEffectiveStatement> ctx,
- final SubmoduleStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
- return new SubmoduleEffectiveStatementImpl(ctx, declared, substatements);
- }
-
- @Override
- protected final SubmoduleEffectiveStatement createEmptyEffective(
- final StmtContext<UnqualifiedQName, SubmoduleStatement, SubmoduleEffectiveStatement> ctx,
- final SubmoduleStatement declared) {
- throw noBelongsTo(ctx);
+ protected SubmoduleEffectiveStatement createEffective(final Current<UnqualifiedQName, SubmoduleStatement> stmt,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ if (substatements.isEmpty()) {
+ throw noBelongsTo(stmt.sourceReference());
+ }
+ return new SubmoduleEffectiveStatementImpl(stmt, substatements);
}
- private static SourceException noBelongsTo(final StmtContext<?, ?, ?> ctx) {
- return new SourceException("No belongs-to declared in submodule", ctx.getStatementSourceReference());
+ private static SourceException noBelongsTo(final StatementSourceReference ref) {
+ return new SourceException("No belongs-to declared in submodule", ref);
}
}