From 0a297e75ee792d3369b6a9fa161aa596c10b9f3d Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 1 Dec 2020 22:55:19 +0100 Subject: [PATCH] Refactor ConfigListWarningNamespace We are using a boolean to suppress warnings for particular statements here. There are two problems here: 1. we can end up accessing the namespace after originalCtx has been built, which is not nice, as it cannot be swept 2. we make poor use of namespace's capabilities (we just hold a boolean) Make ConfigListWarningNamespace a global namespace, hence it end up being hosted BuildGlobalContext, hence is always accessible. Furthermore make the connection that a StatementSourceReference is good enough alias for the statement, hence we can just store those, reducing the number of places where StmtContexts can lurk. JIRA: YANGTOOLS-1184 Change-Id: I31629f73e095301617254be30e10a695d13309ec Signed-off-by: Robert Varga --- .../stmt/list/AbstractListStatementSupport.java | 13 +++++++------ .../stmt/list/ConfigListWarningNamespace.java | 7 ++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/list/AbstractListStatementSupport.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/list/AbstractListStatementSupport.java index e686a7664c..bc03fdcd4a 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/list/AbstractListStatementSupport.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/list/AbstractListStatementSupport.java @@ -44,6 +44,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; 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.source.SourceException; +import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -129,16 +130,16 @@ abstract class AbstractListStatementSupport extends } private static void warnConfigList(final @NonNull Current stmt) { - final StmtContext ctx = stmt.caerbannog(); - final StmtContext warnCtx = ctx.getOriginalCtx().orElse(ctx); - final Boolean warned = warnCtx.getFromNamespace(ConfigListWarningNamespace.class, Boolean.TRUE); + final StatementSourceReference ref = stmt.sourceReference(); + final Boolean warned = stmt.getFromNamespace(ConfigListWarningNamespace.class, ref); // Hacky check if we have issued a warning for the original statement if (warned == null) { - verify(warnCtx instanceof Mutable, "Unexpected context %s", warnCtx); - ((Mutable) warnCtx).addToNs(ConfigListWarningNamespace.class, Boolean.TRUE, Boolean.TRUE); + final StmtContext ctx = stmt.caerbannog(); + verify(ctx instanceof Mutable, "Unexpected context %s", ctx); + ((Mutable) ctx).addToNs(ConfigListWarningNamespace.class, ref, Boolean.TRUE); LOG.info("Configuration list {} does not define any keys in violation of RFC7950 section 7.8.2. While " + "this is fine with OpenDaylight, it can cause interoperability issues with other systems " - + "[defined at {}]", ctx.argument(), warnCtx.sourceReference()); + + "[defined at {}]", stmt.argument(), ref); } } diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/list/ConfigListWarningNamespace.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/list/ConfigListWarningNamespace.java index ed816e12ee..8baf2cdacf 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/list/ConfigListWarningNamespace.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/list/ConfigListWarningNamespace.java @@ -11,9 +11,10 @@ import com.google.common.annotations.Beta; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour; +import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference; @Beta -public interface ConfigListWarningNamespace extends IdentifierNamespace { - NamespaceBehaviour BEHAVIOUR = - NamespaceBehaviour.statementLocal(ConfigListWarningNamespace.class); +public interface ConfigListWarningNamespace extends IdentifierNamespace { + NamespaceBehaviour BEHAVIOUR = + NamespaceBehaviour.global(ConfigListWarningNamespace.class); } -- 2.36.6