Generate implementedInterfaces method for DataRoot 55/91355/2
authorTomas Cere <tomas.cere@pantheon.tech>
Thu, 16 Jul 2020 11:34:25 +0000 (13:34 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 17 Jul 2020 07:21:36 +0000 (09:21 +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>
(cherry picked from commit 30794cd4999beb5a7a4902d4cf0484692cbd629b)

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 c04647d62ee459f382300bac36be88a63133e908..37d420554a46174d55b3a712189f42d150379b98 100644 (file)
@@ -424,6 +424,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..3909d4d
--- /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 = new BindingGeneratorImpl().generateTypes(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