Yang code generator cleanup
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / ftl / model / MethodSerializer.java
index 7d2b9fcdafa1974be14d512deba8df25c17a3140..eba6e53e23257899ccc178760cd3bc30b8e676f6 100644 (file)
@@ -24,42 +24,40 @@ class MethodSerializer {
 
         build.append("    " + "public ");
         for (String mod : method.getModifiers()) {
-            build.append(mod + " ");
+            build.append(mod).append(" ");
         }
-        build.append(method.getReturnType() + " ");
+        build.append(method.getReturnType()).append(" ");
 
-        build.append(method.getName() + "(");
+        build.append(method.getName()).append("(");
+        boolean firstParam = true;
         for (Field param : method.getParameters()) {
+            if (!firstParam) {
+                build.append(", ");
+            }
             for (String mod : param.getModifiers()) {
-                build.append(mod + " ");
+                build.append(mod).append(" ");
             }
-            build.append(param.getType() + " ");
-            build.append(param.getName() + ", ");
-        }
-        if (method.getParameters().isEmpty()) {
-            build.append(")");
-        } else {
-            build.deleteCharAt(build.length() - 1);
-            build.deleteCharAt(build.length() - 1);
-            build.append(')');
+            build.append(param.getType()).append(" ");
+            build.append(param.getName());
+            firstParam = false;
         }
+        build.append(")");
 
         if (method instanceof MethodDeclaration) {
             build.append(";");
             build.append("\n");
         } else if (method instanceof MethodDefinition) {
-            if (!((MethodDefinition) method).getThrowsExceptions()
-                    .isEmpty()) {
+            MethodDefinition definition = (MethodDefinition) method;
+            if (!definition.getThrowsExceptions().isEmpty()) {
                 build.append(" throws ");
             }
-            for (String ex : ((MethodDefinition) method)
-                    .getThrowsExceptions()) {
-                build.append(ex + " ");
+            for (String ex : definition.getThrowsExceptions()) {
+                build.append(ex).append(" ");
             }
             build.append(" {");
             build.append("\n");
             build.append("        ");
-            build.append(((MethodDefinition) method).getBody());
+            build.append(definition.getBody());
             build.append("\n");
             build.append("    ");
             build.append("}");