X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=inline;f=binding%2Fmdsal-binding-java-api-generator%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fjava%2Fapi%2Fgenerator%2FAbstractJavaGeneratedType.java;h=7d0e3170ca3ed22b01c275b3af03e879ebdfefc4;hb=37ba772acba4cf4f56e3814c073c64f096f94d02;hp=a02843f01c383a96e756342c4b13e2d5fadfcb6d;hpb=dbaae85acd37ba622f4f53a7335af14e768fb180;p=mdsal.git diff --git a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/AbstractJavaGeneratedType.java b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/AbstractJavaGeneratedType.java index a02843f01c..7d0e3170ca 100644 --- a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/AbstractJavaGeneratedType.java +++ b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/AbstractJavaGeneratedType.java @@ -17,6 +17,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.mdsal.binding.model.api.Enumeration; @@ -50,8 +51,8 @@ abstract class AbstractJavaGeneratedType { enclosedTypes = b.build(); final Set 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); @@ -61,8 +62,7 @@ abstract class AbstractJavaGeneratedType { private void collectAccessibleTypes(final Set 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()); } @@ -79,23 +79,32 @@ 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; } - 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, - ((ParameterizedType) type).getActualTypeArguments()) - : annotate(ref, annotations).toString(); + return annotateReference(ref, type, annotation); } - private String getReferenceString(final StringBuilder sb, final Type type, final Type[] arguments) { + private String getReferenceString(final StringBuilder sb, final Type type, final @NonNull Type[] arguments) { if (arguments.length == 0) { return sb.append("").toString(); } @@ -169,16 +178,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()); } }