Do not generate prime when not needed
[mdsal.git] / binding / mdsal-binding-java-api-generator / src / main / java / org / opendaylight / mdsal / binding / java / api / generator / AbstractJavaGeneratedType.java
index b6a0d56464b57866e5b3126d2be7c83dca06a393..7d0e3170ca3ed22b01c275b3af03e879ebdfefc4 100644 (file)
@@ -51,8 +51,8 @@ abstract class AbstractJavaGeneratedType {
         enclosedTypes = b.build();
 
         final Set<String> cb = new HashSet<>();
-        if (genType instanceof Enumeration) {
-            ((Enumeration) genType).getValues().stream().map(Pair::getMappedName).forEach(cb::add);
+        if (genType instanceof Enumeration enumeration) {
+            enumeration.getValues().stream().map(Pair::getMappedName).forEach(cb::add);
         }
         // TODO: perhaps we can do something smarter to actually access the types
         collectAccessibleTypes(cb, genType);
@@ -62,8 +62,7 @@ abstract class AbstractJavaGeneratedType {
 
     private void collectAccessibleTypes(final Set<String> set, final GeneratedType type) {
         for (Type impl : type.getImplements()) {
-            if (impl instanceof GeneratedType) {
-                final GeneratedType genType = (GeneratedType) impl;
+            if (impl instanceof GeneratedType genType) {
                 for (GeneratedType inner : Iterables.concat(genType.getEnclosedTypes(), genType.getEnumerations())) {
                     set.add(inner.getIdentifier().simpleName());
                 }
@@ -80,10 +79,21 @@ abstract class AbstractJavaGeneratedType {
         return name.simpleName();
     }
 
+    private String annotateReference(final String ref, final Type type, final String annotation) {
+        if (type instanceof ParameterizedType parameterized) {
+            return getReferenceString(annotate(ref, annotation), type, parameterized.getActualTypeArguments());
+        }
+        return "byte[]".equals(ref) ? "byte @" + annotation + "[]" : annotate(ref, annotation).toString();
+    }
+
+    final String getFullyQualifiedReference(final Type type, final String annotation) {
+        return annotateReference(type.getFullyQualifiedName(), type ,annotation);
+    }
+
     final String getReferenceString(final Type type) {
         final String ref = getReferenceString(type.getIdentifier());
-        return type instanceof ParameterizedType ? getReferenceString(new StringBuilder(ref), type,
-            ((ParameterizedType) type).getActualTypeArguments())
+        return type instanceof ParameterizedType parameterized
+            ? getReferenceString(new StringBuilder(ref), type, parameterized.getActualTypeArguments())
                 : ref;
     }
 
@@ -91,9 +101,7 @@ abstract class AbstractJavaGeneratedType {
         // Package-private method, all callers who would be passing an empty array are bound to the more special
         // case above, hence we know annotations.length >= 1
         final String ref = getReferenceString(type.getIdentifier());
-        return type instanceof ParameterizedType ? getReferenceString(annotate(ref, annotation), type,
-            ((ParameterizedType) type).getActualTypeArguments())
-                : annotate(ref, annotation).toString();
+        return annotateReference(ref, type, annotation);
     }
 
     private String getReferenceString(final StringBuilder sb, final Type type, final @NonNull Type[] arguments) {