Reformulate StatementContextFactory.createEffective()
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / submodule / AbstractSubmoduleStatementSupport.java
index 193ba16695be564276cd5512d86f0e9a54774f60..55e9a39bd63c6e72ca24da759544d5517665b535 100644 (file)
@@ -23,11 +23,13 @@ import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 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> {
@@ -47,15 +49,14 @@ abstract class AbstractSubmoduleStatementSupport
     @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>
@@ -80,30 +81,26 @@ abstract class AbstractSubmoduleStatementSupport
     @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);
     }
 }