Bug4231 - Yang tools failing to parse Augmentations under "uses" clause.
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / BuilderUtils.java
index e98553e8009013e5b4f5c2bc2c60123fdd147630..1c202f61004c5d7ac84a57532571897da679cf80 100644 (file)
@@ -121,22 +121,6 @@ public final class BuilderUtils {
         });
     }
 
-    /**
-     * Create new SchemaPath from given path and qname.
-     *
-     * @param schemaPath
-     *            base path
-     * @param qname
-     *            one or more qnames added to base path
-     * @return new SchemaPath from given path and qname
-     *
-     * @deprecated Use {@link SchemaPath#createChild(QName...)} instead.
-     */
-    @Deprecated
-    public static SchemaPath createSchemaPath(final SchemaPath schemaPath, final QName... qname) {
-        return schemaPath.createChild(qname);
-    }
-
     /**
      * Find dependent module based on given prefix
      *
@@ -180,7 +164,7 @@ public final class BuilderUtils {
         return dependentModule;
     }
 
-    public static ModuleBuilder findModuleFromBuilders(ModuleImport imp, Iterable<ModuleBuilder> modules) {
+    public static ModuleBuilder findModuleFromBuilders(final ModuleImport imp, final Iterable<ModuleBuilder> modules) {
         String name = imp.getModuleName();
         Date revision = imp.getRevision();
         NavigableMap<Date, ModuleBuilder> map = new TreeMap<>();
@@ -343,7 +327,7 @@ public final class BuilderUtils {
     /**
      * Set addedByUses flag to true for node and all its child nodes.
      *
-     * @param node
+     * @param node grouping member node
      */
     public static void setNodeAddedByUses(final GroupingMember node) {
         node.setAddedByUses(true);
@@ -360,6 +344,41 @@ public final class BuilderUtils {
         }
     }
 
+    /**
+     * Find builder of schema node under parent builder (including under
+     * AugmentationSchemaBuilder).
+     *
+     * @param path
+     *            - path of target schema node builder
+     * @param parent
+     *            - base data node container builder under which the target
+     *            schema node builder should be found
+     * @return builder of schema node
+     */
+    public static SchemaNodeBuilder findTargetNode(final Iterable<QName> path,
+            final DataNodeContainerBuilder parent) {
+
+        Preconditions.checkNotNull(parent);
+        Preconditions.checkNotNull(path);
+
+        SchemaNodeBuilder foundNode = null;
+
+        final Iterator<QName> pathIterator = path.iterator();
+        if (pathIterator.hasNext()) {
+            String name = pathIterator.next().getLocalName();
+            foundNode = parent.getDataChildByName(name);
+            if (foundNode == null) {
+                foundNode = findUnknownNode(name, parent);
+            }
+        }
+
+        if (pathIterator.hasNext() && foundNode != null) {
+            return findSchemaNode(Iterables.skip(path, 1), foundNode);
+        } else {
+            return foundNode;
+        }
+    }
+
     public static SchemaNodeBuilder findSchemaNode(final Iterable<QName> path, final SchemaNodeBuilder parentNode) {
         SchemaNodeBuilder node = null;
         SchemaNodeBuilder parent = parentNode;
@@ -693,7 +712,7 @@ public final class BuilderUtils {
     /**
      * Get module in which this node is defined.
      *
-     * @param node
+     * @param node node
      * @return builder of module where this node is defined
      */
     public static ModuleBuilder getParentModule(final Builder node) {