X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=binding%2Fmdsal-binding-java-api-generator%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fjava%2Fapi%2Fgenerator%2FBuilderTemplate.xtend;h=79567d51bcbf6a8088bed8b6c7c967e1302955a4;hb=938a70d61dc8948d65e8c7ca64ffcbf4e6162b68;hp=dbc7846d57b4a36d7bcfbfa8bc098e5a58be80ac;hpb=4c2b08900d7a4a06bf99698801f339c8bf22e07c;p=mdsal.git 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 dbc7846d57..79567d51bc 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,11 +70,26 @@ 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» + /** + * Construct an empty builder. + */ + public «type.name»() { + // No-op + } + «generateConstructorsFromIfcs()» + «val targetTypeName = targetType.importedName» + /** + * Construct a builder initialized with state from specified {@link «targetTypeName»}. + * + * @param base «targetTypeName» from which the builder should be initialized + */ public «generateCopyConstructor(targetType, type.enclosedTypes.get(0))» «generateMethodFieldsFrom()» @@ -88,11 +103,11 @@ class BuilderTemplate extends AbstractBuilderTemplate { «generateSetters» /** - * A new {@link «targetType.name»} instance. + * A new {@link «targetTypeName»} instance. * - * @return A new {@link «targetType.name»} instance. + * @return A new {@link «targetTypeName»} instance. */ - public «targetType.name» build() { + public «targetType.importedNonNull» build() { return new «type.enclosedTypes.get(0).importedName»(this); } @@ -112,9 +127,6 @@ class BuilderTemplate extends AbstractBuilderTemplate { * Generate default constructor and constructor for every implemented interface from uses statements. */ def private generateConstructorsFromIfcs() ''' - public «type.name»() { - } - «IF (!(targetType instanceof GeneratedTransferObject))» «FOR impl : targetType.implements SEPARATOR "\n"» «generateConstructorFromIfc(impl)» @@ -128,9 +140,16 @@ class BuilderTemplate extends AbstractBuilderTemplate { def private Object generateConstructorFromIfc(Type impl) ''' «IF (impl instanceof GeneratedType)» «IF impl.hasNonDefaultMethods» - public «type.name»(«impl.importedName» arg) { + «val typeName = impl.importedName» + /** + * Construct a new builder initialized from specified {@link «typeName»}. + * + * @param arg «typeName» from which the builder should be initialized + */ + public «type.name»(«typeName» arg) { «printConstructorPropertySetter(impl)» } + «ENDIF» «FOR implTypeImplement : impl.implements» «generateConstructorFromIfc(implTypeImplement)» @@ -202,7 +221,7 @@ class BuilderTemplate extends AbstractBuilderTemplate { * Set fields from given grouping argument. Valid argument is instance of one of following types: * * @@ -410,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. @@ -420,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; } @@ -436,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); } @@ -497,6 +514,14 @@ class BuilderTemplate extends AbstractBuilderTemplate { } private def generateAugmentation() ''' + /** + * Return the specified augmentation, if it is present in this builder. + * + * @param augmentation type + * @param augmentationType augmentation type class + * @return Augmentation object from this builder, or {@code null} if not present + * @throws «NPE.importedName» if {@code augmentType} is {@code null} + */ @«SUPPRESS_WARNINGS.importedName»({ "unchecked", "checkstyle:methodTypeParameterName"}) public E$$ «AUGMENTABLE_AUGMENTATION_NAME»(«CLASS.importedName» augmentationType) { return (E$$) «AUGMENTATION_FIELD».get(«JU_OBJECTS.importedName».requireNonNull(augmentationType));