Upstream StmtContextUtils.producesDeclared()
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / augment / AbstractAugmentStatementSupport.java
index 87b690388d5499de6e035c60fd3c531760f86c43..9c938ac6b626a639357cf2bb0271caaccaf74b73 100644 (file)
@@ -48,7 +48,6 @@ 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.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StmtOrderingNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
@@ -88,14 +87,11 @@ abstract class AbstractAugmentStatementSupport
             return;
         }
 
-        final ModelActionBuilder augmentAction = augmentNode.newInferenceAction(
-            ModelProcessingPhase.EFFECTIVE_MODEL);
-        final Prerequisite<StmtContext<SchemaNodeIdentifier, AugmentStatement,
-                AugmentEffectiveStatement>> sourceCtxPrereq =
-                    augmentAction.requiresCtx(augmentNode, ModelProcessingPhase.EFFECTIVE_MODEL);
-        final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> target =
-                augmentAction.mutatesEffectiveCtxPath(getSearchRoot(augmentNode),
-                    ChildSchemaNodeNamespace.class, augmentNode.coerceStatementArgument().getPathFromRoot());
+        final ModelActionBuilder augmentAction = augmentNode.newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
+        augmentAction.requiresCtx(augmentNode, ModelProcessingPhase.EFFECTIVE_MODEL);
+        final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> target = augmentAction.mutatesEffectiveCtxPath(
+            getSearchRoot(augmentNode), ChildSchemaNodeNamespace.class,
+            augmentNode.coerceStatementArgument().getNodeIdentifiers());
 
         augmentAction.apply(new InferenceAction() {
             @Override
@@ -120,7 +116,6 @@ abstract class AbstractAugmentStatementSupport
                 try {
                     copyFromSourceToTarget(augmentSourceCtx, augmentTargetCtx);
                     augmentTargetCtx.addEffectiveSubstatement(augmentSourceCtx);
-                    updateAugmentOrder(augmentSourceCtx);
                 } catch (final SourceException e) {
                     LOG.warn("Failed to add augmentation {} defined at {}",
                         augmentTargetCtx.getStatementSourceReference(),
@@ -128,18 +123,6 @@ abstract class AbstractAugmentStatementSupport
                 }
             }
 
-            private void updateAugmentOrder(final StatementContextBase<?, ?, ?> augmentSourceCtx) {
-                Integer currentOrder = augmentSourceCtx.getFromNamespace(StmtOrderingNamespace.class,
-                    YangStmtMapping.AUGMENT);
-                if (currentOrder == null) {
-                    currentOrder = 1;
-                } else {
-                    currentOrder++;
-                }
-
-                augmentSourceCtx.addToNs(StmtOrderingNamespace.class, YangStmtMapping.AUGMENT, currentOrder);
-            }
-
             @Override
             public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
                 /*
@@ -195,8 +178,8 @@ abstract class AbstractAugmentStatementSupport
                 .setStatus(findFirstArgument(substatements, StatusEffectiveStatement.class, Status.CURRENT))
                 .toFlags();
 
-        return new AugmentEffectiveStatementImpl(declared, flags, StmtContextUtils.getRootModuleQName(ctx),
-            substatements, ctx.getStatementSourceReference(),
+        return new AugmentEffectiveStatementImpl(declared, ctx.coerceStatementArgument(), flags,
+            StmtContextUtils.getRootModuleQName(ctx), substatements, ctx.getStatementSourceReference(),
             (AugmentationSchemaNode) ctx.getOriginalCtx().map(StmtContext::buildEffective).orElse(null));
     }
 
@@ -218,9 +201,8 @@ abstract class AbstractAugmentStatementSupport
 
     static void copyFromSourceToTarget(final StatementContextBase<?, ?, ?> sourceCtx,
             final StatementContextBase<?, ?, ?> targetCtx) {
-        final CopyType typeOfCopy = UsesStatement.class.equals(sourceCtx.coerceParentContext().getPublicDefinition()
-                .getDeclaredRepresentationClass()) ? CopyType.ADDED_BY_USES_AUGMENTATION
-                : CopyType.ADDED_BY_AUGMENTATION;
+        final CopyType typeOfCopy = sourceCtx.coerceParentContext().producesDeclared(UsesStatement.class)
+                ? CopyType.ADDED_BY_USES_AUGMENTATION : CopyType.ADDED_BY_AUGMENTATION;
         /*
          * Since Yang 1.1, if an augmentation is made conditional with a
          * "when" statement, it is allowed to add mandatory nodes.
@@ -278,7 +260,7 @@ abstract class AbstractAugmentStatementSupport
             final StatementContextBase<?, ?, ?> targetCtx, final CopyType typeOfCopy,
             final boolean skipCheckOfMandatoryNodes) {
 
-        if (WhenStatement.class.equals(sourceCtx.getPublicDefinition().getDeclaredRepresentationClass())) {
+        if (sourceCtx.producesDeclared(WhenStatement.class)) {
             return;
         }
 
@@ -288,12 +270,9 @@ abstract class AbstractAugmentStatementSupport
         }
 
         // Data definition statements must not collide on their namespace
-        if (DataDefinitionStatement.class.isAssignableFrom(
-            sourceCtx.getPublicDefinition().getDeclaredRepresentationClass())) {
+        if (sourceCtx.producesDeclared(DataDefinitionStatement.class)) {
             for (final StmtContext<?, ?, ?> subStatement : targetCtx.allSubstatements()) {
-                if (DataDefinitionStatement.class.isAssignableFrom(
-                    subStatement.getPublicDefinition().getDeclaredRepresentationClass())) {
-
+                if (subStatement.producesDeclared(DataDefinitionStatement.class)) {
                     InferenceException.throwIf(
                         Objects.equals(sourceCtx.getStatementArgument(), subStatement.getStatementArgument()),
                         sourceCtx.getStatementSourceReference(),