Check if we are operating in a grouping before issuing a warning 98/86898/4
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 14 Jan 2020 16:30:09 +0000 (17:30 +0100)
committerRobert Varga <nite@hq.sk>
Tue, 14 Jan 2020 22:06:45 +0000 (22:06 +0000)
If we are examining a list in a grouping, we should not be issuing
a warning, as we do not know where that grouping is going to be
instantiated.

Once we determine that a warning may be appropriate, walk statement
contexts upwards, searching for a grouping -- if we find one, just
bail out without any warning.

JIRA: YANGTOOLS-957
Change-Id: If54b05cc444f19f56c6f8b4f931d85b0b270b4ac
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

index 91d2e7750ba9ae2c8cdacd390a4ff40f4ae0482b..8449858df7b8cc55ea6328a75561010ad32426bb 100644 (file)
@@ -103,7 +103,7 @@ abstract class AbstractListStatementSupport extends BaseQNameStatementSupport<Li
                 .setUserOrdered(findFirstArgument(substatements, OrderedByEffectiveStatement.class, "system")
                     .equals("user"))
                 .toFlags();
-        if (configuration && keyDefinition.isEmpty()) {
+        if (configuration && keyDefinition.isEmpty() && !inGrouping(ctx)) {
             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 "
                     + "[at {}]", ctx.getStatementArgument(), ref);
@@ -117,6 +117,17 @@ abstract class AbstractListStatementSupport extends BaseQNameStatementSupport<Li
                             elementCountConstraint.orElse(null), original);
     }
 
+    private static boolean inGrouping(final StmtContext<?, ?, ?> ctx) {
+        StmtContext<?, ?, ?> parent = ctx.getParentContext();
+        while (parent != null) {
+            if (parent.getPublicDefinition() == YangStmtMapping.GROUPING) {
+                return true;
+            }
+            parent = parent.getParentContext();
+        }
+        return false;
+    }
+
     @Override
     protected final ListEffectiveStatement createEmptyEffective(
             final StmtContext<QName, ListStatement, ListEffectiveStatement> ctx, final ListStatement declared) {