Revert "Revert "BUG-994: reorganize SchemaPath into a tree""
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / SchemaContextUtil.java
index f48bfde63e7e420b54004cce9b1ce19fb7f7e273..fc98c1daf0aef88d6e202743d0db8e3fcb56576d 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
+import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
 import com.google.common.collect.Iterables;
@@ -498,7 +499,7 @@ public final class SchemaContextUtil {
         Preconditions.checkArgument(m != null, "Failed to find module for node {} in context {}", node, ctx);
 
         for (final UsesNode u : m.getUses()) {
-            final SchemaNode targetGrouping = findNodeInSchemaContext(ctx, u.getGroupingPath().getPath());
+            final SchemaNode targetGrouping = findNodeInSchemaContext(ctx, u.getGroupingPath().getPathFromRoot());
             Preconditions.checkArgument(targetGrouping instanceof GroupingDefinition,
                     "Failed to generate code for augment in %s", u);
 
@@ -625,7 +626,7 @@ public final class SchemaContextUtil {
     }
 
     private static DataSchemaNode getResultFromUses(final UsesNode u, final String currentName, final SchemaContext ctx) {
-        SchemaNode targetGrouping = findNodeInSchemaContext(ctx, u.getGroupingPath().getPath());
+        SchemaNode targetGrouping = findNodeInSchemaContext(ctx, u.getGroupingPath().getPathFromRoot());
 
         Preconditions.checkArgument(targetGrouping instanceof GroupingDefinition,
                 "Failed to generate code for augment in %s", u);
@@ -867,16 +868,13 @@ public final class SchemaContextUtil {
             ++colCount;
         }
 
-        final List<QName> absolutePath = new LinkedList<QName>();
-        final List<QName> path = leafrefParentNode.getPath().getPath();
-        if (path != null) {
-            int lenght = path.size() - colCount;
-            absolutePath.addAll(path.subList(0, lenght));
-            for (String s : Iterables.skip(xpaths, colCount)) {
-                absolutePath.add(stringPathPartToQName(context, module, s));
-            }
-        }
-
-        return absolutePath;
+        final Iterable<QName> parent = leafrefParentNode.getPath().getPathFromRoot();
+        return Iterables.concat(Iterables.limit(parent, Iterables.size(parent) - colCount),
+                Iterables.transform(Iterables.skip(xpaths, colCount), new Function<String, QName>() {
+                    @Override
+                    public QName apply(final String input) {
+                        return stringPathPartToQName(context, module, input);
+                    }
+                }));
     }
 }