import java.util.LinkedHashSet
import java.util.List
import java.util.Map
+import java.util.Objects
import java.util.Set
import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl
import org.opendaylight.yangtools.binding.generator.util.Types
val Set<GeneratedProperty> properties
private static val METHOD_COMPARATOR = new AlphabeticallyTypeMemberComparator<MethodSignature>();
+ private static val APPEND_COMMA = "builder.append(\", \");";
+ private static val APPEND_COMMA_WITH_WS = "\n "+ APPEND_COMMA + "\n}";
+ private static val APPEND_ENDIF = " }\n";
+ private static val APPEND_END = "return builder.append(']').toString();";
/**
* Constructs new instance of this class.
«IF properties !== null»
«FOR f : properties»
private«IF _final» final«ENDIF» «f.returnType.importedName» «f.fieldName»;
- «val restrictions = f.returnType.restrictions»
- «IF !_final && restrictions != null && !(restrictions.lengthConstraints.empty)»
- «LengthGenerator.generateLengthChecker(f.fieldName.toString, f.returnType, restrictions.lengthConstraints)»
- «ENDIF»
«ENDFOR»
«ENDIF»
'''
*/
def private generateSetters() '''
«FOR field : properties SEPARATOR '\n'»
- «val restrictions = field.returnType.restrictions»
- «IF restrictions != null»
- «IF !restrictions.rangeConstraints.nullOrEmpty»
- «val rangeGenerator = AbstractRangeGenerator.forType(field.returnType)»
- «rangeGenerator.generateRangeChecker(field.name.toFirstUpper, restrictions.rangeConstraints)»
+ «/* 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»
+ «val rangeGenerator = AbstractRangeGenerator.forType(field.returnType)»
+ «rangeGenerator.generateRangeChecker(field.name.toFirstUpper, restrictions.rangeConstraints)»
- «ENDIF»
+ «ENDIF»
+ «IF !restrictions.lengthConstraints.nullOrEmpty»
+ «LengthGenerator.generateLengthChecker(field.fieldName.toString, field.returnType, restrictions.lengthConstraints)»
+
+ «ENDIF»
«ENDIF»
- public «type.name»«BUILDER» set«field.name.toFirstUpper»(«field.returnType.importedName» value) {
- «IF restrictions != null»
+ 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 (value != null) {
«IF !restrictions.rangeConstraints.nullOrEmpty»
«val rangeGenerator = AbstractRangeGenerator.forType(field.returnType)»
«rangeGenerator.generateRangeCheckerCall(field.name.toFirstUpper, "value.getValue()")»
«ENDIF»
«ENDIF»
- «generateRestrictions(field, "value")»
+ «IF !restrictions.lengthConstraints.nullOrEmpty»
+ «IF field.returnType instanceof ConcreteType»
+ «LengthGenerator.generateLengthCheckerCall(field.fieldName.toString, "value")»
+ «ELSE»
+ «LengthGenerator.generateLengthCheckerCall(field.fieldName.toString, "value.getValue()")»
+ «ENDIF»
+ «ENDIF»
}
«ENDIF»
+ «ENDIF»
this.«field.fieldName» = value;
return this;
}
«ENDIF»
'''
- def private generateRestrictions(GeneratedProperty field, String paramName) '''
- «val Type type = field.returnType»
- «val restrictions = type.getRestrictions»
- «IF restrictions !== null && !restrictions.lengthConstraints.empty»
- «IF type instanceof ConcreteType»
- «LengthGenerator.generateLengthCheckerCall(field.fieldName.toString, paramName)»
- «ELSE»
- «LengthGenerator.generateLengthCheckerCall(field.fieldName.toString, paramName + ".getValue()")»
- «ENDIF»
- «ENDIF»
- '''
-
def private CharSequence generateCopyConstructor(boolean impl) '''
«IF impl»private«ELSE»public«ENDIF» «type.name»«IF impl»«IMPL»«ELSE»«BUILDER»«ENDIF»(«type.name»«IF impl»«BUILDER»«ENDIF» base) {
«val allProps = new ArrayList(properties)»
int result = 1;
«FOR property : properties»
«IF property.returnType.name.contains("[")»
- result = prime * result + ((«property.fieldName» == null) ? 0 : «Arrays.importedName».hashCode(«property.fieldName»));
+ result = prime * result + «Arrays.importedName».hashCode(«property.fieldName»);
«ELSE»
- result = prime * result + ((«property.fieldName» == null) ? 0 : «property.fieldName».hashCode());
+ result = prime * result + «Objects.importedName».hashCode(«property.fieldName»);
«ENDIF»
«ENDFOR»
«IF augmentField != null»
- result = prime * result + ((«augmentField.name» == null) ? 0 : «augmentField.name».hashCode());
+ result = prime * result + «Objects.importedName».hashCode(«augmentField.name»);
«ENDIF»
hash = result;
«type.importedName» other = («type.importedName»)obj;
«FOR property : properties»
«val fieldName = property.fieldName»
- if («fieldName» == null) {
- if (other.«property.getterMethodName»() != null) {
- return false;
- }
«IF property.returnType.name.contains("[")»
- } else if(!«Arrays.importedName».equals(«fieldName», other.«property.getterMethodName»())) {
+ if (!«Arrays.importedName».equals(«fieldName», other.«property.getterMethodName»())) {
«ELSE»
- } else if(!«fieldName».equals(other.«property.getterMethodName»())) {
+ if (!«Objects.importedName».equals(«fieldName», other.«property.getterMethodName»())) {
«ENDIF»
return false;
}
// Simple case: we are comparing against self
«type.name»«IMPL» otherImpl = («type.name»«IMPL») obj;
«val fieldName = augmentField.name»
- if («fieldName» == null) {
- if (otherImpl.«fieldName» != null) {
- return false;
- }
- } else if(!«fieldName».equals(otherImpl.«fieldName»)) {
+ if (!«Objects.importedName».equals(«fieldName», otherImpl.«fieldName»)) {
return false;
}
} else {
@Override
public «String.importedName» toString() {
«StringBuilder.importedName» builder = new «StringBuilder.importedName» ("«type.name» [");
- boolean first = true;
-
- «FOR property : properties»
+ «FOR property : properties SEPARATOR APPEND_COMMA_WITH_WS AFTER APPEND_ENDIF»
if («property.fieldName» != null) {
- if (first) {
- first = false;
- } else {
- builder.append(", ");
- }
builder.append("«property.fieldName»=");
«IF property.returnType.name.contains("[")»
builder.append(«Arrays.importedName».toString(«property.fieldName»));
«ELSE»
builder.append(«property.fieldName»);
«ENDIF»
- }
«ENDFOR»
«IF augmentField != null»
- if (first) {
- first = false;
- } else {
- builder.append(", ");
- }
+ «IF !properties.empty»
+ «APPEND_COMMA»
+ «ENDIF»
builder.append("«augmentField.name»=");
- builder.append(«augmentField.name».values());
+ builder.append(«augmentField.name».values());«"\n"»
+ «APPEND_END»
+ «ELSE»
+ «IF properties.empty»
+ «APPEND_END»
+ «ELSE»
+ «APPEND_END»
+ «ENDIF»
«ENDIF»
- return builder.append(']').toString();
}
«ENDIF»
'''