BUG-4658: fix default value in BooleanType
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / type / LeafrefSpecificationEffectiveStatementImpl.java
index 67f0e37719b77caa6b3528e1ca2d1ffa162500fb..33447d8576d7941ac4e5a3af6480a0c20b30bca9 100644 (file)
@@ -7,41 +7,42 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
 
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-
-import org.opendaylight.yangtools.yang.model.util.Leafref;
-import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.LeafrefSpecification;
 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.Leafref;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PathEffectiveStatementImpl;
 
-public class LeafrefSpecificationEffectiveStatementImpl extends
-        EffectiveStatementBase<String, TypeStatement.LeafrefSpecification> implements LeafrefTypeDefinition, TypeDefinitionEffectiveBuilder {
+public class LeafrefSpecificationEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, LeafrefSpecification>
+        implements LeafrefTypeDefinition, TypeEffectiveStatement<LeafrefSpecification> {
 
     public static final String LOCAL_NAME = "leafref";
     private static final QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, LOCAL_NAME);
-    private static final SchemaPath PATH = SchemaPath.create(true, QNAME);
     private static final String DESCRIPTION = "The leafref type is used to reference a particular leaf instance in the data tree.";
     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.9";
     private static final String UNITS = "";
 
-    private RevisionAwareXPath xpath;
     private final SchemaPath path;
+    private RevisionAwareXPath xpath;
+    private Leafref leafrefInstance = null;
 
-    public LeafrefSpecificationEffectiveStatementImpl(StmtContext<String, TypeStatement.LeafrefSpecification, EffectiveStatement<String, TypeStatement.LeafrefSpecification>> ctx) {
+    public LeafrefSpecificationEffectiveStatementImpl(final StmtContext<String, LeafrefSpecification, EffectiveStatement<String, LeafrefSpecification>> ctx) {
         super(ctx);
 
-        path = Utils.getSchemaPath(ctx.getParentContext()).createChild(QNAME);
+        path = ctx.getParentContext().getSchemaPath().get().createChild(QNAME);
 
         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
             if (effectiveStatement instanceof PathEffectiveStatementImpl) {
@@ -67,7 +68,7 @@ public class LeafrefSpecificationEffectiveStatementImpl extends
 
     @Override
     public Object getDefaultValue() {
-        return this;
+        return null;
     }
 
     @Override
@@ -104,7 +105,7 @@ public class LeafrefSpecificationEffectiveStatementImpl extends
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((xpath == null) ? 0 : xpath.hashCode());
+        result = prime * result + Objects.hashCode(xpath);
         return result;
     }
 
@@ -120,14 +121,7 @@ public class LeafrefSpecificationEffectiveStatementImpl extends
             return false;
         }
         LeafrefSpecificationEffectiveStatementImpl other = (LeafrefSpecificationEffectiveStatementImpl) obj;
-        if (xpath == null) {
-            if (other.xpath != null) {
-                return false;
-            }
-        } else if (!xpath.equals(other.xpath)) {
-            return false;
-        }
-        return true;
+        return Objects.equals(xpath, other.xpath);
     }
 
     @Override
@@ -141,11 +135,8 @@ public class LeafrefSpecificationEffectiveStatementImpl extends
         return builder.toString();
     }
 
-    private Leafref leafrefInstance = null;
-
     @Override
-    public Leafref buildType() {
-
+    public TypeDefinition<?> getTypeDefinition() {
         if (leafrefInstance != null) {
             return leafrefInstance;
         }