BUG-994: Use SchemaPath.getParent() 85/8285/2
authorRobert Varga <rovarga@cisco.com>
Tue, 24 Jun 2014 07:35:00 +0000 (09:35 +0200)
committerMartin Vitez <mvitez@cisco.com>
Wed, 25 Jun 2014 06:51:08 +0000 (08:51 +0200)
Now that SchemaPath defines the proper utility method, use it instead of
brewing our own.

Change-Id: If3661c78491ab97e70627dfffcd902a21bd93e83
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java

index f05c20614d542618be17cef838aad0919f6b4e63..b5ddcc37b30a67ea07dd773a75511442ca53ff83 100644 (file)
@@ -549,21 +549,17 @@ public final class SchemaContextUtil {
                 // groupings => parent is added by grouping too, so repeat same
                 // process for parent
                 if (result == null) {
+                    final SchemaNode sn = (SchemaNode) parent;
+
                     // set current name to name of parent node
-                    currentName = ((SchemaNode) parent).getQName();
+                    currentName = sn.getQName();
                     Preconditions.checkArgument(parent instanceof SchemaNode,
                             "Failed to generate code for augmend node {} at parent {}", node, parent);
+
                     // create schema path for parent of current parent
-                    SchemaPath nodeSp = ((SchemaNode) parent).getPath();
-                    List<QName> nodeNewNames = new ArrayList<>(nodeSp.getPath());
-                    nodeNewNames.remove(nodeNewNames.size() - 1);
-                    // set new parent based on path
-                    if (nodeNewNames.isEmpty()) {
-                        parent = getParentModule((SchemaNode) parent, ctx);
-                    } else {
-                        SchemaPath nodeNewSp = new SchemaPath(nodeNewNames, nodeSp.isAbsolute());
-                        parent = findDataSchemaNode(ctx, nodeNewSp);
-                    }
+                    final SchemaPath parentSp = sn.getPath().getParent();
+                    parent = parentSp.getPathFromRoot().iterator().hasNext() ? findDataSchemaNode(ctx, parentSp)
+                            : getParentModule(sn, ctx);
                 } else {
                     // if wanted node was found in grouping, traverse this node
                     // based on level of nesting