BUG-1485: move generateLengthMethod to BuilderTemplate 84/21284/3
authorRobert Varga <rovarga@cisco.com>
Thu, 28 May 2015 00:26:42 +0000 (02:26 +0200)
committerRobert Varga <rovarga@cisco.com>
Thu, 28 May 2015 08:51:08 +0000 (10:51 +0200)
While it looks this method is shared, it is not, as ClassTemplate
defines its own. Move it to BuilderTemplate and make it private,
reducing confusion.

Change-Id: I998f200a963dea39b1e2fedaf7a9fd1e394db58d
Signed-off-by: Robert Varga <rovarga@cisco.com>
code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BaseTemplate.xtend
code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BuilderTemplate.xtend

index 2f1388a593263d10be163fc88f9207ebdede7a56..9fed74f915527a3561e7d87439661519dcbf2426 100644 (file)
@@ -9,8 +9,6 @@ package org.opendaylight.yangtools.sal.java.api.generator
 
 import com.google.common.base.CharMatcher
 import com.google.common.base.Splitter
-import com.google.common.collect.ImmutableList
-import com.google.common.collect.Range
 import java.math.BigDecimal
 import java.math.BigInteger
 import java.util.Arrays
@@ -422,35 +420,6 @@ abstract class BaseTemplate {
         ENDIF
     »'''
 
-    def protected generateLengthMethod(String methodName, Type type, String className, String varName) '''
-        «val Restrictions restrictions = type.restrictions»
-        «IF restrictions != null && !(restrictions.lengthConstraints.empty)»
-            «val numberClass = restrictions.lengthConstraints.iterator.next.min.class»
-            public static «List.importedName»<«Range.importedName»<«numberClass.importedNumber»>> «methodName»() {
-                «IF numberClass.equals(typeof(BigDecimal))»
-                    «lengthBody(restrictions, numberClass, className, varName)»
-                «ELSE»
-                    «lengthBody(restrictions, typeof(BigInteger), className, varName)»
-                «ENDIF»
-            }
-        «ENDIF»
-    '''
-
-    def private lengthBody(Restrictions restrictions, Class<? extends Number> numberClass, String className, String varName) '''
-        if («varName» == null) {
-            synchronized («className».class) {
-                if («varName» == null) {
-                    «ImmutableList.importedName».Builder<«Range.importedName»<«numberClass.importedName»>> builder = «ImmutableList.importedName».builder();
-                    «FOR r : restrictions.lengthConstraints»
-                        builder.add(«Range.importedName».closed(«numericValue(numberClass, r.min)», «numericValue(numberClass, r.max)»));
-                    «ENDFOR»
-                    «varName» = builder.build();
-                }
-            }
-        }
-        return «varName»;
-    '''
-
     def protected String importedNumber(Class<? extends Number> clazz) {
         if (clazz.equals(typeof(BigDecimal))) {
             return BigDecimal.importedName
index 9806ff5d2c5c897815689f9f89a7edac65c755ff..5d3ed1399449d2ece02d60fc72b0b088f6de63ba 100644 (file)
@@ -532,6 +532,34 @@ class BuilderTemplate extends BaseTemplate {
         }
     '''
 
+    def private generateLengthMethod(String methodName, Type type, String className, String varName) '''
+        «val Restrictions restrictions = type.restrictions»
+        «IF restrictions != null && !(restrictions.lengthConstraints.empty)»
+            «val numberClass = restrictions.lengthConstraints.iterator.next.min.class»
+            public static «List.importedName»<«Range.importedName»<«numberClass.importedNumber»>> «methodName»() {
+                «IF numberClass.equals(typeof(BigDecimal))»
+                    «lengthBody(restrictions, numberClass, className, varName)»
+                «ELSE»
+                    «lengthBody(restrictions, typeof(BigInteger), className, varName)»
+                «ENDIF»
+            }
+        «ENDIF»
+    '''
+
+    def private lengthBody(Restrictions restrictions, Class<? extends Number> numberClass, String className, String varName) '''
+        if («varName» == null) {
+            synchronized («className».class) {
+                if («varName» == null) {
+                    «ImmutableList.importedName».Builder<«Range.importedName»<«numberClass.importedName»>> builder = «ImmutableList.importedName».builder();
+                    «FOR r : restrictions.lengthConstraints»
+                        builder.add(«Range.importedName».closed(«numericValue(numberClass, r.min)», «numericValue(numberClass, r.max)»));
+                    «ENDFOR»
+                    «varName» = builder.build();
+                }
+            }
+        }
+        return «varName»;
+    '''
 
     def private generateRangeMethod(String methodName, Restrictions restrictions, Type returnType, String className, String varName) '''
         «IF restrictions != null && !(restrictions.rangeConstraints.empty)»