Propagate grouping inference flag 32/88332/2
authorSamuel Kontris <samuel.kontris@pantheon.tech>
Fri, 28 Feb 2020 13:33:02 +0000 (14:33 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 6 Mar 2020 15:02:20 +0000 (16:02 +0100)
The test case ends up looking through the magic code flagged
for refactoring -- which is losing knowledge that the parent
node is actually a grouping. Fix this up by propagating the
flag correctly.

JIRA: MDSAL-519
Change-Id: I8fe04e688adfcc068ff29e90a039530bcd56b3c3
Signed-off-by: Samuel Kontris <samuel.kontris@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/yang/types/AbstractTypeProvider.java
binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal519Test.java [new file with mode: 0644]
binding/mdsal-binding-generator-impl/src/test/resources/mdsal-519/specific-grouping-leafref.yang [new file with mode: 0644]

index 2efc0f64c3fe6dc619dd89d1a4966b021fda9ba4..24f11dffee589a726771253b30e3f4d99c8336f0 100644 (file)
@@ -555,7 +555,7 @@ public abstract class AbstractTypeProvider implements TypeProvider {
             returnType = Types.listTypeFor(referencedTypes.get(dataNode.getPath()));
         }
         if (returnType == null) {
-            returnType = resolveTypeFromDataSchemaNode(dataNode);
+            returnType = resolveTypeFromDataSchemaNode(dataNode, inGrouping);
         }
         Preconditions.checkArgument(returnType != null, "Failed to find leafref target: %s in module %s (%s)",
                 strXPath, this.getParentModule(parentNode).getName(), parentNode.getQName().getModule(), this);
@@ -711,16 +711,16 @@ public abstract class AbstractTypeProvider implements TypeProvider {
      * @param dataNode contains information about YANG type
      * @return JAVA <code>Type</code> representation of <code>dataNode</code>
      */
-    private Type resolveTypeFromDataSchemaNode(final SchemaNode dataNode) {
+    private Type resolveTypeFromDataSchemaNode(final SchemaNode dataNode, final boolean inGrouping) {
         Type returnType = null;
         if (dataNode != null) {
             if (dataNode instanceof LeafSchemaNode) {
                 final LeafSchemaNode leaf = (LeafSchemaNode) dataNode;
                 final TypeDefinition<?> type = CompatUtils.compatType(leaf);
-                returnType = javaTypeForSchemaDefinitionType(type, leaf);
+                returnType = javaTypeForSchemaDefinitionType(type, leaf, inGrouping);
             } else if (dataNode instanceof LeafListSchemaNode) {
                 final LeafListSchemaNode leafList = (LeafListSchemaNode) dataNode;
-                returnType = javaTypeForSchemaDefinitionType(leafList.getType(), leafList);
+                returnType = javaTypeForSchemaDefinitionType(leafList.getType(), leafList, inGrouping);
             }
         }
         return returnType;
diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal519Test.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal519Test.java
new file mode 100644 (file)
index 0000000..ceac4f4
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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.mdsal.binding.generator.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Collection;
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+/**
+ * Test specific combination of leafrefs, grouping and relative paths.
+ */
+public class Mdsal519Test {
+
+    @Test
+    public void testNestedLeafref2() {
+        final Collection<Type> types = new BindingGeneratorImpl().generateTypes(
+            YangParserTestUtils.parseYangResource("/mdsal-519/specific-grouping-leafref.yang"));
+        assertNotNull(types);
+        assertEquals(4, types.size());
+    }
+}
diff --git a/binding/mdsal-binding-generator-impl/src/test/resources/mdsal-519/specific-grouping-leafref.yang b/binding/mdsal-binding-generator-impl/src/test/resources/mdsal-519/specific-grouping-leafref.yang
new file mode 100644 (file)
index 0000000..67f13cd
--- /dev/null
@@ -0,0 +1,30 @@
+module specific-grouping-leafref {
+
+  namespace "odl:test:leafref:grouping:nested";
+  prefix "gl";
+  revision 2020-02-28;
+
+  container container-top {
+    leaf leaf-1 {
+      type string;
+    }
+    uses grouping-leafref;
+  }
+
+  grouping grouping-leafref {
+    container nested-container {
+      leaf leafref-1 {
+        type leafref {
+          path "../leafref-2";
+        }
+      }
+
+      leaf leafref-2 {
+        type leafref {
+          path "../../leaf-1";
+        }
+      }
+    }
+  }
+
+}