Make JavaFileTemplate.importedName() identify all name collisions. 98/94298/12
authorIaroslav <iaroslav.kholiavko@pantheon.tech>
Wed, 23 Dec 2020 10:23:54 +0000 (12:23 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 21 Jun 2021 12:24:37 +0000 (14:24 +0200)
Refactor xtend files to use importedName instead of fillyQualifiedName
to prevent full package path in generated files.

JIRA: MDSAL-649
Change-Id: I569f46bb095512274b28c0decd5d2d2eefe7f7dd
Signed-off-by: Iaroslav Kholiavko <iaroslav.kholiavko@pantheon.tech>
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/BuilderTemplate.xtend
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/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/Bug5151Test.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/SpecializingLeafrefTest.java

index 90fb8f6b3107c1693fdf18eebc56308c75092eca..027bac6d555f2016eb3ad2370270c7539692261e 100644 (file)
@@ -132,7 +132,7 @@ class BuilderTemplate extends AbstractBuilderTemplate {
     def private Object generateConstructorFromIfc(Type impl) '''
         «IF (impl instanceof GeneratedType)»
             «IF impl.hasNonDefaultMethods»
-                public «type.name»(«impl.fullyQualifiedName» arg) {
+                public «type.name»(«impl.importedName» arg) {
                     «printConstructorPropertySetter(impl)»
                 }
             «ENDIF»
@@ -206,7 +206,7 @@ class BuilderTemplate extends AbstractBuilderTemplate {
          * Set fields from given grouping argument. Valid argument is instance of one of following types:
          * <ul>
          «FOR impl : type.getAllIfcs»
-         * <li>«impl.fullyQualifiedName»</li>
+         * <li>«impl.importedName»</li>
          «ENDFOR»
          * </ul>
          *
@@ -231,7 +231,7 @@ class BuilderTemplate extends AbstractBuilderTemplate {
     def private generateIfCheck(Type impl, List<Type> done) '''
         «IF (impl instanceof GeneratedType && (impl as GeneratedType).hasNonDefaultMethods)»
             «val implType = impl as GeneratedType»
-            if (arg instanceof «implType.fullyQualifiedName») {
+            if (arg instanceof «implType.importedName») {
                 «printPropertySetter(implType)»
                 isValidArg = true;
             }
@@ -243,7 +243,7 @@ class BuilderTemplate extends AbstractBuilderTemplate {
         «val ifc = implementedIfc as GeneratedType»
         «FOR getter : ifc.nonDefaultMethods»
             «IF BindingMapping.isGetterMethodName(getter.name) && !hasOverrideAnnotation(getter)»
-                «printPropertySetter(getter, '''((«ifc.fullyQualifiedName»)arg).«getter.name»()''', getter.propertyNameFromGetter)»;
+                «printPropertySetter(getter, '''((«ifc.importedName»)arg).«getter.name»()''', getter.propertyNameFromGetter)»;
             «ENDIF»
         «ENDFOR»
         «ENDIF»
@@ -258,10 +258,10 @@ class BuilderTemplate extends AbstractBuilderTemplate {
         if (Types.isListType(ownGetterType)) {
             val itemType = (ownGetterType as ParameterizedType).actualTypeArguments.get(0)
             return '''
-                this._«propertyName» = «CODEHELPERS.importedName».checkListFieldCast(«itemType.fullyQualifiedName».class, "«propertyName»", «retrieveProperty»)'''
+                this._«propertyName» = «CODEHELPERS.importedName».checkListFieldCast(«itemType.importedName».class, "«propertyName»", «retrieveProperty»)'''
         }
         return '''
-            this._«propertyName» = «CODEHELPERS.importedName».checkFieldCast(«ownGetter.returnType.fullyQualifiedName».class, "«propertyName»", «retrieveProperty»)'''
+            this._«propertyName» = «CODEHELPERS.importedName».checkFieldCast(«ownGetter.returnType.importedName».class, "«propertyName»", «retrieveProperty»)'''
     }
 
     private def List<Type> getBaseIfcs(GeneratedType type) {
@@ -291,7 +291,7 @@ class BuilderTemplate extends AbstractBuilderTemplate {
     private def List<String> toListOfNames(Collection<Type> types) {
         val List<String> names = new ArrayList
         for (type : types) {
-            names.add(type.fullyQualifiedName)
+            names.add(type.importedName)
         }
         return names
     }
index b41817df9b648b6300cb7d576af7c4ac27383db6..c2eb8ca20c954685391b639376c71f2d9230152c 100644 (file)
@@ -232,7 +232,7 @@ class InterfaceTemplate extends BaseTemplate {
         }
     '''
 
-    def private static accessorJavadoc(MethodSignature method, String orString) {
+    def private accessorJavadoc(MethodSignature method, String orString) {
         val reference = method.comment?.referenceDescription
         val propReturn = method.propertyNameFromGetter + ", or " + orString + " if it is not present."
 
@@ -240,7 +240,7 @@ class InterfaceTemplate extends BaseTemplate {
             Return «propReturn»
 
             «reference.formatReference»
-            @return {@code «method.returnType.fullyQualifiedName»} «propReturn»
+            @return {@code «method.returnType.importedName»} «propReturn»
         ''')
     }
 
index 20c0ed26f55f7f09ed2a7b870d38d376ece2f698..b295efa6931634b87e3f14a71336d75ed98f6bde 100644 (file)
@@ -41,7 +41,7 @@ public class Bug5151Test extends BaseCompilationTest {
         final File fooContainerFile = generatedFiles.get("FooContainer.java");
         assertNotNull(fooContainerFile);
         FileSearchUtil.assertFileContains(fooContainerFile,
-            "@return {@code java.lang.String} fooInContainer, or {@code null} if it is not present");
+            "@return {@code String} fooInContainer, or {@code null} if it is not present");
 
         final File fooDataFile = generatedFiles.get("FooData.java");
         assertNotNull(fooDataFile);
index 93a5fc0c3f68ed90735ce3f1dd9b568a0b8e4d22..e108e8c2f97f45e15b2ccda9ca96d651120d6cd7 100644 (file)
@@ -63,11 +63,11 @@ public class SpecializingLeafrefTest extends BaseCompilationTest {
     private static final String TAB_CLOSING_METHOD_BRACE = TAB + CLOSING_METHOD_BRACE;
     private static final String DTAB_CLOSING_METHOD_BRACE = DOUBLE_TAB + CLOSING_METHOD_BRACE;
 
-    private static final String FOO_GRP_REF = "org.opendaylight.yang.gen.v1.mdsal426.norev.FooGrp";
-    private static final String RESOLVED_LEAF_GRP_REF = "org.opendaylight.yang.gen.v1.mdsal426.norev.ResolvedLeafGrp";
+    private static final String FOO_GRP_REF = "FooGrp";
+    private static final String RESOLVED_LEAF_GRP_REF = "ResolvedLeafGrp";
 
     private static final String UNRESOLVED_GROUPING_REF =
-            "org.opendaylight.yang.gen.v1.mdsal426.norev.UnresolvedGrouping";
+            "UnresolvedGrouping";
 
     private static final String ARG_AS_FOO_GRP = "((" + FOO_GRP_REF + ")arg)";
 
@@ -217,9 +217,9 @@ public class SpecializingLeafrefTest extends BaseCompilationTest {
                 TAB_FIELDS_FROM_SIGNATURE,
                 DTAB_INIT_IS_VALID_ARG_FALSE,
                 doubleTab("if (arg instanceof " + FOO_GRP_REF + ") {"),
-                tripleTab("this._leaf1 = CodeHelpers.checkFieldCast(java.lang.String.class, \"leaf1\", "
+                tripleTab("this._leaf1 = CodeHelpers.checkFieldCast(String.class, \"leaf1\", "
                     + ARG_AS_FOO_GRP + ".getLeaf1());"),
-                tripleTab("this._leafList1 = CodeHelpers.checkListFieldCast(java.lang.String.class, \"leafList1\", "
+                tripleTab("this._leafList1 = CodeHelpers.checkListFieldCast(String.class, \"leafList1\", "
                     + ARG_AS_FOO_GRP + ".getLeafList1());"),
                 tripleTab("this._leaf2 = " + ARG_AS_FOO_GRP + ".getLeaf2();"),
                 TTAB_SET_IS_VALID_ARG_TRUE,
@@ -236,9 +236,9 @@ public class SpecializingLeafrefTest extends BaseCompilationTest {
     private static void barContBuilderConstructorFooGrpTest(final File file, final String content) {
         FileSearchUtil.assertFileContainsConsecutiveLines(file, content,
                 tab("public BarContBuilder(" + FOO_GRP_REF + " arg) {"),
-                doubleTab("this._leaf1 = CodeHelpers.checkFieldCast(java.lang.String.class, \"leaf1\", "
+                doubleTab("this._leaf1 = CodeHelpers.checkFieldCast(String.class, \"leaf1\", "
                     + "arg.getLeaf1());"),
-                doubleTab("this._leafList1 = CodeHelpers.checkListFieldCast(java.lang.String.class, \"leafList1\", "
+                doubleTab("this._leafList1 = CodeHelpers.checkListFieldCast(String.class, \"leafList1\", "
                     + "arg.getLeafList1());"),
                 doubleTab(LEAF2_ASSIGNMENT),
                 TAB_CLOSING_METHOD_BRACE);
@@ -258,7 +258,7 @@ public class SpecializingLeafrefTest extends BaseCompilationTest {
                 TAB_FIELDS_FROM_SIGNATURE,
                 DTAB_INIT_IS_VALID_ARG_FALSE,
                 doubleTab("if (arg instanceof " + UNRESOLVED_GROUPING_REF + ") {"),
-                tripleTab("this._leaf1 = CodeHelpers.checkFieldCast(java.lang.Boolean.class, \"leaf1\", (("
+                tripleTab("this._leaf1 = CodeHelpers.checkFieldCast(Boolean.class, \"leaf1\", (("
                     + UNRESOLVED_GROUPING_REF + ")arg).getLeaf1());"),
                 TTAB_SET_IS_VALID_ARG_TRUE,
                 DTAB_CLOSING_METHOD_BRACE,
@@ -269,7 +269,7 @@ public class SpecializingLeafrefTest extends BaseCompilationTest {
     private static void booleanContBuilderConstructorTest(final File file, final String content) {
         FileSearchUtil.assertFileContainsConsecutiveLines(file, content,
                 tab("public BooleanContBuilder(" + UNRESOLVED_GROUPING_REF + " arg) {"),
-                doubleTab("this._leaf1 = CodeHelpers.checkFieldCast(java.lang.Boolean.class, \"leaf1\", "
+                doubleTab("this._leaf1 = CodeHelpers.checkFieldCast(Boolean.class, \"leaf1\", "
                     + "arg.getLeaf1());"),
                 TAB_CLOSING_METHOD_BRACE);
     }