BUG-8226: do not import nested classes 47/57947/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 11 May 2017 09:28:38 +0000 (11:28 +0200)
committerMartin Ciglan <martin.ciglan@pantheon.tech>
Mon, 29 May 2017 06:34:32 +0000 (06:34 +0000)
Importing a nested classes leads to a unused import warning, so compare
the declared package name with the class being generated and do not emit
an import declaration if the package name matches FQDN.

Change-Id: I4240cac663476c1405962631a9d173f5ed434ee9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit a6fdc323e0b9b76d99c0d976e7a5912a6fc42ef8)

binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/BaseTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderTemplate.xtend

index 5c5f49c07fb5312e77f80860c9fe122597206b19..3b85a5c42123aabde7246ed8d22cd8f0b335cd21 100644 (file)
@@ -59,27 +59,27 @@ abstract class BaseTemplate {
     }
 
     protected def imports() '''
-        «IF !importMap.empty»
-            «FOR entry : importMap.entrySet»
-                «IF !hasSamePackage(entry.value)»
-                    import «entry.value».«entry.key»;
-                «ENDIF»
-            «ENDFOR»
-        «ENDIF»
-
+        «FOR entry : importMap.entrySet»
+            «IF !hasSamePackage(entry.value) && !isLocalInnerClass(entry.value)»
+                import «entry.value».«entry.key»;
+            «ENDIF»
+        «ENDFOR»
     '''
 
     /**
      * Checks if packages of generated type and imported type is the same
      *
-     * @param importedTypePackageNam
-     * the package name of imported type
+     * @param importedTypePackageName the package name of imported type
      * @return true if the packages are the same false otherwise
      */
     final private def boolean hasSamePackage(String importedTypePackageName) {
         return type.packageName.equals(importedTypePackageName);
     }
 
+    def isLocalInnerClass(String importedTypePackageName) {
+        return type.fullyQualifiedName.equals(importedTypePackageName);
+    }
+
     protected abstract def CharSequence body();
 
     // Helper patterns
index d3f833043aa868152f42c18af3349b80894366ce..1dd08f87b98b0a6429dc42d8722f8a43b1928bf5 100644 (file)
@@ -53,7 +53,7 @@ class BuilderTemplate extends BaseTemplate {
     /**
      * Constant with the name of the BuilderFor interface
      */
-     val static BUILDERFOR = Builder.simpleName;
+    val static BUILDERFOR = Builder.simpleName;
 
     /**
      * Constant with suffix for the classes which are generated from the builder classes.
@@ -210,6 +210,11 @@ class BuilderTemplate extends BaseTemplate {
         }
     }
 
+    override isLocalInnerClass(String importedTypePackageName) {
+        // Builders do not have inner types
+        return false;
+    }
+
     /**
      * Template method which generates JAVA class body for builder class and for IMPL class.
      *
@@ -217,7 +222,7 @@ class BuilderTemplate extends BaseTemplate {
      */
     override body() '''
         «wrapToDocumentation(formatDataForJavaDoc(type))»
-        public class «type.name»«BUILDER» implements «BUILDERFOR» <«type.importedName»> {
+        public class «type.name»«BUILDER» implements «BUILDERFOR»<«type.importedName»> {
 
             «generateFields(false)»