Convert leaf statement to instantiatedPolicy() 33/94833/7
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Jan 2021 08:37:21 +0000 (09:37 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Jan 2021 13:13:09 +0000 (14:13 +0100)
Leaf statements are not doing anything out of the ordinary, just
the routine instantiated schema three thing. Switch their policy
and add a unit test.

JIRA: YANGTOOLS-1208
Change-Id: I5e38765e76cf8be422f05e6b779ffd54519d6b61
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/leaf/LeafStatementSupport.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1208Test.java [new file with mode: 0644]
yang/yang-parser-rfc7950/src/test/resources/bugs/YT1208/leaf.yang [new file with mode: 0644]

index d24b6f3e111d9e8c2ca4d2f4aa7c01a9e5d826ad..b8c74125c1acb6e31054f32fdd6e5cca83b180ac 100644 (file)
@@ -49,7 +49,7 @@ public final class LeafStatementSupport extends BaseSchemaTreeStatementSupport<L
     private static final LeafStatementSupport INSTANCE = new LeafStatementSupport();
 
     private LeafStatementSupport() {
-        super(YangStmtMapping.LEAF, StatementPolicy.legacyDeclaredCopy());
+        super(YangStmtMapping.LEAF, instantiatedPolicy());
     }
 
     public static LeafStatementSupport getInstance() {
diff --git a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1208Test.java b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT1208Test.java
new file mode 100644 (file)
index 0000000..040b572
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2020 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 static org.junit.Assert.assertSame;
+
+import java.net.URI;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
+
+public class YT1208Test {
+    @Test
+    public void testLeafStatementReuse() throws Exception {
+        final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/leaf.yang")
+            .getModuleStatements()
+            .get(QNameModule.create(URI.create("foo")));
+        assertNotNull(module);
+
+        final NotificationEffectiveStatement notif = module
+            .findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow();
+
+        final LeafEffectiveStatement grpBar = notif
+            .findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow()
+            .findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
+        final LeafEffectiveStatement contBar = notif
+            .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow()
+            .findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
+
+        assertSame(contBar, grpBar);
+    }
+}
diff --git a/yang/yang-parser-rfc7950/src/test/resources/bugs/YT1208/leaf.yang b/yang/yang-parser-rfc7950/src/test/resources/bugs/YT1208/leaf.yang
new file mode 100644 (file)
index 0000000..e4b415c
--- /dev/null
@@ -0,0 +1,21 @@
+module foo {
+  namespace foo;
+  prefix foo;
+
+  grouping grp {
+    leaf bar {
+      type string;
+      description "desc";
+    }
+  }
+
+  notification foo {
+    grouping foo {
+      uses grp;
+    }
+
+    container foo {
+      uses foo;
+    }
+  }
+}