Clean up tryToUseCacheElse() 48/81548/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 10 Apr 2019 12:51:00 +0000 (14:51 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 11 Apr 2019 09:53:57 +0000 (11:53 +0200)
Generated code is a bit ugly for the case of accessing cache,
with missing newline and misplaced whitespace. Clean that up.

Change-Id: I13c754c808b9da19e3f5e4cfc216073aafb462db
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit d9972690bb45cb28f43c63c21395b5042f4d4ce2)

binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/gen/impl/DataNodeContainerSerializerSource.java

index 9bed830009c7bd4eda1f2c625cf7c7a1ec41996f..deb82f611716f9e3352d796241a6d37c6e58e4b9 100644 (file)
@@ -161,26 +161,23 @@ abstract class DataNodeContainerSerializerSource extends DataObjectSerializerSou
             final ListSchemaNode casted = (ListSchemaNode) child;
             emitList(sb, getterName, valueType, casted);
         } else if (child instanceof ContainerSchemaNode) {
-            sb.append(tryToUseCacheElse(getterName,statement(staticInvokeEmitter(childType, getterName))));
+            sb.append(tryToUseCacheElse(getterName, statement(staticInvokeEmitter(childType, getterName))));
         } else if (child instanceof ChoiceSchemaNode) {
             final String propertyName = CHOICE_PREFIX + childType.getName();
             staticConstant(propertyName, DataObjectSerializerImplementation.class,
                 ChoiceDispatchSerializer.from(loadClass(childType)));
-            sb.append(tryToUseCacheElse(getterName,statement(invoke(propertyName,
+            sb.append(tryToUseCacheElse(getterName, statement(invoke(propertyName,
                 StreamWriterGenerator.SERIALIZE_METHOD_NAME, REGISTRY, cast(DataObject.class.getName(), getterName),
                 STREAM))));
         }
     }
 
     private static StringBuilder tryToUseCacheElse(final String getterName, final CharSequence statement) {
-        final StringBuilder b = new StringBuilder();
-        b.append("if ( ");
-        b.append(SERIALIZER).append("== null || ");
-        b.append(invoke(SERIALIZER, "serialize", getterName)).append("== null");
-        b.append(") {");
-        b.append(statement);
-        b.append('}');
-        return b;
+        return new StringBuilder()
+                .append("if (").append(SERIALIZER).append(" == null || ")
+                .append(invoke(SERIALIZER, "serialize", getterName)).append(" == null) {\n")
+                .append(statement)
+                .append('}');
     }
 
     private void emitList(final StringBuilder sb, final String getterName, final Type valueType,