From 2789476b592b0df9eab7b83f3a9d2a2b9cd60099 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 27 Apr 2022 17:02:43 +0200 Subject: [PATCH] Use Map.of() instead of Collections.emptyMap() in builders 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 --- .../java/api/generator/AbstractBuilderTemplate.xtend | 10 ---------- .../binding/java/api/generator/BuilderTemplate.xtend | 10 +++++----- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/AbstractBuilderTemplate.xtend b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/AbstractBuilderTemplate.xtend index a3f048d4e2..c558ada0f5 100644 --- a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/AbstractBuilderTemplate.xtend +++ b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/AbstractBuilderTemplate.xtend @@ -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», «augmentTypeRef»> «AUGMENTATION_FIELD» = «Collections.importedName».emptyMap(); - ''' - } - /** * Template method which generate getter methods for IMPL class. * diff --git a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderTemplate.xtend b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderTemplate.xtend index c0e4ef72ed..d920c51908 100644 --- a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderTemplate.xtend +++ b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderTemplate.xtend @@ -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», «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» 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» augmentationType) { + public «type.name» removeAugmentation(«CLASS.importedName» augmentationType) { if (this.«AUGMENTATION_FIELD» instanceof «hashMapRef») { this.«AUGMENTATION_FIELD».remove(augmentationType); } -- 2.36.6