Remove support for multiple annotations 13/85313/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 21 Oct 2019 20:43:43 +0000 (22:43 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 21 Oct 2019 20:57:36 +0000 (22:57 +0200)
We are only using a single annotation, hence we can collapse
a for loop into a straight append. Also reduces the need to allocate
arrays (even if JIT will handle that).

Change-Id: I5d226b115c16a91636045031c1ae3870a119e81a
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/main/java/org/opendaylight/mdsal/binding/java/api/generator/JavaFileTemplate.java

index a02843f01c383a96e756342c4b13e2d5fadfcb6d..12b5924346c90615a9f8006ff62746d86b831ec2 100644 (file)
@@ -86,13 +86,13 @@ abstract class AbstractJavaGeneratedType {
                 : ref;
     }
 
-    final String getReferenceString(final Type type, final String... annotations) {
+    final String getReferenceString(final Type type, final String annotation) {
         // 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, annotations), type,
+        return type instanceof ParameterizedType ? getReferenceString(annotate(ref, annotation), type,
             ((ParameterizedType) type).getActualTypeArguments())
-                : annotate(ref, annotations).toString();
+                : annotate(ref, annotation).toString();
     }
 
     private String getReferenceString(final StringBuilder sb, final Type type, final Type[] arguments) {
@@ -169,16 +169,12 @@ abstract class AbstractJavaGeneratedType {
         return checkAndImportType(type.topLevelClass()) ? type.localName() : type.toString();
     }
 
-    private static StringBuilder annotate(final String ref, final String... annotations) {
+    private static StringBuilder annotate(final String ref, final String annotation) {
         final StringBuilder sb = new StringBuilder();
         final int dot = ref.lastIndexOf('.');
         if (dot != -1) {
             sb.append(ref, 0, dot + 1);
         }
-        for (String annotation : annotations) {
-            sb.append('@').append(annotation).append(' ');
-        }
-
-        return sb.append(ref, dot + 1, ref.length());
+        return sb.append('@').append(annotation).append(' ').append(ref, dot + 1, ref.length());
     }
 }
index 5cceeef75970419d0a6a05916c151910aae581b2..0259a9ad7b56ca0cd9a8e20d327df758889b62ff 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.model.api.ConcreteType;
 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
@@ -130,8 +131,8 @@ class JavaFileTemplate {
         return javaType.getReferenceString(intype);
     }
 
-    final String importedName(final Type intype, final String... annotations) {
-        return javaType.getReferenceString(intype, annotations);
+    final String importedName(final Type intype, final @NonNull String annotation) {
+        return javaType.getReferenceString(intype, annotation);
     }
 
     final String importedName(final Class<?> cls) {