Make BaseTemplate.fieldName() return String 16/84216/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 5 Sep 2019 10:00:15 +0000 (12:00 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 5 Sep 2019 10:02:40 +0000 (12:02 +0200)
Java 9+ has very efficient string concatenations, hence we can
use them. This allows us to better bind to to StringConcatenation,
as we'll end up wired to .append(String) rather than .append(Object),
as would be the case with CharSequences.

Change-Id: I2a93139c1b1af8b4c335aa4a4cb8a68bd76acb95
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/BaseTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/BuilderTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/ClassTemplate.xtend
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/UnionTemplate.xtend

index dc7fc89889f6c2db6036c5565cac76bc8a2b7e33..51abd5dcd51b5fb7c5b168650e84c7e40822b587 100644 (file)
@@ -97,7 +97,9 @@ abstract class BaseTemplate extends JavaFileTemplate {
     protected abstract def CharSequence body();
 
     // Helper patterns
-    final protected def fieldName(GeneratedProperty property) '''_«property.name»'''
+    final protected def fieldName(GeneratedProperty property) {
+        "_" + property.name
+    }
 
     final protected def propertyNameFromGetter(MethodSignature getter) {
         var String prefix;
@@ -457,7 +459,7 @@ abstract class BaseTemplate extends JavaFileTemplate {
                restrictions.rangeConstraint.get, this)»
        «ENDIF»
        «IF restrictions.lengthConstraint.present»
-           «LengthGenerator.generateLengthChecker(field.fieldName.toString, actualType, restrictions.lengthConstraint.get, this)»
+           «LengthGenerator.generateLengthChecker(field.fieldName, actualType, restrictions.lengthConstraint.get, this)»
        «ENDIF»
     '''
 
@@ -472,13 +474,13 @@ abstract class BaseTemplate extends JavaFileTemplate {
        «val fieldName = property.fieldName»
        «IF restrictions.getLengthConstraint.isPresent»
            «IF actualType instanceof ConcreteType»
-               «LengthGenerator.generateLengthCheckerCall(fieldName.toString, value)»
+               «LengthGenerator.generateLengthCheckerCall(fieldName, value)»
            «ELSE»
-               «LengthGenerator.generateLengthCheckerCall(fieldName.toString, value + ".getValue()")»
+               «LengthGenerator.generateLengthCheckerCall(fieldName, value + ".getValue()")»
            «ENDIF»
        «ENDIF»
 
-       «val fieldUpperCase = fieldName.toString.toUpperCase(Locale.ENGLISH)»
+       «val fieldUpperCase = fieldName.toUpperCase(Locale.ENGLISH)»
        «FOR currentConstant : type.getConstantDefinitions»
            «IF currentConstant.getName.startsWith(TypeConstants.PATTERN_CONSTANT_NAME)
                && fieldUpperCase.equals(currentConstant.getName.substring(TypeConstants.PATTERN_CONSTANT_NAME.length))»
index 58276affa9622b719980f63a591e801dce39be9c..5831fb7dd8f254d6f43318ab8faf0f431ffde09f 100644 (file)
@@ -275,7 +275,7 @@ class BuilderTemplate extends AbstractBuilderTemplate {
                }
             }
         «ENDIF»
-            this.«field.fieldName.toString» = values;
+            this.«field.fieldName» = values;
             return this;
         }
 
@@ -295,7 +295,7 @@ class BuilderTemplate extends AbstractBuilderTemplate {
                     «checkArgument(field, restrictions, actualType, "value")»
                 }
             «ENDIF»
-            this.«field.fieldName.toString» = value;
+            this.«field.fieldName» = value;
             return this;
         }
         «val uintType = UINT_TYPES.get(field.returnType)»
index c4b36f694ebfac645b1f8faa257829bb9946fbd4..35dc26bd7c9fd91bbc071a9f3810c8adeae76164 100644 (file)
@@ -221,7 +221,7 @@ class ClassTemplate extends BaseTemplate {
             super(«parentProperties.asArguments»);
         «ENDIF»
         «FOR p : allProperties»
-            «generateRestrictions(type, p.fieldName.toString, p.returnType)»
+            «generateRestrictions(type, p.fieldName, p.returnType)»
         «ENDFOR»
 
         «FOR p : properties»
@@ -243,7 +243,7 @@ class ClassTemplate extends BaseTemplate {
             super(«parentProperties.asArguments»);
         «ENDIF»
         «FOR p : allProperties»
-            «generateRestrictions(type, p.fieldName.toString, p.returnType)»
+            «generateRestrictions(type, p.fieldName, p.returnType)»
         «ENDFOR»
         «/*
          * If we have patterns, we need to apply them to the value field. This is a sad consequence of how this code is
@@ -294,7 +294,7 @@ class ClassTemplate extends BaseTemplate {
         «ENDIF»
 
         «val fieldName = property.fieldName»
-        «generateRestrictions(type, fieldName.toString, property.returnType)»
+        «generateRestrictions(type, fieldName, property.returnType)»
 
         this.«fieldName» = «property.name»;
         «FOR p : other»
index 866e813a1e83b0f5453a3c238cfe43dc8e9d956b..9f1582cdc4477c146d820ab47d26a38b65a079bd 100644 (file)
@@ -67,7 +67,7 @@ class UnionTemplate extends ClassTemplate {
             public «type.name»(«propertyAndTopParentProperties.asArgumentsDeclaration») {
                 super(«parentProperties.asArguments»);
                 «IF restrictions !== null»
-                    «checkArgument(property, restrictions, actualType, property.fieldName.toString
+                    «checkArgument(property, restrictions, actualType, property.fieldName)»
                 «ENDIF»
                 this.«property.fieldName» = «property.fieldName»;
                 «FOR other : finalProperties»