Use Map.of() instead of Collections.emptyMap() in builders 43/101043/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Apr 2022 15:02:43 +0000 (17:02 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 10 May 2022 09:25:24 +0000 (11:25 +0200)
Augmentation field is not used by the builder-internal implementation,
hence we can inline the codegen. Also use Map.of() instead of
emptyMap().

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

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/main/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderTemplate.xtend

index a3f048d4e299a50565f9be168baed8420fbb0c4c..c558ada0f59c4c26259c2b8aa8b011da715b36da 100644 (file)
@@ -7,11 +7,8 @@
  */
 package org.opendaylight.mdsal.binding.java.api.generator
 
-import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTATION_FIELD
-
 import java.util.ArrayList
 import java.util.Collection
-import java.util.Collections
 import java.util.Comparator
 import java.util.List
 import java.util.Set
@@ -79,13 +76,6 @@ abstract class AbstractBuilderTemplate extends BaseTemplate {
         «ENDIF»
     '''
 
-    def protected final generateAugmentField() {
-        val augmentTypeRef = augmentType.importedName
-        return '''
-           «JU_MAP.importedName»<«CLASS.importedName»<? extends «augmentTypeRef»>, «augmentTypeRef»> «AUGMENTATION_FIELD» = «Collections.importedName».emptyMap();
-        '''
-    }
-
     /**
      * Template method which generate getter methods for IMPL class.
      *
index 2a23fe1a90a776e0d971fc4137cfdac66c99b50d..6723efdfc37d14728226c51b343c5ff04557f09c 100644 (file)
@@ -70,7 +70,9 @@ class BuilderTemplate extends AbstractBuilderTemplate {
             «constantsDeclarations()»
 
             «IF augmentType !== null»
-                «generateAugmentField()»
+                «val augmentTypeRef = augmentType.importedName»
+                «val mapTypeRef = JU_MAP.importedName»
+                «mapTypeRef»<«CLASS.importedName»<? extends «augmentTypeRef»>, «augmentTypeRef»> «AUGMENTATION_FIELD» = «mapTypeRef».of();
             «ENDIF»
 
             /**
@@ -447,7 +449,6 @@ class BuilderTemplate extends AbstractBuilderTemplate {
 
         «IF augmentType !== null»
             «val augmentTypeRef = augmentType.importedName»
-            «val jlClassRef = CLASS.importedName»
             «val hashMapRef = JU_HASHMAP.importedName»
             /**
               * Add an augmentation to this builder's product.
@@ -457,12 +458,11 @@ class BuilderTemplate extends AbstractBuilderTemplate {
               * @throws NullPointerException if {@code augmentation} is null
               */
             public «type.name» addAugmentation(«augmentTypeRef» augmentation) {
-                «jlClassRef»<? extends «augmentTypeRef»> augmentationType = augmentation.«DATA_CONTAINER_IMPLEMENTED_INTERFACE_NAME»();
                 if (!(this.«AUGMENTATION_FIELD» instanceof «hashMapRef»)) {
                     this.«AUGMENTATION_FIELD» = new «hashMapRef»<>();
                 }
 
-                this.«AUGMENTATION_FIELD».put(augmentationType, augmentation);
+                this.«AUGMENTATION_FIELD».put(augmentation.«DATA_CONTAINER_IMPLEMENTED_INTERFACE_NAME»(), augmentation);
                 return this;
             }
 
@@ -473,7 +473,7 @@ class BuilderTemplate extends AbstractBuilderTemplate {
               * @param augmentationType augmentation type to be removed
               * @return this builder
               */
-            public «type.name» removeAugmentation(«jlClassRef»<? extends «augmentTypeRef»> augmentationType) {
+            public «type.name» removeAugmentation(«CLASS.importedName»<? extends «augmentTypeRef»> augmentationType) {
                 if (this.«AUGMENTATION_FIELD» instanceof «hashMapRef») {
                     this.«AUGMENTATION_FIELD».remove(augmentationType);
                 }