Binding generator v2 - uses implement - fix finding target grouping 14/60514/12
authorJie Han <[email protected]>
Tue, 18 Jul 2017 00:51:00 +0000 (08:51 +0800)
committerJie Han <[email protected]>
Thu, 10 Aug 2017 02:09:00 +0000 (10:09 +0800)
- can not call findDataSchemaNode to find target grouping since it search
data node first that may find a wrong data node with the same name, here
specially find grouping by getGrouping() first, and that should be always
correct for uses grouping, anyway, in case find nothing,
keep the findDataSchemaNode methord.

Change-Id: Ibef1c5a0e01d1fe36260c76676ae02b926d62296
Signed-off-by: Jie Han <[email protected]>
binding2/mdsal-binding2-generator-impl/src/main/java/org/opendaylight/mdsal/binding/javav2/generator/impl/GenHelperUtil.java

index 7f772fd68c527c894fd47b5b235dbabbc55999a0..a659b322438316c8e3759f5b6d833aa84018f3b4 100644 (file)
@@ -38,6 +38,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import org.opendaylight.mdsal.binding.javav2.generator.context.ModuleContext;
+import java.util.stream.Collectors;
 import org.opendaylight.mdsal.binding.javav2.generator.spi.TypeProvider;
 import org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil;
 import org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes;
@@ -352,7 +353,16 @@ final class GenHelperUtil {
                     .findFirst().orElse(null);
         } else {
             //FIXME: Schema path is not unique for Yang 1.1, findDataSchemaNode always does search from data node first.
-            groupingNode = SchemaContextUtil.findDataSchemaNode(schemaContext, usesNode.getGroupingPath());
+            final Iterable<QName> prefixedPath = usesNode.getGroupingPath().getPathFromRoot();
+            final QName current = prefixedPath.iterator().next();
+            final Module targetModule = schemaContext.findModuleByNamespaceAndRevision(current.getNamespace(), current.getRevision());
+            Preconditions.checkArgument(targetModule != null, "Cannot find target module for %s and %s.",
+                    current.getNamespace(), current.getRevision());
+            groupingNode = targetModule.getGroupings().stream().filter(grouping -> grouping.getPath().equals(usesNode.getGroupingPath()))
+                    .collect(Collectors.toList()).get(0);
+            if (groupingNode == null) {
+                groupingNode = SchemaContextUtil.findDataSchemaNode(schemaContext, usesNode.getGroupingPath());
+            }
         }
         Preconditions.checkNotNull(groupingNode, module.toString() + "->"
                 + usesNode.getGroupingPath().toString());