BUG-4688: Rename StmtContext.Mutable.addRequiredModule()
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / BelongsToStatementImpl.java
index b208d454ea73f180bcd8b57fafe5780153e4c1f9..3cdfbba48d3ae50f87547ac513789ca6d820cbf0 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 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.util.ModuleIdentifierImpl;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
@@ -23,14 +24,16 @@ 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;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 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.meta.SubstatementValidator;
 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToModuleContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleIdentifier;
 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNamespaceForBelongsTo;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.BelongsEffectiveToStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.BelongsToEffectiveStatementImpl;
 
 public class BelongsToStatementImpl extends AbstractDeclaredStatement<String>
         implements BelongsToStatement {
@@ -63,17 +66,23 @@ public class BelongsToStatementImpl extends AbstractDeclaredStatement<String>
         @Override
         public EffectiveStatement<String, BelongsToStatement> createEffective(
                 final StmtContext<String, BelongsToStatement, EffectiveStatement<String, BelongsToStatement>> ctx) {
-            return new BelongsEffectiveToStatementImpl(ctx);
+            return new BelongsToEffectiveStatementImpl(ctx);
         }
 
         @Override
-        public void onLinkageDeclared(
-                final StmtContext.Mutable<String, BelongsToStatement, EffectiveStatement<String, BelongsToStatement>> belongsToCtx) {
+        public void onPreLinkageDeclared(final StmtContext.Mutable<String, BelongsToStatement,
+                EffectiveStatement<String, BelongsToStatement>> belongsToCtx) {
+            belongsToCtx.addRequiredSource(RevisionSourceIdentifier.create(belongsToCtx.getStatementArgument()));
+        }
+
+        @Override
+        public void onLinkageDeclared(final Mutable<String, BelongsToStatement,
+                EffectiveStatement<String, BelongsToStatement>> belongsToCtx) {
             ModelActionBuilder belongsToAction = belongsToCtx.newInferenceAction(ModelProcessingPhase.SOURCE_LINKAGE);
 
             final ModuleIdentifier belongsToModuleIdentifier = getModuleIdentifier(belongsToCtx);
-            final ModelActionBuilder.Prerequisite<StmtContext<?, ?, ?>> belongsToPrereq = belongsToAction.requiresCtx(
-                belongsToCtx, ModuleNamespaceForBelongsTo.class, belongsToModuleIdentifier.getName(),
+            final Prerequisite<StmtContext<?, ?, ?>> belongsToPrereq = belongsToAction.requiresCtx(belongsToCtx,
+                ModuleNamespaceForBelongsTo.class, belongsToModuleIdentifier.getName(),
                 ModelProcessingPhase.SOURCE_LINKAGE);
 
             belongsToAction.apply(new InferenceAction() {
@@ -97,10 +106,9 @@ public class BelongsToStatementImpl extends AbstractDeclaredStatement<String>
             });
         }
 
-        private static ModuleIdentifier getModuleIdentifier(
-                final StmtContext.Mutable<String, BelongsToStatement, EffectiveStatement<String, BelongsToStatement>> belongsToCtx) {
-            String moduleName = belongsToCtx.getStatementArgument();
-            return ModuleIdentifierImpl.create(moduleName, Optional.empty(),
+        private static ModuleIdentifier getModuleIdentifier(final Mutable<String, BelongsToStatement,
+                EffectiveStatement<String, BelongsToStatement>> belongsToCtx) {
+            return ModuleIdentifierImpl.create(belongsToCtx.getStatementArgument(), Optional.empty(),
                 Optional.of(SimpleDateFormatUtil.DEFAULT_BELONGS_TO_DATE));
         }
 
@@ -121,5 +129,4 @@ public class BelongsToStatementImpl extends AbstractDeclaredStatement<String>
     public PrefixStatement getPrefix() {
         return firstDeclared(PrefixStatement.class);
     }
-
 }