From 50b15bc3e5a1db35903bae9b2722644ed8dd516c Mon Sep 17 00:00:00 2001 From: Samuel Kontris Date: Fri, 28 Feb 2020 14:33:02 +0100 Subject: [PATCH] Propagate grouping inference flag 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 Signed-off-by: Robert Varga --- .../yang/types/AbstractTypeProvider.java | 8 ++--- .../binding/generator/impl/Mdsal519Test.java | 30 +++++++++++++++++++ .../mdsal-519/specific-grouping-leafref.yang | 30 +++++++++++++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal519Test.java create mode 100644 binding/mdsal-binding-generator-impl/src/test/resources/mdsal-519/specific-grouping-leafref.yang diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/yang/types/AbstractTypeProvider.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/yang/types/AbstractTypeProvider.java index 2efc0f64c3..24f11dffee 100644 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/yang/types/AbstractTypeProvider.java +++ b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/yang/types/AbstractTypeProvider.java @@ -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 Type representation of dataNode */ - 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 index 0000000000..ceac4f4981 --- /dev/null +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal519Test.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.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 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 index 0000000000..67f13cd508 --- /dev/null +++ b/binding/mdsal-binding-generator-impl/src/test/resources/mdsal-519/specific-grouping-leafref.yang @@ -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"; + } + } + } + } + +} -- 2.36.6