BUG-1485: move *Range* methods to BuilderTemplate 83/21283/3
authorRobert Varga <rovarga@cisco.com>
Thu, 28 May 2015 00:14:29 +0000 (02:14 +0200)
committerRobert Varga <rovarga@cisco.com>
Thu, 28 May 2015 08:51:08 +0000 (10:51 +0200)
printRangeConstraint and generateRangeMethod are used by BuilderTemplate
only, move them there to preserve locality and stop them from spreading.

Change-Id: I5d5421b50bd5e4ac65182ad1a11e7bfad199df51
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 c93f428131430a53f47be3459e83f4c502b700be..2f1388a593263d10be163fc88f9207ebdede7a56 100644 (file)
@@ -451,47 +451,6 @@ abstract class BaseTemplate {
         return «varName»;
     '''
 
-    def protected generateRangeMethod(String methodName, Restrictions restrictions, Type returnType, String className, String varName) '''
-        «IF restrictions != null && !(restrictions.rangeConstraints.empty)»
-            «val number = returnType.importedNumber»
-            public static «List.importedName»<«Range.importedName»<«number»>> «methodName»() {
-                «IF returnType.fullyQualifiedName.equals(BigDecimal.canonicalName)»
-                    «rangeBody(restrictions, BigDecimal, className, varName)»
-                «ELSE»
-                    «rangeBody(restrictions, BigInteger, className, varName)»
-                «ENDIF»
-            }
-        «ENDIF»
-    '''
-
-    def protected generateRangeMethod(String methodName, Restrictions restrictions, String className, String varName, Iterable<GeneratedProperty> properties) '''
-        «IF restrictions != null && !(restrictions.rangeConstraints.empty)»
-            «val returnType = properties.iterator.next.returnType»
-            public static «List.importedName»<«Range.importedName»<«returnType.importedNumber»>> «methodName»() {
-                «IF returnType.fullyQualifiedName.equals(BigDecimal.canonicalName)»
-                    «rangeBody(restrictions, BigDecimal, className, varName)»
-                «ELSE»
-                    «rangeBody(restrictions, BigInteger, className, varName)»
-                «ENDIF»
-            }
-        «ENDIF»
-    '''
-
-    def private rangeBody(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.rangeConstraints»
-                        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 dc7f9d4390282f0da82e9844a8430f57212806ce..9806ff5d2c5c897815689f9f89a7edac65c755ff 100644 (file)
@@ -33,6 +33,10 @@ import org.opendaylight.yangtools.yang.binding.DataObject
 import org.opendaylight.yangtools.yang.binding.Identifiable
 import org.opendaylight.yangtools.concepts.Builder
 import org.opendaylight.yangtools.yang.binding.AugmentationHolder
+import org.opendaylight.yangtools.sal.binding.model.api.Restrictions
+import java.math.BigDecimal
+import java.math.BigInteger
+import com.google.common.collect.ImmutableList
 
 /**
  * Template for generating JAVA builder classes.
@@ -528,6 +532,35 @@ class BuilderTemplate extends BaseTemplate {
         }
     '''
 
+
+    def private generateRangeMethod(String methodName, Restrictions restrictions, Type returnType, String className, String varName) '''
+        «IF restrictions != null && !(restrictions.rangeConstraints.empty)»
+            «val number = returnType.importedNumber»
+            public static «List.importedName»<«Range.importedName»<«number»>> «methodName»() {
+                «IF returnType.fullyQualifiedName.equals(BigDecimal.canonicalName)»
+                    «rangeBody(restrictions, BigDecimal, className, varName)»
+                «ELSE»
+                    «rangeBody(restrictions, BigInteger, className, varName)»
+                «ENDIF»
+            }
+        «ENDIF»
+    '''
+
+    def private rangeBody(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.rangeConstraints»
+                        builder.add(«Range.importedName».closed(«numericValue(numberClass, r.min)», «numericValue(numberClass, r.max)»));
+                    «ENDFOR»
+                    «varName» = builder.build();
+                }
+            }
+        }
+        return «varName»;
+    '''
+
     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)»