BUG-8043: correct RangeConstraint definition
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / RpcEffectiveStatementImpl.java
index 0e640571202ebea0b240bfdd197a9dd5b4b1b649..c201777d58c6446e2c3122b6dc004e702dbb5c76 100644 (file)
@@ -8,8 +8,8 @@
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
 import com.google.common.collect.ImmutableSet;
-import java.util.Collection;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Objects;
 import java.util.Set;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -27,27 +27,32 @@ public class RpcEffectiveStatementImpl extends AbstractEffectiveSchemaNode<RpcSt
     private final Set<TypeDefinition<?>> typeDefinitions;
     private final Set<GroupingDefinition> groupings;
 
-    public RpcEffectiveStatementImpl(final StmtContext<QName, RpcStatement, EffectiveStatement<QName, RpcStatement>> ctx) {
+    public RpcEffectiveStatementImpl(final StmtContext<QName, RpcStatement,
+            EffectiveStatement<QName, RpcStatement>> ctx) {
         super(ctx);
         this.input = firstEffective(InputEffectiveStatementImpl.class);
         this.output = firstEffective(OutputEffectiveStatementImpl.class);
 
         // initSubstatements
-        Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
         Set<GroupingDefinition> groupingsInit = new HashSet<>();
-        Set<TypeDefinition<?>> typeDefinitionsInit = new HashSet<>();
-        for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
+        Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
+        for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
             if (effectiveStatement instanceof GroupingDefinition) {
                 GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
                 groupingsInit.add(groupingDefinition);
             }
-            if (effectiveStatement instanceof TypeDefinition) {
-                TypeDefinition<?> typeDefinition = (TypeDefinition<?>) effectiveStatement;
-                typeDefinitionsInit.add(typeDefinition);
+            if (effectiveStatement instanceof TypeDefEffectiveStatementImpl) {
+                TypeDefEffectiveStatementImpl typeDef = (TypeDefEffectiveStatementImpl) effectiveStatement;
+                TypeDefinition<?> type = typeDef.getTypeDefinition();
+                if (!mutableTypeDefinitions.contains(type)) {
+                    mutableTypeDefinitions.add(type);
+                } else {
+                    throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+                }
             }
         }
         this.groupings = ImmutableSet.copyOf(groupingsInit);
-        this.typeDefinitions = ImmutableSet.copyOf(typeDefinitionsInit);
+        this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
     }
 
     @Override
@@ -96,15 +101,11 @@ public class RpcEffectiveStatementImpl extends AbstractEffectiveSchemaNode<RpcSt
 
     @Override
     public String toString() {
-        return RpcEffectiveStatementImpl.class.getSimpleName() + "[" +
-                "qname=" +
-                getQName() +
-                ", path=" +
-                getPath() +
-                ", input=" +
-                input +
-                ", output=" +
-                output +
-                "]";
+        return RpcEffectiveStatementImpl.class.getSimpleName() + "["
+                + "qname=" + getQName()
+                + ", path=" +  getPath()
+                + ", input=" + input
+                + ", output=" + output
+                + "]";
     }
 }