CopyHistory and yangVersion merge 84/93984/6
authormiroslav.kovac <miroslav.kovac@pantheon.tech>
Tue, 1 Dec 2020 13:16:34 +0000 (14:16 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 2 Dec 2020 23:39:04 +0000 (00:39 +0100)
history and getCopyHistory together with yangVersion and
getRootVersion can be merged since it is used in both
StmtContext and EffectuveStmtCtx.Current.

Since a few methods still do not have a proper new name,
introduce StmtContextCompat to host these.

JIRA: YANGTOOLS-1185
Change-Id: I7b63a96e6d00ef3378544ce9bd0970f3857e7358
Signed-off-by: miroslav.kovac <miroslav.kovac@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
14 files changed:
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BaseCurrentEffectiveStmtCtx.java
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/InferredStatementContext.java
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/XPathSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AugmentInferenceAction.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/deviate/AbstractDeviateStatementSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/uses/UsesStatementSupport.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/BoundStmtCtx.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveStmtCtx.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextCompat.java [new file with mode: 0644]
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java

index c3ffb9f4ff1cd233cb53c8c179c563dfe599225b..f7bbc9c1ddc439cee81cf7d8be8c66e6cf1eff4c 100644 (file)
@@ -61,7 +61,7 @@ final class BaseCurrentEffectiveStmtCtx<A, D extends DeclaredStatement<A>> imple
 
     @Override
     public CopyHistory history() {
-        return delegate.getCopyHistory();
+        return delegate.history();
     }
 
     @Override
@@ -139,7 +139,7 @@ final class BaseCurrentEffectiveStmtCtx<A, D extends DeclaredStatement<A>> imple
 
     @Override
     public YangVersion yangVersion() {
-        return delegate.getRootVersion();
+        return delegate.yangVersion();
     }
 
     @Override
index b0b42a88876496352be32e03227d283895d5d041..ffc510290f93baaf8023465b56f847047f781e1d 100644 (file)
@@ -88,7 +88,7 @@ final class InferredStatementContext<A, D extends DeclaredStatement<A>, E extend
 
     InferredStatementContext(final StatementContextBase<?, ?, ?> parent, final StatementContextBase<A, D, E> prototype,
             final CopyType myCopyType, final CopyType childCopyType, final QNameModule targetModule) {
-        super(prototype.definition(), CopyHistory.of(myCopyType, prototype.getCopyHistory()));
+        super(prototype.definition(), CopyHistory.of(myCopyType, prototype.history()));
         this.parent = requireNonNull(parent);
         this.prototype = requireNonNull(prototype);
         this.argument = targetModule == null ? prototype.argument()
index b371a067447893b18662223174a9ea5372f21866..2b2071052394c57da179dfd6f7e67b7638d0031f 100644 (file)
@@ -178,7 +178,7 @@ abstract class ReactorStmtCtx<A, D extends DeclaredStatement<A>, E extends Effec
     }
 
     @Override
-    public final YangVersion getRootVersion() {
+    public final YangVersion yangVersion() {
         return getRoot().getRootVersionImpl();
     }
 
index 911e92cd63057410a25a2178d951516855669ae9..bbbd48e1461493d793a7f18f4aa9ad1c9de3f6a0 100644 (file)
@@ -146,9 +146,9 @@ final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeha
          */
         if (root == null) {
             root = new RootStatementContext<>(this, def, ref, argument);
-        } else if (!RootStatementContext.DEFAULT_VERSION.equals(root.getRootVersion())
+        } else if (!RootStatementContext.DEFAULT_VERSION.equals(root.yangVersion())
                 && inProgressPhase == ModelProcessingPhase.SOURCE_LINKAGE) {
-            root = new RootStatementContext<>(this, def, ref, argument, root.getRootVersion(),
+            root = new RootStatementContext<>(this, def, ref, argument, root.yangVersion(),
                     root.getRootIdentifier());
         } else {
             final QName rootStatement = root.definition().getStatementName();
@@ -170,7 +170,7 @@ final class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeha
      * @return version of root statement context
      */
     YangVersion getRootVersion() {
-        return root != null ? root.getRootVersion() : RootStatementContext.DEFAULT_VERSION;
+        return root != null ? root.yangVersion() : RootStatementContext.DEFAULT_VERSION;
     }
 
     void startPhase(final ModelProcessingPhase phase) {
index aa0b2702142dbd0f6efc381208c53fb61f5c0025..f742cee5ca13702be2d5bef465e313ff86f43bcd 100644 (file)
@@ -149,7 +149,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     }
 
     @Override
-    public CopyHistory getCopyHistory() {
+    public CopyHistory history() {
         return copyHistory;
     }
 
@@ -708,7 +708,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         }
 
         final StatementDefinitionContext<?, ?, ?> def = new StatementDefinitionContext<>(optImplicit.get());
-        final CopyType type = original.getCopyHistory().getLastOperation();
+        final CopyType type = original.history().getLastOperation();
         final SubstatementContext<?, ?, ?> result = new SubstatementContext(original.getParentContext(), def,
             original.sourceReference(), original.rawArgument(), original.argument(), type);
 
index a9ac8fa740f83c23807975698431466e9b799412..8ad738d499a152f4171c7105c530d1b88d39e37c 100644 (file)
@@ -42,9 +42,9 @@ public final class XPathSupport {
             throw new SourceException(ctx.sourceReference(), e, "Argument \"%s\" is not valid XPath string", xpath);
         }
 
-        if (ctx.getRootVersion().compareTo(parsed.getYangVersion()) < 0) {
+        if (ctx.yangVersion().compareTo(parsed.getYangVersion()) < 0) {
             LOG.warn("{} features required in {} context to parse expression '{}' [at {}]",
-                parsed.getYangVersion().getReference(), ctx.getRootVersion().getReference(), xpath,
+                parsed.getYangVersion().getReference(), ctx.yangVersion().getReference(), xpath,
                 ctx.sourceReference());
         }
         return parsed;
index d5213f94c25d26c7faa7b3dccbf51aa32bcb614c..226faa363fcfe75b79cb59b6f17dcd748d6194cf 100644 (file)
@@ -230,7 +230,7 @@ final class AugmentInferenceAction implements InferenceAction {
 
             // This could be an augmentation stacked on top of a previous augmentation from the same module, which is
             // conditional -- in which case we do not run further checks
-            if (targetCtx.getCopyHistory().getLastOperation() == CopyType.ADDED_BY_AUGMENTATION) {
+            if (targetCtx.history().getLastOperation() == CopyType.ADDED_BY_AUGMENTATION) {
                 final Optional<? extends StmtContext<?, ?, ?>> optPrevCopy = targetCtx.getPreviousCopyCtx();
                 if (optPrevCopy.isPresent()) {
                     final StmtContext<?, ?, ?> original = optPrevCopy.get();
index 048d10bed46ed2c44a76383cf091c1dc02c30aca..b16661d6b3d4193ea9ebddd84c7aae03e9364040 100644 (file)
@@ -378,7 +378,7 @@ abstract class AbstractDeviateStatementSupport
     private static void validateDeviationTarget(final StmtContext<?, ?, ?> deviateSubStmtCtx,
             final StmtContext<?, ?, ?> targetCtx) {
         InferenceException.throwIf(!isSupportedDeviationTarget(deviateSubStmtCtx, targetCtx,
-            targetCtx.getRootVersion()), deviateSubStmtCtx.sourceReference(),
+            targetCtx.yangVersion()), deviateSubStmtCtx.sourceReference(),
             "%s is not a valid deviation target for substatement %s.", targetCtx.argument(),
             deviateSubStmtCtx.publicDefinition().getStatementName());
     }
@@ -386,7 +386,7 @@ abstract class AbstractDeviateStatementSupport
     private static boolean isSupportedDeviationTarget(final StmtContext<?, ?, ?> deviateSubstatementCtx,
             final StmtContext<?, ?, ?> deviateTargetCtx, final YangVersion yangVersion) {
         Set<StatementDefinition> supportedDeviationTargets =
-                YangValidationBundles.SUPPORTED_DEVIATION_TARGETS.get(deviateTargetCtx.getRootVersion(),
+                YangValidationBundles.SUPPORTED_DEVIATION_TARGETS.get(yangVersion,
                         deviateSubstatementCtx.publicDefinition());
 
         if (supportedDeviationTargets == null) {
index a6e0b075d5ea2b43ba7fc745dfab94dcfaf27c58..351be56bbba9a64d5d984be6dfbe4044b047f3e9 100644 (file)
@@ -288,7 +288,7 @@ public final class UsesStatementSupport
         /*
          * In case of Yang 1.1, checks whether features are supported.
          */
-        return !YangVersion.VERSION_1_1.equals(subStmtCtx.getRootVersion()) || subStmtCtx.isSupportedByFeatures();
+        return !YangVersion.VERSION_1_1.equals(subStmtCtx.yangVersion()) || subStmtCtx.isSupportedByFeatures();
     }
 
     private static void performRefine(final Mutable<?, ?, ?> subStmtCtx, final StmtContext<?, ?, ?> usesParentCtx) {
index 739ca30b3b6f69ad5a971822fd7ea74bf43476d4..147b1ec2f23357a88c3430478729d4276bb4e5a2 100644 (file)
@@ -13,6 +13,7 @@ import com.google.common.annotations.Beta;
 import com.google.common.base.VerifyException;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.common.YangVersion;
 
 /**
  * A {@link CommonStmtCtx} which has additionally been bound to a {@link StatementSupport}. It provides
@@ -38,4 +39,11 @@ public interface BoundStmtCtx<A> extends CommonStmtCtx {
     default @NonNull A getArgument() {
         return verifyNotNull(argument(), "Attempted to use non-existent argument of %s", this);
     }
+
+    /**
+     * Return the {@link YangVersion} associated with this statement.
+     *
+     * @return YANG version used to bind this statement
+     */
+    @NonNull YangVersion yangVersion();
 }
index 7e83df46cba8c5565a53f64f32a49729d0db1781..95791adf390c1c33ee7c67705a7dee9413da3b39 100644 (file)
@@ -16,7 +16,6 @@ import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.common.YangVersion;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
@@ -26,7 +25,7 @@ import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
  * Effective view of a {@link StmtContext} for the purposes of creating an {@link EffectiveStatement}.
  */
 @Beta
-public interface EffectiveStmtCtx extends CommonStmtCtx, Immutable {
+public interface EffectiveStmtCtx extends CommonStmtCtx, StmtContextCompat, Immutable {
     /**
      * Return parent of this context, if there is one. All statements except for top-level source statements, such as
      * {@code module} and {@code submodule}.
@@ -84,8 +83,6 @@ public interface EffectiveStmtCtx extends CommonStmtCtx, Immutable {
 
         @NonNull CommonStmtCtx root();
 
-        @NonNull CopyHistory history();
-
         @NonNull D declared();
 
         <K, V, T extends K, N extends IdentifierNamespace<K, V>> @Nullable V getFromNamespace(Class<@NonNull N> type,
@@ -95,8 +92,6 @@ public interface EffectiveStmtCtx extends CommonStmtCtx, Immutable {
 
         @Nullable EffectiveStatement<?, ?> original();
 
-        @NonNull YangVersion yangVersion();
-
         /**
          * Summon the <a href="https://en.wikipedia.org/wiki/Rabbit_of_Caerbannog">Rabbit of Caerbannog</a>.
          *
index 24abd97787d1b5717716484ee2fd7e7d0163afa1..15fb8fb6888be08d272e047533390c8a0df03382 100644 (file)
@@ -37,7 +37,7 @@ import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReferenc
  * @param <E> Effective Statement representation
  */
 public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
-        extends BoundStmtCtx<A> {
+        extends BoundStmtCtx<A>, StmtContextCompat {
     @Deprecated(forRemoval = true)
     default @NonNull StatementDefinition getPublicDefinition() {
         return publicDefinition();
@@ -187,7 +187,7 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     /*
      * FIXME: YANGTOOLS-784: the next three methods are closely related to the copy process:
-     *        - getCopyHistory() is a brief summary of what went on
+     *        - copyHistory() is a brief summary of what went on
      *        - getOriginalContext() points to the CopyHistory.ORIGINAL
      *        - getPreviousCopyCtx() points to the immediate predecessor forming a singly-linked list terminated
      *          at getOriginalContext()
@@ -198,13 +198,6 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
      *        and hence should become arguments to that method.
      */
 
-    /**
-     * Return the executive summary of the copy process that has produced this context.
-     *
-     * @return A simplified summary of the copy process.
-     */
-    CopyHistory getCopyHistory();
-
     /**
      * Return the statement context of the original definition, if this statement is an instantiated copy.
      *
@@ -222,13 +215,6 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     ModelProcessingPhase getCompletedPhase();
 
-    /**
-     * Return version of root statement context.
-     *
-     * @return version of root statement context
-     */
-    @NonNull YangVersion getRootVersion();
-
     /**
      * An mutable view of an inference context associated with an instance of a statement.
      *
diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextCompat.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextCompat.java
new file mode 100644 (file)
index 0000000..f5b588f
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.spi.meta;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNull;
+
+/**
+ * Intermediate compatibility interface between {@link StmtContext} and {@link EffectiveStmtCtx.Current}.
+ */
+@Beta
+public interface StmtContextCompat extends CommonStmtCtx {
+    /**
+     * Return the executive summary of the copy process that has produced this context.
+     *
+     * @return A simplified summary of the copy process.
+     */
+    @NonNull CopyHistory history();
+}
index e47b0052ecfe786424c43e219ba8c66cfdf18167..ecdcd03efff7844af916f75e01e488dd1cc2336b 100644 (file)
@@ -440,7 +440,7 @@ public final class StmtContextUtils {
     }
 
     private static boolean isRelevantForIfFeatureAndWhenOnListKeysCheck(final StmtContext<?, ?, ?> ctx) {
-        return YangVersion.VERSION_1_1.equals(ctx.getRootVersion()) && hasParentOfType(ctx, YangStmtMapping.LIST)
+        return YangVersion.VERSION_1_1.equals(ctx.yangVersion()) && hasParentOfType(ctx, YangStmtMapping.LIST)
                 && findFirstDeclaredSubstatement(ctx.coerceParentContext(), KeyStatement.class) != null;
     }
 
@@ -483,7 +483,7 @@ public final class StmtContextUtils {
                     localName = value;
                     qnameModule = getRootModuleQName(ctx);
                 }
-                if (qnameModule == null && ctx.getCopyHistory().getLastOperation() == CopyType.ADDED_BY_AUGMENTATION) {
+                if (qnameModule == null && ctx.history().getLastOperation() == CopyType.ADDED_BY_AUGMENTATION) {
                     ctx = ctx.getOriginalCtx().orElse(null);
                     qnameModule = getModuleQNameByPrefix(ctx, prefix);
                 }