Populate enumeration conflicting names 48/72748/3
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 7 Jun 2018 11:00:51 +0000 (13:00 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 7 Jun 2018 13:40:47 +0000 (15:40 +0200)
Pairs need to be accounted as conflicting names to prevent clashes
with classes used by the enumeration template.

JIRA: MDSAL-348
Change-Id: I22e5c72ec944027e20858813c98fed21553d92bd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/AbstractJavaGeneratedType.java
binding/mdsal-binding-java-api-generator/src/test/resources/compilation/mdsal327/test-imports.yang

index fe60bbbf27aeb924e9c8f03e404866b3541ed212..607451b650161a17fec4a0c6b2989a6704f9071c 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.mdsal.binding.java.api.generator;
 
+import static com.google.common.collect.ImmutableSet.toImmutableSet;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.collect.ImmutableMap;
@@ -20,6 +21,8 @@ import java.util.Set;
 import javax.annotation.concurrent.NotThreadSafe;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.mdsal.binding.model.api.Enumeration;
+import org.opendaylight.mdsal.binding.model.api.Enumeration.Pair;
 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
 import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
@@ -48,7 +51,9 @@ abstract class AbstractJavaGeneratedType {
             b.put(type.getIdentifier().simpleName(), new NestedJavaGeneratedType(this, type));
         }
         enclosedTypes = b.build();
-        conflictingNames = ImmutableSet.of();
+        conflictingNames = genType instanceof Enumeration
+                ? ((Enumeration) genType).getValues().stream().map(Pair::getMappedName).collect(toImmutableSet())
+                        : ImmutableSet.of();
     }
 
     AbstractJavaGeneratedType(final JavaTypeName name, final GeneratedType genType) {
@@ -59,7 +64,7 @@ abstract class AbstractJavaGeneratedType {
         // a GeneratedType for the Builder with a nested type for the implementation, which really should be
         // a different template which gets generated as an inner type.
         conflictingNames = Streams.concat(genType.getEnclosedTypes().stream(), genType.getEnumerations().stream())
-        .map(type -> type.getIdentifier().simpleName()).collect(ImmutableSet.toImmutableSet());
+        .map(type -> type.getIdentifier().simpleName()).collect(toImmutableSet());
     }
 
     final JavaTypeName getName() {
index 3376cb560f47fe45e96fe5699d0b06974fa06618..372f98537212b8cfebf7406d4b0f014ffa8a2d4b 100644 (file)
@@ -19,6 +19,7 @@ module test-imports {
                   type enumeration {
                     enum string;
                     enum int8;
+                    enum optional;
                   }
                 }
             }