Bug 6022: Deviation statement is not fully available in the YANG parser output
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / DeviationEffectiveStatementImpl.java
index b66abf8c67bd7aa3fdd00c3bd819fa05b4fed7f4..e4c0e85f61ab2ee00182a3d9acbdf1329f1c701c 100644 (file)
@@ -12,6 +12,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
 import org.opendaylight.yangtools.yang.model.api.Deviation;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
@@ -23,16 +24,19 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 public class DeviationEffectiveStatementImpl extends DeclaredEffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
         implements Deviation, Immutable {
     private final SchemaPath targetPath;
-    private final Deviate deviate;
+    private final String description;
     private final String reference;
     private final List<UnknownSchemaNode> unknownSchemaNodes;
+    private final List<DeviateDefinition> deviateDefinitions;
 
     public DeviationEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
         super(ctx);
         this.targetPath = ctx.getStatementArgument().asSchemaPath();
 
-        DeviateEffectiveStatementImpl deviateStmt = firstEffective(DeviateEffectiveStatementImpl.class);
-        this.deviate = (deviateStmt == null) ? null : deviateStmt.argument();
+        this.deviateDefinitions = ImmutableList.copyOf(allSubstatementsOfType(DeviateDefinition.class));
+
+        DescriptionEffectiveStatementImpl descriptionStmt = firstEffective(DescriptionEffectiveStatementImpl.class);
+        this.description = (descriptionStmt == null) ? null : descriptionStmt.argument();
 
         ReferenceEffectiveStatementImpl referenceStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
         this.reference = (referenceStmt == null) ? null : referenceStmt.argument();
@@ -52,8 +56,13 @@ public class DeviationEffectiveStatementImpl extends DeclaredEffectiveStatementB
     }
 
     @Override
-    public Deviate getDeviate() {
-        return deviate;
+    public List<DeviateDefinition> getDeviates() {
+        return deviateDefinitions;
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
     }
 
     @Override
@@ -71,7 +80,8 @@ public class DeviationEffectiveStatementImpl extends DeclaredEffectiveStatementB
         final int prime = 31;
         int result = 1;
         result = prime * result + Objects.hashCode(targetPath);
-        result = prime * result + Objects.hashCode(deviate);
+        result = prime * result + Objects.hashCode(deviateDefinitions);
+        result = prime * result + Objects.hashCode(description);
         result = prime * result + Objects.hashCode(reference);
         return result;
     }
@@ -91,7 +101,10 @@ public class DeviationEffectiveStatementImpl extends DeclaredEffectiveStatementB
         if (!Objects.equals(targetPath, other.targetPath)) {
             return false;
         }
-        if (!Objects.equals(deviate, other.deviate)) {
+        if (!Objects.equals(deviateDefinitions, other.deviateDefinitions)) {
+            return false;
+        }
+        if (!Objects.equals(description, other.description)) {
             return false;
         }
         if (!Objects.equals(reference, other.reference)) {
@@ -104,7 +117,8 @@ public class DeviationEffectiveStatementImpl extends DeclaredEffectiveStatementB
     public String toString() {
         return DeviationEffectiveStatementImpl.class.getSimpleName() + "[" +
                 "targetPath=" + targetPath +
-                ", deviate=" + deviate +
+                ", deviates=" + deviateDefinitions +
+                ", description=" + description +
                 ", reference=" + reference +
                 "]";
     }