*/
package org.opendaylight.mdsal.binding.java.api.generator
+import com.google.common.collect.ImmutableMap
import com.google.common.collect.ImmutableSortedSet
import java.util.ArrayList
import java.util.Arrays
import org.opendaylight.yangtools.yang.binding.AugmentationHolder
import org.opendaylight.yangtools.yang.binding.DataObject
import org.opendaylight.yangtools.yang.binding.Identifiable
+import org.opendaylight.yangtools.yang.binding.CodeHelpers
/**
* Template for generating JAVA builder classes.
/**
* Constant with the name of the BuilderFor interface
*/
- val static BUILDERFOR = Builder.simpleName;
+ val static BUILDERFOR = Builder.simpleName;
/**
* Constant with suffix for the classes which are generated from the builder classes.
new(GeneratedType genType) {
super(genType)
this.properties = propertiesFromMethods(createMethods)
- importMap.put(Builder.simpleName, Builder.package.name)
+ addImport(Builder.simpleName, Builder.package.name)
}
/**
}
}
+ override isLocalInnerClass(String importedTypePackageName) {
+ // Builders do not have inner types
+ return false;
+ }
+
/**
* Template method which generates JAVA class body for builder class and for IMPL class.
*
*/
override body() '''
«wrapToDocumentation(formatDataForJavaDoc(type))»
- public class «type.name»«BUILDER» implements «BUILDERFOR» <«type.importedName»> {
+ public class «type.name»«BUILDER» implements «BUILDERFOR»<«type.importedName»> {
«generateFields(false)»
«FOR impl : ifc.getAllIfcs»
«generateIfCheck(impl, done)»
«ENDFOR»
- if (!isValidArg) {
- throw new IllegalArgumentException(
- "expected one of: «ifc.getAllIfcs.toListOfNames» \n" +
- "but was: " + arg
- );
- }
+ «CodeHelpers.importedName».validValue(isValidArg, arg, "«ifc.getAllIfcs.toListOfNames»");
}
«ENDIF»
«ENDIF»
def private generateMethodFieldsFromComment(GeneratedType type) '''
/**
- *Set fields from given grouping argument. Valid argument is instance of one of following types:
+ * Set fields from given grouping argument. Valid argument is instance of one of following types:
* <ul>
«FOR impl : type.getAllIfcs»
* <li>«impl.fullyQualifiedName»</li>
«/* FIXME: generate checkers as simple blocks and embed them directly in setters */»
«val restrictions = field.returnType.restrictions»
«IF !(field.returnType instanceof GeneratedType) && restrictions !== null»
- «IF !restrictions.rangeConstraints.nullOrEmpty»
+ «IF restrictions.rangeConstraint.present»
«val rangeGenerator = AbstractRangeGenerator.forType(field.returnType)»
- «rangeGenerator.generateRangeChecker(field.name.toFirstUpper, restrictions.rangeConstraints)»
+ «rangeGenerator.generateRangeChecker(field.name.toFirstUpper, restrictions.rangeConstraint.get)»
«ENDIF»
- «IF !restrictions.lengthConstraints.nullOrEmpty»
- «LengthGenerator.generateLengthChecker(field.fieldName.toString, field.returnType, restrictions.lengthConstraints)»
+ «IF restrictions.lengthConstraint.present»
+ «LengthGenerator.generateLengthChecker(field.fieldName.toString, field.returnType, restrictions.lengthConstraint.get)»
«ENDIF»
«ENDIF»
public «type.name»«BUILDER» set«field.name.toFirstUpper»(final «field.returnType.importedName» value) {
«IF !(field.returnType instanceof GeneratedType) && restrictions !== null»
- «IF restrictions !== null && (!restrictions.rangeConstraints.nullOrEmpty || !restrictions.lengthConstraints.nullOrEmpty)»
+ «IF restrictions !== null && (restrictions.rangeConstraint.present || restrictions.lengthConstraint.present)»
if (value != null) {
- «IF !restrictions.rangeConstraints.nullOrEmpty»
+ «IF restrictions.rangeConstraint.present»
«val rangeGenerator = AbstractRangeGenerator.forType(field.returnType)»
«IF field.returnType instanceof ConcreteType»
«rangeGenerator.generateRangeCheckerCall(field.name.toFirstUpper, "value")»
«rangeGenerator.generateRangeCheckerCall(field.name.toFirstUpper, "value.getValue()")»
«ENDIF»
«ENDIF»
- «IF !restrictions.lengthConstraints.nullOrEmpty»
+ «IF restrictions.lengthConstraint.present»
«IF field.returnType instanceof ConcreteType»
«LengthGenerator.generateLengthCheckerCall(field.fieldName.toString, "value")»
«ELSE»
«ENDFOR»
«IF augmentField !== null»
- public «type.name»«BUILDER» add«augmentField.name.toFirstUpper»(«Class.importedName»<? extends «augmentField.returnType.importedName»> augmentationType, «augmentField.returnType.importedName» augmentation) {
- if (augmentation == null) {
+ public «type.name»«BUILDER» add«augmentField.name.toFirstUpper»(«Class.importedName»<? extends «augmentField.returnType.importedName»> augmentationType, «augmentField.returnType.importedName» augmentationValue) {
+ if (augmentationValue == null) {
return remove«augmentField.name.toFirstUpper»(augmentationType);
}
this.«augmentField.name» = new «HashMap.importedName»<>();
}
- this.«augmentField.name».put(augmentationType, augmentation);
+ this.«augmentField.name».put(augmentationType, augmentationValue);
return this;
}
«ENDFOR»
«IF augmentField !== null»
«IF impl»
- switch (base.«augmentField.name».size()) {
- case 0:
- this.«augmentField.name» = «Collections.importedName».emptyMap();
- break;
- case 1:
- final «Map.importedName».Entry<«Class.importedName»<? extends «augmentField.returnType.importedName»>, «augmentField.returnType.importedName»> e = base.«augmentField.name».entrySet().iterator().next();
- this.«augmentField.name» = «Collections.importedName».<«Class.importedName»<? extends «augmentField.returnType.importedName»>, «augmentField.returnType.importedName»>singletonMap(e.getKey(), e.getValue());
- break;
- default :
- this.«augmentField.name» = new «HashMap.importedName»<>(base.«augmentField.name»);
- }
+ this.«augmentField.name» = «ImmutableMap.importedName».copyOf(base.«augmentField.name»);
«ELSE»
if (base instanceof «type.name»«IMPL») {
«type.name»«IMPL» impl = («type.name»«IMPL») base;
@SuppressWarnings("unchecked")
«IF addOverride»@Override«ENDIF»
public <E extends «augmentField.returnType.importedName»> E get«augmentField.name.toFirstUpper»(«Class.importedName»<E> augmentationType) {
- if (augmentationType == null) {
- throw new IllegalArgumentException("Augmentation Type reference cannot be NULL!");
- }
- return (E) «augmentField.name».get(augmentationType);
+ return (E) «augmentField.name».get(«CodeHelpers.importedName».nonNullValue(augmentationType, "augmentationType"));
}
«ENDIF»
'''