- def private generateLengthRestriction(Type type, String paramName, String getterName, boolean isNestedType, boolean isArray) '''
- «val restrictions = type.getRestrictions»
- if («paramName» != null) {
- «val clazz = restrictions.lengthConstraints.iterator.next.min.class»
- «printLengthConstraint(type, clazz, paramName, isNestedType, isArray)»
- boolean isValidLength = false;
- for («Range.importedName»<«clazz.importedNumber»> r : «getterName»()) {
- if (r.contains(_constraint)) {
- isValidLength = true;
- }
- }
- if (!isValidLength) {
- throw new IllegalArgumentException(String.format("Invalid length: %s, expected: %s.", «paramName», «getterName»));
- }
- }
- '''
-
- def private generateLengthMethod(String methodName, Type type, String className, String varName) '''