Generate implementedInterfaces method for DataRoot 47/91347/1
authorTomas Cere <tomas.cere@pantheon.tech>
Thu, 16 Jul 2020 11:34:25 +0000 (13:34 +0200)
committerTomas Cere <tomas.cere@pantheon.tech>
Thu, 16 Jul 2020 11:42:36 +0000 (13:42 +0200)
In case we have multiple top level uses statements we also
need to generate an override of implementedInterfaces() to prevent
clashes with the return types of the extended interfaces.

JIRA: MDSAL-573
Change-Id: I07ad3f6dc5a18369f0be4bdaba03c6c17072297b
Signed-off-by: Tomas Cere <tomas.cere@pantheon.tech>
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/AbstractTypeGenerator.java
binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal573Test.java [new file with mode: 0644]
binding/mdsal-binding-generator-impl/src/test/resources/mdsal573.yang [new file with mode: 0644]

index eb7d3c002963ca212351910c4c812274b9d8414f..4b2776e78f7f17c94fb0b6f4fdc93a0f6351d5c5 100644 (file)
@@ -437,6 +437,11 @@ abstract class AbstractTypeGenerator {
         final Module module = context.module();
         addImplementedInterfaceFromUses(module, moduleDataTypeBuilder);
         moduleDataTypeBuilder.addImplementsType(DATA_ROOT);
+        // if we have more than 2 top level uses statements we need to define getImplementedInterface() on the
+        // top level DataRoot object
+        if (module.getUses().size() > 1) {
+            narrowImplementedInterface(moduleDataTypeBuilder);
+        }
 
         addCodegenInformation(moduleDataTypeBuilder, module);
         return moduleDataTypeBuilder;
diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal573Test.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal573Test.java
new file mode 100644 (file)
index 0000000..a52cc1b
--- /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.List;
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.model.api.GeneratedType;
+import org.opendaylight.mdsal.binding.model.api.MethodSignature;
+import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class Mdsal573Test {
+    @Test
+    public void mdsal573Test() {
+        final List<Type> generateTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
+                "/mdsal573.yang"));
+        assertNotNull(generateTypes);
+
+        final MethodSignature methodSignature = ((GeneratedType) generateTypes.get(0)).getMethodDefinitions().get(0);
+        assertEquals("implementedInterface", methodSignature.getName());
+    }
+}
diff --git a/binding/mdsal-binding-generator-impl/src/test/resources/mdsal573.yang b/binding/mdsal-binding-generator-impl/src/test/resources/mdsal573.yang
new file mode 100644 (file)
index 0000000..fcc35f7
--- /dev/null
@@ -0,0 +1,34 @@
+module mdsal573 {
+  namespace "mdsal573";
+  prefix l;
+
+  grouping g1 {
+    container c1 {
+      leaf l1 {
+        type string;
+      }
+    }
+  }
+
+  grouping g2 {
+    uses g3;
+
+    container c2 {
+      leaf l2 {
+        type string;
+      }
+    }
+  }
+
+  grouping g3 {
+    container c3 {
+      leaf l3 {
+        type string;
+      }
+    }
+  }
+
+
+  uses g1;
+  uses g2;
+}
\ No newline at end of file