Use Map.of() instead of Collections.emptyMap() in builders 44/100844/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Apr 2022 15:02:43 +0000 (17:02 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Apr 2022 15:21:44 +0000 (17:21 +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>
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 c0e4ef72edc0ae61ae0ef9e3bf32584cbe4add28..d920c519085644d984989c4c4ec6e30cef926bc9 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»
 
             /**
@@ -427,7 +429,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.
@@ -437,12 +438,11 @@ class BuilderTemplate extends AbstractBuilderTemplate {
               * @throws NullPointerException if {@code augmentation} is null
               */
             public «type.name» addAugmentation(«augmentTypeRef» augmentation) {
-                «jlClassRef»<? extends «augmentTypeRef»> augmentationType = augmentation.«BINDING_CONTRACT_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.«BINDING_CONTRACT_IMPLEMENTED_INTERFACE_NAME»(), augmentation);
                 return this;
             }
 
@@ -453,7 +453,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);
                 }