import static org.opendaylight.mdsal.binding.model.ri.BindingTypes.DATA_OBJECT
import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTABLE_AUGMENTATION_NAME
import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTATION_FIELD
-import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.DATA_CONTAINER_IMPLEMENTED_INTERFACE_NAME
+import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.BINDING_CONTRACT_IMPLEMENTED_INTERFACE_NAME
import com.google.common.collect.ImmutableList
import com.google.common.collect.ImmutableSet
«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»
+ /**
+ * 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()»
«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 «targetTypeName» build() {
return new «type.enclosedTypes.get(0).importedName»(this);
}
* 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)»
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)»
* Set fields from given grouping argument. Valid argument is instance of one of following types:
* <ul>
«FOR impl : type.getAllIfcs»
- * <li>«impl.importedName»</li>
+ * <li>{@link «impl.importedName»}</li>
«ENDFOR»
* </ul>
*
if (ownGetterType instanceof ParameterizedType) {
val itemType = ownGetterType.actualTypeArguments.get(0)
if (Types.isListType(ownGetterType)) {
- val importedClass = importedClass(itemType)
- if (importedClass !== null) {
- return printPropertySetter(retrieveProperty, propertyName, "checkListFieldCastIdentity", importedClass)
- }
return printPropertySetter(retrieveProperty, propertyName, "checkListFieldCast", itemType.importedName)
}
if (Types.isSetType(ownGetterType)) {
- val importedClass = importedClass(itemType)
- if (importedClass !== null) {
- return printPropertySetter(retrieveProperty, propertyName, "checkSetFieldCastIdentity", importedClass)
- }
return printPropertySetter(retrieveProperty, propertyName, "checkSetFieldCast", itemType.importedName)
}
- if (Types.CLASS.equals(ownGetterType)) {
- return printPropertySetter(retrieveProperty, propertyName, "checkFieldCastIdentity", itemType.identifier.importedName)
- }
}
return printPropertySetter(retrieveProperty, propertyName, "checkFieldCast", ownGetterType.importedName)
}
def private printPropertySetter(String retrieveProperty, String propertyName, String checkerName, String className) '''
this._«propertyName» = «CODEHELPERS.importedName».«checkerName»(«className».class, "«propertyName»", «retrieveProperty»)'''
- private def importedClass(Type type) {
- if (type instanceof ParameterizedType) {
- if (Types.CLASS.equals(type.rawType)) {
- return type.actualTypeArguments.get(0).identifier.importedName
- }
- }
- return null
- }
-
private def List<Type> getBaseIfcs(GeneratedType type) {
val List<Type> baseIfcs = new ArrayList();
for (ifc : type.implements) {
«IF augmentType !== null»
«val augmentTypeRef = augmentType.importedName»
- «val jlClassRef = CLASS.importedName»
«val hashMapRef = JU_HASHMAP.importedName»
/**
* Add an augmentation to this builder's product.
* @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.«BINDING_CONTRACT_IMPLEMENTED_INTERFACE_NAME»(), augmentation);
return this;
}
* @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);
}