Optimize ClassTemplate.allProperties 91/84191/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 4 Sep 2019 11:46:14 +0000 (13:46 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 4 Sep 2019 11:49:08 +0000 (13:49 +0200)
This variable is guaranteed to be a List, declare it as such,
adding following benefits:
- eliminates ClassTemplate's reliance on IterableExtensions
- a few isEmpty() checks get be eliminated, as size() is now
  handled through List.size()

Change-Id: I14354dfef3a6b663c9a027353704127437d4344d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/ClassTemplate.xtend

index 658c341ee2cddd9277854cf4ea024c4c04a0cc35..18baa3440388d00432e73d5f656beddb496de228 100644 (file)
@@ -50,7 +50,7 @@ class ClassTemplate extends BaseTemplate {
     protected val List<GeneratedProperty> properties
     protected val List<GeneratedProperty> finalProperties
     protected val List<GeneratedProperty> parentProperties
-    protected val Iterable<GeneratedProperty> allProperties
+    protected val List<GeneratedProperty> allProperties
     protected val Restrictions restrictions
 
     /**
@@ -214,7 +214,7 @@ class ClassTemplate extends BaseTemplate {
     '''
 
     def protected allValuesConstructor() '''
-    «IF genTO.typedef && !allProperties.empty && allProperties.size == 1 && allProperties.get(0).name.equals("value")»
+    «IF genTO.typedef && allProperties.size == 1 && allProperties.get(0).name.equals("value")»
         @«ConstructorParameters.importedName»("value")
         @«ConstructorProperties.importedName»("value")
     «ENDIF»
@@ -230,14 +230,14 @@ class ClassTemplate extends BaseTemplate {
          * If we have patterns, we need to apply them to the value field. This is a sad
          * consequence of how this code is structured.
          */
-        IF genTO.typedef && !allProperties.empty && allProperties.size == 1 && allProperties.get(0).name.equals("value")»
+        IF genTO.typedef && allProperties.size == 1 && allProperties.get(0).name.equals("value")»
             «CodeHelpers.importedName».requireValue(_value);
             «genPatternEnforcer("_value")»
         «ENDIF»
 
         «FOR p : properties»
             «IF p.returnType.importedName.contains("[]")»
-                «IF genTO.typedef && !allProperties.empty && allProperties.size == 1 && allProperties.get(0).name
+                «IF genTO.typedef && allProperties.size == 1 && allProperties.get(0).name
                 .equals("value")»
                 this.«p.fieldName» = «p.fieldName».clone();
                 «ELSE»