Fix sonar warnings is yang-parser-impl
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / InputEffectiveStatementImpl.java
index e0ded9ec84b9068079599de01bac77927d4aec3b..6757ba567e9d2fbe344e5b053277964218a3d5cc 100644 (file)
@@ -7,10 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
 import java.util.HashSet;
 import java.util.LinkedList;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import java.util.List;
@@ -36,7 +36,7 @@ public class InputEffectiveStatementImpl extends
 
     boolean augmenting;
     boolean addedByUses;
-    boolean configuration;
+    boolean configuration = true;
     ContainerSchemaNode original;
     ConstraintDefinition constraints;
 
@@ -51,17 +51,39 @@ public class InputEffectiveStatementImpl extends
         path = Utils.getSchemaPath(ctx);
         presence = (firstEffective(PresenceEffectiveStatementImpl.class) == null) ? false
                 : true;
-        // :TODO init other fields
+        this.constraints = new EffectiveConstraintDefinitionImpl(this);
+
+        initSubstatementCollectionsAndFields();
+        initCopyType(ctx);
+    }
+
+    private void initCopyType(
+            StmtContext<QName, InputStatement, EffectiveStatement<QName, InputStatement>> ctx) {
+
+        List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
 
-        initSubstatementCollections();
+        if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
+            augmenting = true;
+        }
+        if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
+            addedByUses = true;
+        }
+        if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
+            addedByUses = augmenting = true;
+        }
+
+        if (ctx.getOriginalCtx() != null) {
+            original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
+        }
     }
 
-    private void initSubstatementCollections() {
+    private void initSubstatementCollectionsAndFields() {
         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
 
         List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
         Set<AugmentationSchema> augmentationsInit = new HashSet<>();
 
+        boolean configurationInit = false;
         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
             if (effectiveStatement instanceof UnknownSchemaNode) {
                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
@@ -71,6 +93,12 @@ public class InputEffectiveStatementImpl extends
                 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
                 augmentationsInit.add(augmentationSchema);
             }
+            if (!configurationInit
+                    && effectiveStatement instanceof ConfigEffectiveStatementImpl) {
+                ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveStatement;
+                this.configuration = configStmt.argument();
+                configurationInit = true;
+            }
         }
 
         this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);