Remove getter @Nullable annotations for non-List/Map types
[mdsal.git] / binding / mdsal-binding-java-api-generator / src / main / java / org / opendaylight / mdsal / binding / java / api / generator / InterfaceTemplate.xtend
index 7780cbd510f5a290d4dba1ef9863bd0061ba111e..799a0f85f5420c60ac55c38fcb6e55981f7afbfe 100644 (file)
@@ -79,7 +79,7 @@ class InterfaceTemplate extends BaseTemplate {
      * @return string with code for interface body in JAVA format
      */
     override body() '''
-        «wrapToDocumentation(formatDataForJavaDoc(type))»
+        «type.formatDataForJavaDoc.wrapToDocumentation»
         «type.annotations.generateAnnotations»
         public interface «type.name»
             «superInterfaces»
@@ -189,6 +189,10 @@ class InterfaceTemplate extends BaseTemplate {
         } else {
             switch method.name {
                 case DATA_CONTAINER_IMPLEMENTED_INTERFACE_NAME : generateDefaultImplementedInterface
+                default :
+                    if (VOID == method.returnType.identifier) {
+                        generateNoopVoidInterfaceMethod(method)
+                    }
             }
         }
     }
@@ -207,13 +211,34 @@ class InterfaceTemplate extends BaseTemplate {
         «method.returnType.importedName» «method.name»(«method.parameters.generateParameters»);
     '''
 
-    def private generateAccessorMethod(MethodSignature method) '''
-        «val ret = method.returnType»
-        «formatDataForJavaDoc(method, "@return " + asCode(ret.fullyQualifiedName) + " " + asCode(propertyNameFromGetter(method)) + ", or " + asCode("null") + " if not present")»
+    def private generateNoopVoidInterfaceMethod(MethodSignature method) '''
+        «method.comment.asJavadoc»
         «method.annotations.generateAnnotations»
-        «nullableType(ret)» «method.name»();
+        default «VOID.importedName» «method.name»(«method.parameters.generateParameters») {
+            // No-op
+        }
     '''
 
+    def private static accessorJavadoc(MethodSignature method, String orString) {
+        val reference = method.comment?.referenceDescription
+        val propReturn = method.propertyNameFromGetter + ", or " + orString + " if it is not present."
+
+        return wrapToDocumentation('''
+            Return «propReturn».
+
+            «reference.formatReference»
+            @return {@code «method.returnType.fullyQualifiedName»} «propReturn»
+        ''')
+    }
+
+    def private generateAccessorMethod(MethodSignature method) {
+        return '''
+            «accessorJavadoc(method, "{@code null}")»
+            «method.annotations.generateAnnotations»
+            «method.returnType.nullableType» «method.name»();
+        '''
+    }
+
     def private generateDefaultImplementedInterface() '''
         @«OVERRIDE.importedName»
         default «CLASS.importedName»<«type.fullyQualifiedName»> «DATA_CONTAINER_IMPLEMENTED_INTERFACE_NAME»() {
@@ -305,7 +330,7 @@ class InterfaceTemplate extends BaseTemplate {
     def private generateNonnullMethod(MethodSignature method) '''
         «val ret = method.returnType»
         «val name = method.name»
-        «formatDataForJavaDoc(method, "@return " + asCode(ret.fullyQualifiedName) + " " + asCode(propertyNameFromGetter(method)) + ", or an empty list if it is not present")»
+        «accessorJavadoc(method, "an empty list")»
         «method.annotations.generateAnnotations»
         default «ret.importedNonNull» «name»() {
             return «CODEHELPERS.importedName».nonnull(«name.getGetterMethodForNonnull»());
@@ -313,7 +338,7 @@ class InterfaceTemplate extends BaseTemplate {
     '''
 
     def private String nullableType(Type type) {
-        if (type.isObject) {
+        if (type.isObject && (Types.isMapType(type) || Types.isListType(type))) {
             return type.importedNullable
         }
         return type.importedName