Migrate rawStatementArgument()/getStatementSourceReference() callers
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / belongs_to / BelongsToStatementSupport.java
index d4f2ff8684f41c1a309147eb3195ba36e927adb5..ce4a243a8c91303e73349d381744a509a16c4fcd 100644 (file)
@@ -9,14 +9,18 @@ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.belongs_to;
 
 import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.findFirstDeclaredSubstatement;
 
+import com.google.common.collect.ImmutableList;
 import java.util.Collection;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStringStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction;
@@ -30,8 +34,8 @@ import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToModuleContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleCtx;
 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNamespaceForBelongsTo;
 
-public final class BelongsToStatementSupport extends
-        AbstractStatementSupport<String, BelongsToStatement, EffectiveStatement<String, BelongsToStatement>> {
+public final class BelongsToStatementSupport
+        extends BaseStringStatementSupport<BelongsToStatement, BelongsToEffectiveStatement> {
     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
             SubstatementValidator.builder(YangStmtMapping.BELONGS_TO).addMandatory(YangStmtMapping.PREFIX).build();
     private static final BelongsToStatementSupport INSTANCE = new BelongsToStatementSupport();
@@ -45,31 +49,12 @@ public final class BelongsToStatementSupport extends
     }
 
     @Override
-    public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
-        return value;
+    public void onPreLinkageDeclared(final Mutable<String, BelongsToStatement, BelongsToEffectiveStatement> ctx) {
+        ctx.addRequiredSource(getSourceIdentifier(ctx));
     }
 
     @Override
-    public BelongsToStatement createDeclared(
-            final StmtContext<String, BelongsToStatement, ?> ctx) {
-        return new BelongsToStatementImpl(ctx);
-    }
-
-    @Override
-    public EffectiveStatement<String, BelongsToStatement> createEffective(
-            final StmtContext<String, BelongsToStatement, EffectiveStatement<String, BelongsToStatement>> ctx) {
-        return new BelongsToEffectiveStatementImpl(ctx);
-    }
-
-    @Override
-    public void onPreLinkageDeclared(final StmtContext.Mutable<String, BelongsToStatement,
-            EffectiveStatement<String, BelongsToStatement>> belongsToCtx) {
-        belongsToCtx.addRequiredSource(getSourceIdentifier(belongsToCtx));
-    }
-
-    @Override
-    public void onLinkageDeclared(final Mutable<String, BelongsToStatement,
-            EffectiveStatement<String, BelongsToStatement>> belongsToCtx) {
+    public void onLinkageDeclared(final Mutable<String, BelongsToStatement, BelongsToEffectiveStatement> belongsToCtx) {
         ModelActionBuilder belongsToAction = belongsToCtx.newInferenceAction(ModelProcessingPhase.SOURCE_LINKAGE);
 
         final SourceIdentifier belongsToSourceIdentifier = getSourceIdentifier(belongsToCtx);
@@ -91,15 +76,33 @@ public final class BelongsToStatementSupport extends
             @Override
             public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
                 if (failed.contains(belongsToPrereq)) {
-                    throw new InferenceException(belongsToCtx.getStatementSourceReference(),
-                        "Module '%s' from belongs-to was not found", belongsToCtx.getStatementArgument());
+                    throw new InferenceException(belongsToCtx.sourceReference(),
+                        "Module '%s' from belongs-to was not found", belongsToCtx.argument());
                 }
             }
         });
     }
 
+    @Override
+    protected BelongsToStatement createDeclared(final StmtContext<String, BelongsToStatement, ?> ctx,
+            final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+        return new RegularBelongsToStatement(ctx.coerceRawStatementArgument(), substatements);
+    }
+
+    @Override
+    protected BelongsToStatement createEmptyDeclared(final StmtContext<String, BelongsToStatement, ?> ctx) {
+        return new EmptyBelongsToStatement(ctx.coerceRawStatementArgument());
+    }
+
+    @Override
+    protected BelongsToEffectiveStatement createEffective(final Current<String, BelongsToStatement> stmt,
+            final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+        return substatements.isEmpty() ? new EmptyBelongsToEffectiveStatement(stmt.declared())
+            : new RegularBelongsToEffectiveStatement(stmt.declared(), substatements);
+    }
+
     private static SourceIdentifier getSourceIdentifier(final StmtContext<String, BelongsToStatement,
-            EffectiveStatement<String, BelongsToStatement>> belongsToCtx) {
+            BelongsToEffectiveStatement> belongsToCtx) {
         return RevisionSourceIdentifier.create(belongsToCtx.coerceStatementArgument());
     }