Add @NonNull in DataObjects' default method signatures 57/91757/6
authorillia.ihushev <illia.ihushev@pantheon.tech>
Wed, 29 Jul 2020 10:41:34 +0000 (13:41 +0300)
committerRobert Varga <nite@hq.sk>
Mon, 3 Aug 2020 07:56:14 +0000 (07:56 +0000)
When specific DataObject is not Augmentable bindingToString parameter,
bindingEquals thisObj parameter, bindingHashCode parameter are not
annotated with @NonNull. Add these missing @NonNulls.

JIRA: MDSAL-582
Change-Id: I1ec4b500fd30cdf6b5006b8da2d91e035eff04ae
Signed-off-by: illia.ihushev <illia.ihushev@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/InterfaceTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/JavaFileTemplate.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderGeneratorTest.java

index b6a0d56464b57866e5b3126d2be7c83dca06a393..cdbcc1654d6cf7432e052608fc63190b982cb3b0 100644 (file)
@@ -80,6 +80,16 @@ abstract class AbstractJavaGeneratedType {
         return name.simpleName();
     }
 
+    private String annotateReference(final String ref, final Type type, final String annotation) {
+        return type instanceof ParameterizedType ? getReferenceString(annotate(ref, annotation), type,
+                ((ParameterizedType) type).getActualTypeArguments())
+                : 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,
@@ -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) {
index 9007afcfdf2712630b91cd2e786f10726d290d38..2ead021a95d9a7dde5a758eec068ac1d841ffb7b 100644 (file)
@@ -241,7 +241,7 @@ class InterfaceTemplate extends BaseTemplate {
             «IF augmentable»
                 static <T$$ extends «type.fullyQualifiedName» & «AUGMENTATION_HOLDER.importedName»<?>> int «BINDING_HASHCODE_NAME»(final @«NONNULL.importedName» T$$ obj) {
             «ELSE»
-                static int «BINDING_HASHCODE_NAME»(final «type.fullyQualifiedName» obj) {
+                static int «BINDING_HASHCODE_NAME»(final «type.fullyQualifiedNonNull» obj) {
             «ENDIF»
                 final int prime = 31;
                 int result = 1;
@@ -276,7 +276,7 @@ class InterfaceTemplate extends BaseTemplate {
             «IF augmentable»
             static <T$$ extends «type.fullyQualifiedName» & «AUGMENTATION_HOLDER.importedName»<«type.fullyQualifiedName»>> boolean «BINDING_EQUALS_NAME»(final @«NONNULL.importedName» T$$ thisObj, final «Types.objectType().importedName» obj) {
             «ELSE»
-            static boolean «BINDING_EQUALS_NAME»(final «type.fullyQualifiedName» thisObj, final «Types.objectType().importedName» obj) {
+            static boolean «BINDING_EQUALS_NAME»(final «type.fullyQualifiedNonNull» thisObj, final «Types.objectType().importedName» obj) {
             «ENDIF»
                 if (thisObj == obj) {
                     return true;
@@ -313,7 +313,7 @@ class InterfaceTemplate extends BaseTemplate {
         «IF augmentable»
         static <T$$ extends «type.fullyQualifiedName» & «AUGMENTATION_HOLDER.importedName»<«type.fullyQualifiedName»>> «STRING.importedName» «BINDING_TO_STRING_NAME»(final @«NONNULL.importedName» T$$ obj) {
         «ELSE»
-        static «STRING.importedName» «BINDING_TO_STRING_NAME»(final «type.fullyQualifiedName» obj) {
+        static «STRING.importedName» «BINDING_TO_STRING_NAME»(final «type.fullyQualifiedNonNull» obj) {
         «ENDIF»
             final «MoreObjects.importedName».ToStringHelper helper = «MoreObjects.importedName».toStringHelper("«type.name»");
             «FOR property : typeAnalysis.value»
index 3aa4f8f7901ba0a5cc998ebb7c4aba8072e3400b..b8b3ecf23c68474688f702a664a0af1aae4d7da4 100644 (file)
@@ -183,6 +183,14 @@ class JavaFileTemplate {
         return importedName(intype, importedName(NULLABLE));
     }
 
+    final @NonNull String fullyQualifiedNonNull(final @NonNull Type intype) {
+        return fullyQualifiedName(intype, importedName(NONNULL));
+    }
+
+    final @NonNull String fullyQualifiedName(final @NonNull Type intype, final @NonNull String annotation) {
+        return javaType.getFullyQualifiedReference(intype, annotation);
+    }
+
     // Exposed for BuilderTemplate
     boolean isLocalInnerClass(final JavaTypeName name) {
         final Optional<JavaTypeName> optEnc = name.immediatelyEnclosingClass();
index 7fb78485e519cce09f62fe5fc4e2db228c0a6c2f..79cbe70982680c2fac3110fc5033a422e9fb962d 100644 (file)
@@ -48,7 +48,7 @@ public class BuilderGeneratorTest {
                 + " * @return Hash code value of data modeled by this interface.\n"
                 + " * @throws NullPointerException if {@code obj} is null\n"
                 + " */\n"
-                + "static int bindingHashCode(final test.test obj) {\n"
+                + "static int bindingHashCode(final test.@NonNull test obj) {\n"
                 + "    final int prime = 31;\n"
                 + "    int result = 1;\n"
                 + "    result = prime * result + Objects.hashCode(obj.getTest());\n"
@@ -73,7 +73,7 @@ public class BuilderGeneratorTest {
                 + " * @return Hash code value of data modeled by this interface.\n"
                 + " * @throws NullPointerException if {@code obj} is null\n"
                 + " */\n"
-                + "static int bindingHashCode(final test.test obj) {\n"
+                + "static int bindingHashCode(final test.@NonNull test obj) {\n"
                 + "    final int prime = 31;\n"
                 + "    int result = 1;\n"
                 + "    result = prime * result + Objects.hashCode(obj.getTest1());\n"
@@ -167,7 +167,7 @@ public class BuilderGeneratorTest {
                 + " * @return {@link String} value of data modeled by this interface.\n"
                 + " * @throws NullPointerException if {@code obj} is null\n"
                 + " */\n"
-                + "static String bindingToString(final test.test obj) {\n"
+                + "static String bindingToString(final test.@NonNull test obj) {\n"
                 + "    final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(\"test\");\n"
                 + "    CodeHelpers.appendValue(helper, \"test\", obj.gettest());\n"
                 + "    return helper.toString();\n"
@@ -185,7 +185,7 @@ public class BuilderGeneratorTest {
                 + " * @return {@link String} value of data modeled by this interface.\n"
                 + " * @throws NullPointerException if {@code obj} is null\n"
                 + " */\n"
-                + "static String bindingToString(final test.test obj) {\n"
+                + "static String bindingToString(final test.@NonNull test obj) {\n"
                 + "    final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(\"test\");\n"
                 + "    return helper.toString();\n"
                 + "}\n", genToString(mockGenType(TEST)).toString());
@@ -202,7 +202,7 @@ public class BuilderGeneratorTest {
                 + " * @return {@link String} value of data modeled by this interface.\n"
                 + " * @throws NullPointerException if {@code obj} is null\n"
                 + " */\n"
-                + "static String bindingToString(final test.test obj) {\n"
+                + "static String bindingToString(final test.@NonNull test obj) {\n"
                 + "    final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(\"test\");\n"
                 + "    CodeHelpers.appendValue(helper, \"test1\", obj.gettest1());\n"
                 + "    CodeHelpers.appendValue(helper, \"test2\", obj.gettest2());\n"