From: Tomas Cere Date: Thu, 16 Jul 2020 11:34:25 +0000 (+0200) Subject: Generate implementedInterfaces method for DataRoot X-Git-Tag: v4.0.16~4 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=mdsal.git;a=commitdiff_plain;h=c7a0aabb4e3a66f520da7c0bad60520eb0f9d2f2 Generate implementedInterfaces method for DataRoot 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 (cherry picked from commit 30794cd4999beb5a7a4902d4cf0484692cbd629b) --- diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/AbstractTypeGenerator.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/AbstractTypeGenerator.java index c04647d62e..37d420554a 100644 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/AbstractTypeGenerator.java +++ b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/AbstractTypeGenerator.java @@ -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 index 0000000000..3909d4dbf1 --- /dev/null +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal573Test.java @@ -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 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 index 0000000000..fcc35f7a22 --- /dev/null +++ b/binding/mdsal-binding-generator-impl/src/test/resources/mdsal573.yang @@ -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