From: miroslav.kovac Date: Tue, 1 Dec 2020 13:16:34 +0000 (+0100) Subject: CopyHistory and yangVersion merge X-Git-Tag: v7.0.0~390 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;ds=inline;h=35536f9802bc1ae6fdf7435cbfed0cee58b47c68;p=yangtools.git CopyHistory and yangVersion merge 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 Signed-off-by: Robert Varga --- diff --git a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BaseCurrentEffectiveStmtCtx.java b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BaseCurrentEffectiveStmtCtx.java index c3ffb9f4ff..f7bbc9c1dd 100644 --- a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BaseCurrentEffectiveStmtCtx.java +++ b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BaseCurrentEffectiveStmtCtx.java @@ -61,7 +61,7 @@ final class BaseCurrentEffectiveStmtCtx> imple @Override public CopyHistory history() { - return delegate.getCopyHistory(); + return delegate.history(); } @Override @@ -139,7 +139,7 @@ final class BaseCurrentEffectiveStmtCtx> imple @Override public YangVersion yangVersion() { - return delegate.getRootVersion(); + return delegate.yangVersion(); } @Override diff --git a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/InferredStatementContext.java b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/InferredStatementContext.java index b0b42a8887..ffc510290f 100644 --- a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/InferredStatementContext.java +++ b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/InferredStatementContext.java @@ -88,7 +88,7 @@ final class InferredStatementContext, E extend InferredStatementContext(final StatementContextBase parent, final StatementContextBase 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() diff --git a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java index b371a06744..2b20710523 100644 --- a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java +++ b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java @@ -178,7 +178,7 @@ abstract class ReactorStmtCtx, E extends Effec } @Override - public final YangVersion getRootVersion() { + public final YangVersion yangVersion() { return getRoot().getRootVersionImpl(); } diff --git a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java index 911e92cd63..bbbd48e146 100644 --- a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java +++ b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java @@ -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) { diff --git a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java index aa0b270214..f742cee5ca 100644 --- a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java +++ b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java @@ -149,7 +149,7 @@ public abstract class StatementContextBase, E } @Override - public CopyHistory getCopyHistory() { + public CopyHistory history() { return copyHistory; } @@ -708,7 +708,7 @@ public abstract class StatementContextBase, 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); diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/XPathSupport.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/XPathSupport.java index a9ac8fa740..8ad738d499 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/XPathSupport.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/XPathSupport.java @@ -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; diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AugmentInferenceAction.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AugmentInferenceAction.java index d5213f94c2..226faa363f 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AugmentInferenceAction.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AugmentInferenceAction.java @@ -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> optPrevCopy = targetCtx.getPreviousCopyCtx(); if (optPrevCopy.isPresent()) { final StmtContext original = optPrevCopy.get(); diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/deviate/AbstractDeviateStatementSupport.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/deviate/AbstractDeviateStatementSupport.java index 048d10bed4..b16661d6b3 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/deviate/AbstractDeviateStatementSupport.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/deviate/AbstractDeviateStatementSupport.java @@ -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 supportedDeviationTargets = - YangValidationBundles.SUPPORTED_DEVIATION_TARGETS.get(deviateTargetCtx.getRootVersion(), + YangValidationBundles.SUPPORTED_DEVIATION_TARGETS.get(yangVersion, deviateSubstatementCtx.publicDefinition()); if (supportedDeviationTargets == null) { diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/uses/UsesStatementSupport.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/uses/UsesStatementSupport.java index a6e0b075d5..351be56bbb 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/uses/UsesStatementSupport.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/uses/UsesStatementSupport.java @@ -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) { diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/BoundStmtCtx.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/BoundStmtCtx.java index 739ca30b3b..147b1ec2f2 100644 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/BoundStmtCtx.java +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/BoundStmtCtx.java @@ -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 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(); } diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveStmtCtx.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveStmtCtx.java index 7e83df46cb..95791adf39 100644 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveStmtCtx.java +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveStmtCtx.java @@ -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(); > @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 Rabbit of Caerbannog. * diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java index 24abd97787..15fb8fb688 100644 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java @@ -37,7 +37,7 @@ import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReferenc * @param Effective Statement representation */ public interface StmtContext, E extends EffectiveStatement> - extends BoundStmtCtx { + extends BoundStmtCtx, StmtContextCompat { @Deprecated(forRemoval = true) default @NonNull StatementDefinition getPublicDefinition() { return publicDefinition(); @@ -187,7 +187,7 @@ public interface StmtContext, 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, 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, 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 index 0000000000..f5b588ff6c --- /dev/null +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextCompat.java @@ -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(); +} diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java index e47b0052ec..ecdcd03eff 100644 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java @@ -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); }