Refactor ConfigListWarningNamespace 97/93997/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 1 Dec 2020 21:55:19 +0000 (22:55 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 2 Dec 2020 09:29:13 +0000 (10:29 +0100)
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 <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/list/AbstractListStatementSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/list/ConfigListWarningNamespace.java

index e686a7664cc0e86f0d37ea4b7beb847e32d9a437..bc03fdcd4a7c0ed1bbdab644092d21f66272174e 100644 (file)
@@ -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<QName, ListStatement> stmt) {
-        final StmtContext<QName, ListStatement, ListEffectiveStatement> ctx = stmt.caerbannog();
-        final StmtContext<QName, ListStatement, ListEffectiveStatement> 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);
         }
     }
 
index ed816e12ee10daf6dffdf09f7a91b70ead219e6d..8baf2cdacfbb8b53ddd6744cb3dcac3079dcf28a 100644 (file)
@@ -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<Boolean, Boolean> {
-    NamespaceBehaviour<Boolean, Boolean, @NonNull ConfigListWarningNamespace> BEHAVIOUR =
-            NamespaceBehaviour.statementLocal(ConfigListWarningNamespace.class);
+public interface ConfigListWarningNamespace extends IdentifierNamespace<StatementSourceReference, Boolean> {
+    NamespaceBehaviour<StatementSourceReference, Boolean, @NonNull ConfigListWarningNamespace> BEHAVIOUR =
+            NamespaceBehaviour.global(ConfigListWarningNamespace.class);
 }