Disable uses/augment statements of unsupported paths 02/99602/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 6 Feb 2022 18:28:26 +0000 (19:28 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 8 Feb 2022 06:30:16 +0000 (07:30 +0100)
Uses statements should propagate unsupported-by-features statements
as unsupported-to-build statements.

JIRA: YANGTOOLS-1393
Change-Id: Ie373b3f0cf7539219b68d1e7b52f6d348ff246e5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
parser/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/uses/UsesStatementSupport.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1393Test.java [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1393/bar.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1393/baz.yang [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1393/foo.yang [new file with mode: 0644]

index 1fb4613e8522138e438c5b46bafc372e7989dbe4..f2d2f24a8f7da699936424a0e256a97817501caa 100644 (file)
@@ -201,8 +201,13 @@ public final class UsesStatementSupport
         final QNameModule newQNameModule = getNewQNameModule(targetCtx, sourceGrpStmtCtx);
 
         for (StmtContext<?, ?, ?> original : declared) {
-            if (original.isSupportedByFeatures() && shouldCopy(original)) {
-                original.copyAsChildOf(targetCtx, CopyType.ADDED_BY_USES, newQNameModule).ifPresent(buffer::add);
+            if (shouldCopy(original)) {
+                original.copyAsChildOf(targetCtx, CopyType.ADDED_BY_USES, newQNameModule).ifPresent(copy -> {
+                    if (!original.isSupportedByFeatures() || !original.isSupportedToBuildEffective()) {
+                        copy.setUnsupported();
+                    }
+                    buffer.add(copy);
+                });
             }
         }
 
diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1393Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1393Test.java
new file mode 100644 (file)
index 0000000..1e39762
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2022 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.stmt;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public class YT1393Test {
+    @Test
+    public void testUsesAugmentUnsupportedByFeatures() throws Exception {
+        final var module = StmtTestUtils.parseYangSource("/bugs/YT1393/foo.yang", Set.of())
+            .findModuleStatement(QName.create("foo", "foo"))
+            .orElseThrow();
+        assertEquals(4, module.effectiveSubstatements().size());
+    }
+
+    @Test
+    public void testUsesRefineUnsupportedByFeatures() throws Exception {
+        final var module = StmtTestUtils.parseYangSource("/bugs/YT1393/bar.yang", Set.of())
+            .findModuleStatement(QName.create("bar", "bar"))
+            .orElseThrow();
+        assertEquals(5, module.effectiveSubstatements().size());
+    }
+
+    @Test
+    public void testAugmentAugmentUnsupportedByFeatures() throws Exception {
+        final var module = StmtTestUtils.parseYangSource("/bugs/YT1393/baz.yang", Set.of())
+            .findModuleStatement(QName.create("baz", "baz"))
+            .orElseThrow();
+        assertEquals(5, module.effectiveSubstatements().size());
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1393/bar.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1393/bar.yang
new file mode 100644 (file)
index 0000000..ad648ed
--- /dev/null
@@ -0,0 +1,27 @@
+module bar {
+  namespace bar;
+  prefix bar;
+
+  feature foo;
+
+  grouping foo {
+    container foo {
+      if-feature foo;
+      container bar;
+    }
+  }
+
+  uses foo {
+    refine foo/bar {
+      description desc;
+    }
+  }
+
+  container baz {
+    uses foo {
+      refine foo {
+        description desc;
+      }
+    }
+  }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1393/baz.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1393/baz.yang
new file mode 100644 (file)
index 0000000..e37709a
--- /dev/null
@@ -0,0 +1,18 @@
+module baz {
+  namespace baz;
+  prefix baz;
+
+  feature foo;
+
+  container foo;
+
+  augment /foo {
+    container bar {
+      if-feature foo;
+    }
+  }
+
+  augment /foo/bar {
+    container baz;
+  }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1393/foo.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1393/foo.yang
new file mode 100644 (file)
index 0000000..252c893
--- /dev/null
@@ -0,0 +1,20 @@
+module foo {
+  namespace foo;
+  prefix foo;
+
+  feature foo;
+
+  grouping foo {
+    container foo {
+      if-feature foo;
+    }
+  }
+
+  uses foo {
+    augment foo {
+      leaf foo {
+        type string;
+      }
+    }
+  }
+}