Merge "Fixed incorrect test location."
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / AugmentationSchemaBuilderImpl.java
index 91708c00da26ccae197cc35e3c1855ed3ab548ce..5d93a06579bea94c8ead4cea608b422dfab68b78 100644 (file)
@@ -7,14 +7,15 @@
  */
 package org.opendaylight.yangtools.yang.parser.builder.impl;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
 import java.net.URI;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
-
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.NamespaceRevisionAware;
 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
@@ -24,31 +25,26 @@ import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
 
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-
-public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataNodeContainerBuilder implements
-        AugmentationSchemaBuilder {
+public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataNodeContainerBuilder implements AugmentationSchemaBuilder {
     private final int order;
     private AugmentationSchemaImpl instance;
     private String whenCondition;
 
     private final String augmentTargetStr;
     private final SchemaPath targetPath;
-    private SchemaPath targetNodeSchemaPath;
 
     private boolean resolved;
     private AugmentationSchemaBuilder copyOf;
 
-    public AugmentationSchemaBuilderImpl(final String moduleName, final int line, final String augmentTargetStr, final int order) {
+    public AugmentationSchemaBuilderImpl(final String moduleName, final int line, final String augmentTargetStr,
+            final SchemaPath targetPath, final int order) {
         super(moduleName, line, null);
         this.order = order;
         this.augmentTargetStr = augmentTargetStr;
-        targetPath = BuilderUtils.parseXPathString(augmentTargetStr);
+        this.targetPath = targetPath;
     }
 
     @Override
@@ -58,7 +54,12 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
 
     @Override
     public SchemaPath getPath() {
-        return targetNodeSchemaPath;
+        return targetPath;
+    }
+
+    @Override
+    public SchemaPath getTargetPath() {
+        return targetPath;
     }
 
     @Override
@@ -68,6 +69,7 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
         }
 
         buildChildren();
+
         instance = new AugmentationSchemaImpl(targetPath, order,this);
 
         Builder parent = getParent();
@@ -77,19 +79,6 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
             instance.revision = moduleBuilder.getRevision();
         }
 
-        if (parent instanceof UsesNodeBuilder) {
-            final ModuleBuilder mb = BuilderUtils.getParentModule(this);
-            final QNameModule qm = QNameModule.create(mb.getNamespace(), mb.getRevision());
-
-            List<QName> newPath = new ArrayList<>();
-            for (QName name : targetPath.getPathFromRoot()) {
-                newPath.add(QName.create(qm, name.getPrefix(), name.getLocalName()));
-            }
-            instance.targetPath = SchemaPath.create(newPath, false);
-        } else {
-            instance.targetPath = targetNodeSchemaPath;
-        }
-
         if (copyOf != null) {
             instance.setCopyOf(copyOf.build());
         }
@@ -136,21 +125,6 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
         return augmentTargetStr;
     }
 
-    @Override
-    public SchemaPath getTargetPath() {
-        return targetPath;
-    }
-
-    @Override
-    public SchemaPath getTargetNodeSchemaPath() {
-        return targetNodeSchemaPath;
-    }
-
-    @Override
-    public void setTargetNodeSchemaPath(final SchemaPath path) {
-        this.targetNodeSchemaPath = path;
-    }
-
     @Override
     public int getOrder() {
         return order;
@@ -192,11 +166,7 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
         } else if (!whenCondition.equals(other.whenCondition)) {
             return false;
         }
-        if (other.getChildNodeBuilders() == null) {
-            if (other.getChildNodeBuilders() != null) {
-                return false;
-            }
-        } else if (!getChildNodeBuilders().equals(other.getChildNodeBuilders())) {
+        if (!getChildNodeBuilders().equals(other.getChildNodeBuilders())) {
             return false;
         }
         return true;
@@ -211,10 +181,9 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
         copyOf = old;
     }
 
-    private static final class AugmentationSchemaImpl extends AbstractDocumentedDataNodeContainer implements AugmentationSchema, NamespaceRevisionAware,
-            Comparable<AugmentationSchemaImpl> {
+    private static final class AugmentationSchemaImpl extends AbstractDocumentedDataNodeContainer implements AugmentationSchema, NamespaceRevisionAware, Comparable<AugmentationSchemaImpl> {
         private final int order;
-        private SchemaPath targetPath;
+        private final SchemaPath targetPath;
         private RevisionAwareXPath whenCondition;
 
         private URI namespace;
@@ -268,7 +237,7 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
             int result = 1;
             result = prime * result + ((targetPath == null) ? 0 : targetPath.hashCode());
             result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
-            result = getChildNodes().hashCode();
+            result = prime * result + getChildNodes().hashCode();
             return result;
         }
 
@@ -308,14 +277,15 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataN
         public String toString() {
             StringBuilder sb = new StringBuilder(AugmentationSchemaImpl.class.getSimpleName());
             sb.append("[");
-            sb.append("targetPath=" + targetPath);
-            sb.append(", when=" + whenCondition);
+            sb.append("targetPath=").append(targetPath);
+            sb.append(", when=").append(whenCondition);
             sb.append("]");
             return sb.toString();
         }
 
         @Override
         public int compareTo(final AugmentationSchemaImpl o) {
+            checkNotNull(o);
             Iterator<QName> thisIt = this.targetPath.getPathFromRoot().iterator();
             Iterator<QName> otherIt = o.getTargetPath().getPathFromRoot().iterator();
             while (thisIt.hasNext()) {