«clazz.importedNumber» _constraint = «clazz.importedNumber».valueOf(«paramName»«IF isNestedType».getValue()«ENDIF».length«IF !isArray»()«ENDIF»);
'''
- def printRangeConstraint(Type returnType, String paramName, boolean isNestedType) '''
- «IF BigDecimal.canonicalName.equals(returnType.fullyQualifiedName)»
- «BigDecimal.importedName» _constraint = new «BigDecimal.importedName»(«paramName»«IF isNestedType».getValue()«ENDIF».toString());
- «ELSE»
- «IF isNestedType»
- «val propReturnType = findProperty(returnType as GeneratedTransferObject, "value").returnType»
- «IF propReturnType.fullyQualifiedName.equals(BigInteger.canonicalName)»
- «BigInteger.importedName» _constraint = «paramName».getValue();
- «ELSE»
- «BigInteger.importedName» _constraint = «BigInteger.importedName».valueOf(«paramName».getValue());
- «ENDIF»
- «ELSE»
- «IF returnType.fullyQualifiedName.equals(BigInteger.canonicalName)»
- «BigInteger.importedName» _constraint = «paramName»;
- «ELSE»
- «BigInteger.importedName» _constraint = «BigInteger.importedName».valueOf(«paramName»);
- «ENDIF»
- «ENDIF»
- «ENDIF»
- '''
-
def protected generateToString(Collection<GeneratedProperty> properties) '''
«IF !properties.empty»
@Override
return "new " + number + "(\"" + value + "\")"
}
- def private GeneratedProperty findProperty(GeneratedTransferObject gto, String name) {
+ def protected GeneratedProperty findProperty(GeneratedTransferObject gto, String name) {
val props = gto.properties
for (prop : props) {
if (prop.name.equals(name)) {
}
'''
+ def private printRangeConstraint(Type returnType, String paramName, boolean isNestedType) '''
+ «IF BigDecimal.canonicalName.equals(returnType.fullyQualifiedName)»
+ «BigDecimal.importedName» _constraint = new «BigDecimal.importedName»(«paramName»«IF isNestedType».getValue()«ENDIF».toString());
+ «ELSE»
+ «IF isNestedType»
+ «val propReturnType = findProperty(returnType as GeneratedTransferObject, "value").returnType»
+ «IF propReturnType.fullyQualifiedName.equals(BigInteger.canonicalName)»
+ «BigInteger.importedName» _constraint = «paramName».getValue();
+ «ELSE»
+ «BigInteger.importedName» _constraint = «BigInteger.importedName».valueOf(«paramName».getValue());
+ «ENDIF»
+ «ELSE»
+ «IF returnType.fullyQualifiedName.equals(BigInteger.canonicalName)»
+ «BigInteger.importedName» _constraint = «paramName»;
+ «ELSE»
+ «BigInteger.importedName» _constraint = «BigInteger.importedName».valueOf(«paramName»);
+ «ENDIF»
+ «ENDIF»
+ «ENDIF»
+ '''
+
def private generateLengthMethod(String methodName, Type type, String className, String varName) '''
«val Restrictions restrictions = type.restrictions»
«IF restrictions != null && !(restrictions.lengthConstraints.empty)»
protected val GeneratedTransferObject genTO;
+ private val AbstractRangeGenerator<?> rangeGenerator
+
/**
* Creates instance of this class with concrete <code>genType</code>.
*
this.enums = genType.enumerations
this.consts = genType.constantDefinitions
this.enclosedGeneratedTypes = genType.enclosedTypes
+
+ if (restrictions != null && !restrictions.rangeConstraints.nullOrEmpty) {
+ rangeGenerator = AbstractRangeGenerator.forType(findProperty(genType, "value").returnType)
+ Preconditions.checkNotNull(rangeGenerator)
+ } else {
+ rangeGenerator = null
+ }
}
/**
!restrictions.lengthConstraints.nullOrEmpty)»
«generateConstraints»
+ «IF !restrictions.rangeConstraints.nullOrEmpty»
+ «rangeGenerator.generateRangeChecker("_value", restrictions.rangeConstraints)»
+ «ENDIF»
«ENDIF»
+
«constructors»
«defaultInstance»
«generateLengthRestriction(returnType, restrictions, paramName, isNestedType)»
«ENDIF»
«IF !restrictions.rangeConstraints.empty»
- «generateRangeRestriction(returnType, paramName, isNestedType)»
+ if («paramName» != null) {
+ «IF isNestedType»
+ «rangeGenerator.generateRangeCheckerCall(paramName, paramName + ".getValue()")»
+ «ELSE»
+ «rangeGenerator.generateRangeCheckerCall(paramName, paramName)»
+ «ENDIF»
+ }
«ENDIF»
«ENDIF»
'''
}
'''
- def private generateRangeRestriction(Type returnType, String paramName, boolean isNestedType) '''
- if («paramName» != null) {
- «printRangeConstraint(returnType, paramName, isNestedType)»
- boolean isValidRange = false;
- for («Range.importedName»<«returnType.importedNumber»> r : «IF isNestedType»«returnType.importedName».«ENDIF»range()) {
- if (r.contains(_constraint)) {
- isValidRange = true;
- }
- }
- if (!isValidRange) {
- throw new IllegalArgumentException(String.format("Invalid range: %s, expected: %s.", «paramName», «IF isNestedType»«returnType.importedName».«ENDIF»range()));
- }
- }
- '''
-
def protected copyConstructor() '''
/**
* Creates a copy from Source Object.