Fix leaf-list statement original propagation 92/94892/4
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Jan 2021 15:12:47 +0000 (16:12 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 30 Jan 2021 13:29:25 +0000 (14:29 +0100)
We must not forget to propagate the statement's original definition
when copying an empty statement. Also take advantage of copy facilities
in leaf statement.

JIRA: YANGTOOLS-1208
Change-Id: I11a84ffe5226951ab34df91b9e9da665cc315c03
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/leaf_list/AbstractNonEmptyLeafListEffectiveStatement.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/leaf_list/LeafListStatementSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/leaf_list/RegularLeafListEffectiveStatement.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/leaf_list/SlimLeafListEffectiveStatement.java

index 62ed0440b070124cd8df04d0f864afcc72edb076..281da97ed426c51ed0a3980163afc5b4d76d8ed8 100644 (file)
@@ -28,11 +28,18 @@ abstract class AbstractNonEmptyLeafListEffectiveStatement extends AbstractLeafLi
         this.elementCountConstraint = elementCountConstraint;
     }
 
-    AbstractNonEmptyLeafListEffectiveStatement(final AbstractNonEmptyLeafListEffectiveStatement original,
-            final SchemaPath path, final int flags) {
-        super(original, path, flags);
-        this.original = original.original;
-        this.elementCountConstraint = original.elementCountConstraint;
+    AbstractNonEmptyLeafListEffectiveStatement(final AbstractNonEmptyLeafListEffectiveStatement originalEffecive,
+            final LeafListSchemaNode original, final SchemaPath path, final int flags) {
+        super(originalEffecive, path, flags);
+        this.elementCountConstraint = originalEffecive.elementCountConstraint;
+        this.original = original;
+    }
+
+    AbstractNonEmptyLeafListEffectiveStatement(final EmptyLeafListEffectiveStatement originalEffective,
+            final LeafListSchemaNode original, final SchemaPath path, final int flags) {
+        super(originalEffective, path, flags);
+        this.elementCountConstraint = null;
+        this.original = original;
     }
 
     @Override
index 4c0a6c109d07c0b366834fa3ef5cb435669f1a29..085f823ea75371afcfc6817cbe66a9da57fae8c6 100644 (file)
@@ -109,15 +109,16 @@ public final class LeafListStatementSupport
     public LeafListEffectiveStatement copyEffective(final Current<QName, LeafListStatement> stmt,
             final LeafListEffectiveStatement original) {
         final int flags = computeFlags(stmt, original.effectiveSubstatements());
-        if (original instanceof EmptyLeafListEffectiveStatement) {
-            return new EmptyLeafListEffectiveStatement((EmptyLeafListEffectiveStatement) original,
-                stmt.wrapSchemaPath(), flags);
-        } else if (original instanceof SlimLeafListEffectiveStatement) {
-            return new SlimLeafListEffectiveStatement((SlimLeafListEffectiveStatement) original, stmt.wrapSchemaPath(),
-                flags);
-        } else if (original instanceof RegularLeafListEffectiveStatement) {
+        if (original instanceof RegularLeafListEffectiveStatement) {
             return new RegularLeafListEffectiveStatement((RegularLeafListEffectiveStatement) original,
-                stmt.wrapSchemaPath(), flags);
+                (LeafListSchemaNode) stmt.original(), stmt.wrapSchemaPath(), flags);
+        } else if (original instanceof SlimLeafListEffectiveStatement) {
+            return new SlimLeafListEffectiveStatement((SlimLeafListEffectiveStatement) original,
+                (LeafListSchemaNode) stmt.original(), stmt.wrapSchemaPath(), flags);
+        } else if (original instanceof EmptyLeafListEffectiveStatement) {
+            // Promote to slim
+            return new SlimLeafListEffectiveStatement((EmptyLeafListEffectiveStatement) original,
+                (LeafListSchemaNode) stmt.original(), stmt.wrapSchemaPath(), flags);
         } else {
             // Safe fallback
             return super.copyEffective(stmt, original);
index ba517973ccc95f4e8e15b86378d10884af6b1b59..a68aea94c1901c2dca85b3726af0160d43e1edc7 100644 (file)
@@ -28,10 +28,10 @@ final class RegularLeafListEffectiveStatement extends AbstractNonEmptyLeafListEf
         this.defaults = requireNonNull(defaults);
     }
 
-    RegularLeafListEffectiveStatement(final RegularLeafListEffectiveStatement original, final SchemaPath path,
-            final int flags) {
-        super(original, path, flags);
-        this.defaults = original.defaults;
+    RegularLeafListEffectiveStatement(final RegularLeafListEffectiveStatement originalEffective,
+            final LeafListSchemaNode original, final SchemaPath path, final int flags) {
+        super(originalEffective, original, path, flags);
+        this.defaults = originalEffective.defaults;
     }
 
     @Override
index bb82a96428c849917d81ce48852aaea9a92652af..14868673777702c7051adb212982eeaff2be8996 100644 (file)
@@ -22,9 +22,14 @@ final class SlimLeafListEffectiveStatement extends AbstractNonEmptyLeafListEffec
         super(declared, path, flags, substatements, original, elementCountConstraint);
     }
 
-    SlimLeafListEffectiveStatement(final SlimLeafListEffectiveStatement original, final SchemaPath path,
-            final int flags) {
-        super(original, path, flags);
+    SlimLeafListEffectiveStatement(final SlimLeafListEffectiveStatement originalEffective,
+            final LeafListSchemaNode original, final SchemaPath path, final int flags) {
+        super(originalEffective, original, path, flags);
+    }
+
+    SlimLeafListEffectiveStatement(final EmptyLeafListEffectiveStatement originalEffective,
+            final LeafListSchemaNode original, final SchemaPath path, final int flags) {
+        super(originalEffective, original, path, flags);
     }
 
     @Override