Fix StatementContextBase.childCopyOf() 70/97870/3
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Oct 2021 12:15:45 +0000 (14:15 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Oct 2021 16:27:27 +0000 (18:27 +0200)
Most of our StmtContext implementations are derived from
StatementContextBase, but notably ReplicaStatementContext is not -- and
we do not handle it during copy operations.

Update the dispatch code to short circuit to replicaAsChildOf(), which
takes care of the details.

JIRA: YANGTOOLS-1346
Change-Id: I65f9713d5c06bbe251a4b27fb0745dd905c36976
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 3b4308a5a4988fb66839c8d2724c13e0ae1b2e9c)

parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java
parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1346Test.java [new file with mode: 0644]
parser/yang-parser-rfc7950/src/test/resources/bugs/YT1346/foo.yang [new file with mode: 0644]

index b54ce1c26c4acc0fe0365b3115a27a6aec390719..9c537eafcac9fbc40222d32006c025a80795b4ae 100644 (file)
@@ -806,8 +806,13 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     public final Mutable<?, ?, ?> childCopyOf(final StmtContext<?, ?, ?> stmt, final CopyType type,
             final QNameModule targetModule) {
         checkEffectiveModelCompleted(stmt);
-        checkArgument(stmt instanceof StatementContextBase, "Unsupported statement %s", stmt);
-        return childCopyOf((StatementContextBase<?, ?, ?>) stmt, type, targetModule);
+        if (stmt instanceof StatementContextBase) {
+            return childCopyOf((StatementContextBase<?, ?, ?>) stmt, type, targetModule);
+        } else if (stmt instanceof ReplicaStatementContext) {
+            return ((ReplicaStatementContext<?, ?, ?>) stmt).replicaAsChildOf(this);
+        } else {
+            throw new IllegalArgumentException("Unsupported statement " + stmt);
+        }
     }
 
     private <X, Y extends DeclaredStatement<X>, Z extends EffectiveStatement<X, Y>> Mutable<X, Y, Z> childCopyOf(
diff --git a/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1346Test.java b/parser/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1346Test.java
new file mode 100644 (file)
index 0000000..57e1a1a
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2021 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.assertNotNull;
+
+import org.junit.Test;
+
+public class YT1346Test {
+    @Test
+    public void testUsesAugmentUsesException() throws Exception {
+        assertNotNull(StmtTestUtils.parseYangSource("/bugs/YT1346/foo.yang"));
+    }
+}
diff --git a/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1346/foo.yang b/parser/yang-parser-rfc7950/src/test/resources/bugs/YT1346/foo.yang
new file mode 100644 (file)
index 0000000..792b3b4
--- /dev/null
@@ -0,0 +1,22 @@
+module foo {
+  namespace foo;
+  prefix foo;
+
+  extension ext {
+    argument arg;
+  }
+
+  grouping foo {
+    container foo;
+  }
+
+  grouping bar {
+    foo:ext bar;
+  }
+
+  uses foo {
+    augment foo {
+      uses bar;
+    }
+  }
+}