Bug 3051: Fixed pattern checks in generated DTOs
[mdsal.git] / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / yangtools / sal / java / api / generator / ClassTemplate.xtend
index dba7356f9bd68cd61ce72d99407a8bcebc26c28b..6699d502006c1682cea241daa1d322b033a67d8c 100644 (file)
@@ -165,6 +165,10 @@ class ClassTemplate extends BaseTemplate {
     def private generateLengthMethod(String methodName, String varName) '''
         «IF restrictions != null && !(restrictions.lengthConstraints.empty)»
             «val numberClass = restrictions.lengthConstraints.iterator.next.min.class»
+            /**
+             * @deprecated This method is slated for removal in a future release. See BUG-1485 for details.
+             */
+            @Deprecated
             public static «List.importedName»<«Range.importedName»<«numberClass.importedNumber»>> «methodName»() {
                 return «varName»;
             }
@@ -174,6 +178,10 @@ class ClassTemplate extends BaseTemplate {
     def private generateRangeMethod(String methodName, String varName) '''
         «IF restrictions != null && !(restrictions.rangeConstraints.empty)»
             «val returnType = allProperties.iterator.next.returnType»
+            /**
+             * @deprecated This method is slated for removal in a future release. See BUG-1485 for details.
+             */
+            @Deprecated
             public static «List.importedName»<«Range.importedName»<«returnType.importedNumber»>> «methodName»() {
                 return «varName»;
             }
@@ -189,7 +197,7 @@ class ClassTemplate extends BaseTemplate {
         «IF !enclosedGeneratedTypes.empty»
             «FOR innerClass : enclosedGeneratedTypes SEPARATOR "\n"»
                 «IF (innerClass instanceof GeneratedTransferObject)»
-                    «val classTemplate = new ClassTemplate(innerClass as GeneratedTransferObject
+                    «val classTemplate = new ClassTemplate(innerClass)»
                     «classTemplate.generateAsInnerClass»
 
                 «ENDIF»
@@ -282,21 +290,20 @@ class ClassTemplate extends BaseTemplate {
 
             «FOR c : consts»
                 «IF c.name == TypeConstants.PATTERN_CONSTANT_NAME && c.value instanceof List<?>»
-            boolean valid = false;
             for (Pattern p : patterns) {
-                if (p.matcher(_value).matches()) {
-                    valid = true;
-                    break;
-                }
+                «Preconditions.importedName».checkArgument(p.matcher(_value).matches(), "Supplied value \"%s\" does not match any of the permitted patterns %s", _value, «TypeConstants.PATTERN_CONSTANT_NAME»);
             }
 
-            «Preconditions.importedName».checkArgument(valid, "Supplied value \"%s\" does not match any of the permitted patterns %s", _value, «TypeConstants.PATTERN_CONSTANT_NAME»);
                 «ENDIF»
             «ENDFOR»
         «ENDIF»
 
         «FOR p : properties»
+            «IF p.returnType.importedName.contains("[]")»
+            this.«p.fieldName» = «p.fieldName» == null ? null : «p.fieldName».clone();
+            «ELSE»
             this.«p.fieldName» = «p.fieldName»;
+            «ENDIF»
         «ENDFOR»
     }
 
@@ -460,12 +467,11 @@ class ClassTemplate extends BaseTemplate {
                 «IF c.name == TypeConstants.PATTERN_CONSTANT_NAME»
                     «val cValue = c.value»
                     «IF cValue instanceof List<?>»
-                        «val cValues = cValue as List<?>»
                         private static final «List.importedName»<«Pattern.importedName»> «Constants.MEMBER_PATTERN_LIST»;
                         public static final «List.importedName»<String> «TypeConstants.PATTERN_CONSTANT_NAME» = «ImmutableList.importedName».of(«
-                        FOR v : cValues SEPARATOR ", "»«
+                        FOR v : cValue SEPARATOR ", "»«
                             IF v instanceof String»"«
-                                v as String»"«
+                                v»"«
                             ENDIF»«
                         ENDFOR»);
 
@@ -513,7 +519,7 @@ class ClassTemplate extends BaseTemplate {
         «ENDIF»
         «IF !properties.empty»
             «FOR f : properties»
-                «IF f.readOnly»final«ENDIF» private «f.returnType.importedName» «f.fieldName»;
+                private«IF f.readOnly» final«ENDIF» «f.returnType.importedName» «f.fieldName»;
             «ENDFOR»
         «ENDIF»
     '''