import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTATION_FIELD
import com.google.common.collect.ImmutableList
-import com.google.common.collect.ImmutableMap
-import java.math.BigInteger
import java.util.ArrayList
import java.util.Collection
import java.util.HashMap
import org.opendaylight.yangtools.yang.binding.AugmentationHolder
import org.opendaylight.yangtools.yang.binding.CodeHelpers
import org.opendaylight.yangtools.yang.binding.DataObject
-import org.opendaylight.yangtools.yang.common.Uint8
-import org.opendaylight.yangtools.yang.common.Uint16
-import org.opendaylight.yangtools.yang.common.Uint64
-import org.opendaylight.yangtools.yang.common.Uint32
/**
* Template for generating JAVA builder classes.
*/
public static val BUILDER = "Builder";
- static val UINT_TYPES = ImmutableMap.of(
- Types.typeForClass(Uint8), Types.typeForClass(Short),
- Types.typeForClass(Uint16), Types.typeForClass(Integer),
- Types.typeForClass(Uint32), Types.typeForClass(Long),
- Types.typeForClass(Uint64), Types.typeForClass(BigInteger)
- );
+ static val AUGMENTATION_FIELD_UPPER = AUGMENTATION_FIELD.toFirstUpper
/**
* Constructs new instance of this class.
«val cValue = c.value as Map<String, String>»
«val String fieldSuffix = c.getName.substring(TypeConstants.PATTERN_CONSTANT_NAME.length)»
«IF cValue.size == 1»
- private static final «Pattern.importedName» «Constants.MEMBER_PATTERN_LIST»«fieldSuffix» = «Pattern.importedName».compile("«cValue.keySet.get(0).escapeJava»");
- private static final String «Constants.MEMBER_REGEX_LIST»«fieldSuffix» = "«cValue.values.get(0).escapeJava»";
+ «val firstEntry = cValue.entrySet.iterator.next»
+ private static final «Pattern.importedName» «Constants.MEMBER_PATTERN_LIST»«fieldSuffix» = «Pattern.importedName».compile("«firstEntry.key.escapeJava»");
+ private static final String «Constants.MEMBER_REGEX_LIST»«fieldSuffix» = "«firstEntry.value.escapeJava»";
«ELSE»
private static final «Pattern.importedName»[] «Constants.MEMBER_PATTERN_LIST»«fieldSuffix» = «CodeHelpers.importedName».compilePatterns(«ImmutableList.importedName».of(
«FOR v : cValue.keySet SEPARATOR ", "»"«v.escapeJava»"«ENDFOR»));
}
}
«ENDIF»
- this.«field.fieldName.toString» = values;
+ this.«field.fieldName» = values;
return this;
}
def private generateSetter(GeneratedProperty field, Type actualType) '''
«val restrictions = restrictionsForSetter(actualType)»
«IF restrictions !== null»
+
«generateCheckers(field, restrictions, actualType)»
«ENDIF»
«val setterName = "set" + field.getName.toFirstUpper»
public «type.getName» «setterName»(final «field.returnType.importedName» value) {
- «IF restrictions !== null»
- if (value != null) {
- «checkArgument(field, restrictions, actualType, "value")»
- }
- «ENDIF»
- this.«field.fieldName.toString» = value;
+ «IF restrictions !== null»
+ if (value != null) {
+ «checkArgument(field, restrictions, actualType, "value")»
+ }
+ «ENDIF»
+ this.«field.fieldName» = value;
return this;
}
«val uintType = UINT_TYPES.get(field.returnType)»
«IF uintType !== null»
- /**
- * Utility migration setter.
- *
- * @deprecated Use {#link «setterName»(«field.returnType.importedName»)} instead.
- */
- @Deprecated(forRemoval = true)
- public «type.getName» «setterName»(final «uintType.importedName» value) {
- return «setterName»(«CodeHelpers.importedName».compatUint(value));
- }
+ /**
+ * Utility migration setter.
+ *
+ * @param value field value in legacy type
+ * @return this builder
+ * @deprecated Use {#link «setterName»(«field.returnType.importedJavadocName»)} instead.
+ */
+ @Deprecated(forRemoval = true)
+ public «type.getName» «setterName»(final «uintType.importedName» value) {
+ return «setterName»(«CodeHelpers.importedName».compatUint(value));
+ }
«ENDIF»
'''
«ENDFOR»
«IF augmentType !== null»
- public «type.name» add«AUGMENTATION_FIELD.toFirstUpper»(«Class.importedName»<? extends «augmentType.importedName»> augmentationType, «augmentType.importedName» augmentationValue) {
+ «val augmentTypeRef = augmentType.importedName»
+ public «type.name» add«AUGMENTATION_FIELD_UPPER»(«Class.importedName»<? extends «augmentTypeRef»> augmentationType, «augmentTypeRef» augmentationValue) {
if (augmentationValue == null) {
- return remove«AUGMENTATION_FIELD.toFirstUpper»(augmentationType);
+ return remove«AUGMENTATION_FIELD_UPPER»(augmentationType);
}
if (!(this.«AUGMENTATION_FIELD» instanceof «HashMap.importedName»)) {
return this;
}
- public «type.name» remove«AUGMENTATION_FIELD.toFirstUpper»(«Class.importedName»<? extends «augmentType.importedName»> augmentationType) {
+ public «type.name» remove«AUGMENTATION_FIELD_UPPER»(«Class.importedName»<? extends «augmentTypeRef»> augmentationType) {
if (this.«AUGMENTATION_FIELD» instanceof «HashMap.importedName») {
this.«AUGMENTATION_FIELD».remove(augmentationType);
}