Use E$$ to capture augmentation type 12/81012/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 18 Mar 2019 13:55:43 +0000 (14:55 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 19 Mar 2019 15:00:07 +0000 (16:00 +0100)
'E' is a valid generated identifier, which can lead to conflicts
when generating augmentable implementations.

Change-Id: I9d69d06e18301eff788c101e389a6d0b5365ad38
JIRA: MDSAL-425
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 8dbc1c0794dbd6be19ae0e724b4cc21714c6739f)

binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/AbstractBuilderTemplate.xtend
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/CompilationTest.java
binding/mdsal-binding-java-api-generator/src/test/resources/compilation/mdsal425/mdsal425.yang [new file with mode: 0644]
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/Augmentable.java

index ad9f949ed9716cd22114b95016c6c2b343828a8e..a3e8b92892364c574f50ac7ccef348eb5e9ad2be 100644 (file)
@@ -125,10 +125,10 @@ abstract class AbstractBuilderTemplate extends BaseTemplate {
         «ENDIF»
         «IF augmentType !== null»
 
-            @SuppressWarnings("unchecked")
+            @«SuppressWarnings.importedName»({ "unchecked", "checkstyle:methodTypeParameterName"})
             «IF addOverride»@«Override.importedName»«ENDIF»
-            public <E extends «augmentType.importedName»> E «AUGMENTABLE_AUGMENTATION_NAME»(«Class.importedName»<E> augmentationType) {
-                return (E) «AUGMENTATION_FIELD».get(«CodeHelpers.importedName».nonNullValue(augmentationType, "augmentationType"));
+            public <E$$ extends «augmentType.importedName»> E$$ «AUGMENTABLE_AUGMENTATION_NAME»(«Class.importedName»<E$$> augmentationType) {
+                return (E$$) «AUGMENTATION_FIELD».get(«CodeHelpers.importedName».nonNullValue(augmentationType, "augmentationType"));
             }
         «ENDIF»
     '''
index 344962e2e54064d649a063446c6375606e7dfbee..f202ad58524d7c8fd38bbf1965270586d2a1a874 100644 (file)
@@ -665,6 +665,15 @@ public class CompilationTest extends BaseCompilationTest {
         CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 
+    @Test
+    public void testMdsal425() throws Exception {
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal425");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal425");
+        generateTestSources("/compilation/mdsal425", sourcesOutputDir);
+        CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+        CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
+    }
+
     private static void testReturnTypeIdentityref(final Class<?> clazz, final String methodName,
             final String returnTypeStr) throws NoSuchMethodException {
         Method method = clazz.getMethod(methodName);
diff --git a/binding/mdsal-binding-java-api-generator/src/test/resources/compilation/mdsal425/mdsal425.yang b/binding/mdsal-binding-java-api-generator/src/test/resources/compilation/mdsal425/mdsal425.yang
new file mode 100644 (file)
index 0000000..39caaac
--- /dev/null
@@ -0,0 +1,9 @@
+module mdsal425 {
+    namespace "urn:odl:mdsal425";
+    prefix mdsal425;
+
+    container e {
+
+    }
+}
+
index d65097556c73d9f36dc035a26d28f553ad9aa75b..5b8fee8cd8ce1510424eb4e7bdc6abee7dbdbf92 100644 (file)
@@ -26,9 +26,11 @@ public interface Augmentable<T> {
     /**
      * Returns instance of augmentation.
      *
-     * @param augmentationType
-     *            Type of augmentation to be returned.
+     * @param augmentationType Type of augmentation to be returned.
+     * @param <E$$> Type capture for augmentation type
      * @return instance of augmentation.
      */
-    <E extends Augmentation<T>> @Nullable E augmentation(Class<E> augmentationType);
+    // E$$ is an identifier which cannot be generated from models.
+    @SuppressWarnings("checkstyle:methodTypeParameterName")
+    <E$$ extends Augmentation<T>> @Nullable E$$ augmentation(Class<E$$> augmentationType);
 }