X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-java-api-generator%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fjava%2Fapi%2Fgenerator%2FBuilderTemplate.xtend;h=e28bbd771515a506cb49ae46c045fb7cb215d09d;hb=3d507d2253acd7f24b9e89e9a5ab86e8cd3aa753;hp=e02b1615c628ead499ae1cc2fa9e76186a6c665c;hpb=55f2409e9afd9eb7b82213bdd9e710b4e206495a;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 e02b1615c6..e28bbd7715 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 @@ -12,8 +12,6 @@ import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.AUGMENTA 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 @@ -22,6 +20,7 @@ import java.util.List import java.util.Map import java.util.Set import java.util.regex.Pattern +import org.opendaylight.mdsal.binding.model.api.AnnotationType import org.opendaylight.mdsal.binding.model.api.GeneratedProperty import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject import org.opendaylight.mdsal.binding.model.api.GeneratedType @@ -35,10 +34,6 @@ import org.opendaylight.yangtools.concepts.Builder 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. @@ -51,13 +46,6 @@ class BuilderTemplate extends AbstractBuilderTemplate { static val AUGMENTATION_FIELD_UPPER = AUGMENTATION_FIELD.toFirstUpper - 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) - ); - /** * Constructs new instance of this class. * @throws IllegalArgumentException if genType equals null @@ -79,6 +67,7 @@ class BuilderTemplate extends AbstractBuilderTemplate { */ override body() ''' «wrapToDocumentation(formatDataForJavaDoc(targetType))» + «targetType.annotations.generateDeprecatedAnnotation» public class «type.name» implements «Builder.importedName»<«targetType.importedName»> { «generateFields(false)» @@ -103,7 +92,7 @@ class BuilderTemplate extends AbstractBuilderTemplate { «generateSetters» - @«Override.importedName» + @«OVERRIDE.importedName» public «targetType.name» build() { return new «type.enclosedTypes.get(0).importedName»(this); } @@ -112,6 +101,14 @@ class BuilderTemplate extends AbstractBuilderTemplate { } ''' + override generateDeprecatedAnnotation(AnnotationType ann) { + val forRemoval = ann.getParameter("forRemoval") + if (forRemoval !== null) { + return "@" + DEPRECATED.importedName + "(forRemoval = " + forRemoval.value + ")" + } + return "@" + SUPPRESS_WARNINGS.importedName + "(\"deprecation\")" + } + /** * Generate default constructor and constructor for every implemented interface from uses statements. */ @@ -260,8 +257,9 @@ class BuilderTemplate extends AbstractBuilderTemplate { «val cValue = c.value as Map» «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»)); @@ -287,7 +285,7 @@ class BuilderTemplate extends AbstractBuilderTemplate { } } «ENDIF» - this.«field.fieldName.toString» = values; + this.«field.fieldName» = values; return this; } @@ -296,31 +294,34 @@ class BuilderTemplate extends AbstractBuilderTemplate { 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» '''