toString modification in generated code
Change-Id: I879063f1a491be57ed1be190977189b9124578cb
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java
index 5cd5651..4d8f8f1 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/TempJavaFragmentFiles.java
@@ -106,8 +106,6 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.EXTEND;
import static org.onosproject.yang.compiler.utils.UtilConstants.FOUR_SPACE_INDENTATION;
-import static org.onosproject.yang.compiler.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS;
-import static org.onosproject.yang.compiler.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_UTIL_PKG;
import static org.onosproject.yang.compiler.utils.UtilConstants.KEYS;
@@ -125,6 +123,7 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.SERVICE;
import static org.onosproject.yang.compiler.utils.UtilConstants.SLASH;
import static org.onosproject.yang.compiler.utils.UtilConstants.SPACE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.STRING_JOINER_CLASS;
import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE_LEAF;
import static org.onosproject.yang.compiler.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yang.compiler.utils.io.impl.FileSystemUtil.readAppendFile;
@@ -1579,8 +1578,7 @@
getGeneratedJavaClassName(),
getJavaFileInfo().getPackage(), false);
//more objects.
- addImportInfoOfNode(GOOGLE_MORE_OBJECT_IMPORT_CLASS,
- GOOGLE_MORE_OBJECT_IMPORT_PKG,
+ addImportInfoOfNode(STRING_JOINER_CLASS, JAVA_UTIL_PKG,
getGeneratedJavaClassName(),
getJavaFileInfo().getPackage(), false);
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java
index c853fef..6dc15c8 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGenerator.java
@@ -71,7 +71,6 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getListAttribute;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getNewInstance;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getNewLineAndSpace;
-import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getOmitNullValueString;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getOpenCloseParaWithValue;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getOverRideString;
import static org.onosproject.yang.compiler.translator.tojava.utils.StringGenerator.getParseFromStringMethod;
@@ -139,7 +138,6 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.GET_DECODER;
import static org.onosproject.yang.compiler.utils.UtilConstants.GET_ENCODER;
import static org.onosproject.yang.compiler.utils.UtilConstants.GET_METHOD_PREFIX;
-import static org.onosproject.yang.compiler.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.HASH;
import static org.onosproject.yang.compiler.utils.UtilConstants.HASH_CODE_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.IF;
@@ -162,6 +160,7 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.NEG_ONE;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_STRING_JOINER_OBJECT;
import static org.onosproject.yang.compiler.utils.UtilConstants.NOT;
import static org.onosproject.yang.compiler.utils.UtilConstants.NULL;
import static org.onosproject.yang.compiler.utils.UtilConstants.OBJ;
@@ -778,9 +777,8 @@
builder.append(methodSignature(TO_STRING_METHOD, EMPTY_STRING,
PUBLIC, null, STRING_DATA_TYPE, null,
CLASS_TYPE));
- builder.append(getReturnString(GOOGLE_MORE_OBJECT_METHOD_STRING,
- EIGHT_SPACE_INDENTATION)).append(NEW_LINE)
- .append(getOmitNullValueString());
+ builder.append(getReturnString(NEW_STRING_JOINER_OBJECT,
+ EIGHT_SPACE_INDENTATION)).append(NEW_LINE);
return builder.toString();
}
diff --git a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java
index 39226e3..8af4a02 100644
--- a/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java
+++ b/compiler/base/translator/src/main/java/org/onosproject/yang/compiler/translator/tojava/utils/StringGenerator.java
@@ -48,6 +48,7 @@
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getYangDataStructure;
import static org.onosproject.yang.compiler.utils.UtilConstants.ABSTRACT;
+import static org.onosproject.yang.compiler.utils.UtilConstants.ADD;
import static org.onosproject.yang.compiler.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.AND;
import static org.onosproject.yang.compiler.utils.UtilConstants.APP_INSTANCE;
@@ -61,7 +62,6 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.BYTE_WRAPPER;
import static org.onosproject.yang.compiler.utils.UtilConstants.CATCH;
import static org.onosproject.yang.compiler.utils.UtilConstants.CHECK_NOT_NULL_STRING;
-import static org.onosproject.yang.compiler.utils.UtilConstants.CLASS;
import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yang.compiler.utils.UtilConstants.COLON;
@@ -85,7 +85,6 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yang.compiler.utils.UtilConstants.FROM_STRING_METHOD_NAME;
import static org.onosproject.yang.compiler.utils.UtilConstants.GET;
-import static org.onosproject.yang.compiler.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STATIC_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.IF;
import static org.onosproject.yang.compiler.utils.UtilConstants.IMPLEMENTS;
import static org.onosproject.yang.compiler.utils.UtilConstants.IMPORT;
@@ -102,7 +101,6 @@
import static org.onosproject.yang.compiler.utils.UtilConstants.LONG_MIN_RANGE;
import static org.onosproject.yang.compiler.utils.UtilConstants.LONG_WRAPPER;
import static org.onosproject.yang.compiler.utils.UtilConstants.MAP;
-import static org.onosproject.yang.compiler.utils.UtilConstants.MORE_OBJ_ATTR;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW;
import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yang.compiler.utils.UtilConstants.OBJECT;
@@ -374,7 +372,7 @@
*/
static String getToStringMethodsAddString(String space, String paraName) {
return space + PERIOD + ADD_STRING + OPEN_PARENTHESIS +
- getQuotedString(paraName) + COMMA + SPACE;
+ getQuotedString(paraName + EQUAL) + SPACE + ADD + SPACE;
}
/**
@@ -1216,23 +1214,6 @@
}
/**
- * Returns more object attr for union to string method.
- *
- * @param name name of generate class
- * @return more object attr for union to string method
- */
- static String getMoreObjectAttr(String name) {
- String cls = name + PERIOD + CLASS;
- StringBuilder attr = new StringBuilder(EIGHT_SPACE_INDENTATION);
- String[] array = {NEW_LINE};
- attr.append(MORE_OBJ_ATTR).append(GOOGLE_MORE_OBJECT_METHOD_STATIC_STRING)
- .append(getOpenCloseParaWithValue(cls)).append(NEW_LINE)
- .append(FOUR_SPACE_INDENTATION).append(trimAtLast(
- getOmitNullValueString(), array)).append(signatureClose());
- return attr.toString();
- }
-
- /**
* Returns to string call.
*
* @param name name of attribute
diff --git a/compiler/base/translator/src/test/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGeneratorTest.java b/compiler/base/translator/src/test/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGeneratorTest.java
index 2a6b396..f05dbe7 100644
--- a/compiler/base/translator/src/test/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGeneratorTest.java
+++ b/compiler/base/translator/src/test/java/org/onosproject/yang/compiler/translator/tojava/utils/MethodsGeneratorTest.java
@@ -18,10 +18,8 @@
import org.junit.Test;
import org.onosproject.yang.compiler.datamodel.YangType;
-import org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType;
import org.onosproject.yang.compiler.translator.tojava.JavaAttributeInfo;
import org.onosproject.yang.compiler.translator.tojava.JavaQualifiedTypeInfoTranslator;
-import org.onosproject.yang.compiler.utils.UtilConstants;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -32,10 +30,41 @@
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.STRING;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
+import static org.onosproject.yang.compiler.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getGetterForClass;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getGetterForInterface;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getSetterForClass;
import static org.onosproject.yang.compiler.translator.tojava.utils.MethodsGenerator.getSetterForInterface;
+import static org.onosproject.yang.compiler.utils.UtilConstants.ADD;
+import static org.onosproject.yang.compiler.utils.UtilConstants.ADD_STRING;
+import static org.onosproject.yang.compiler.utils.UtilConstants.CHECK_NOT_NULL_STRING;
+import static org.onosproject.yang.compiler.utils.UtilConstants.CLOSE_PARENTHESIS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.COMMA;
+import static org.onosproject.yang.compiler.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
+import static org.onosproject.yang.compiler.utils.UtilConstants.EQUAL;
+import static org.onosproject.yang.compiler.utils.UtilConstants.EQUALS_STRING;
+import static org.onosproject.yang.compiler.utils.UtilConstants.GET_METHOD_PREFIX;
+import static org.onosproject.yang.compiler.utils.UtilConstants.JAVA_LANG;
+import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.OBJECT_STRING;
+import static org.onosproject.yang.compiler.utils.UtilConstants.OF;
+import static org.onosproject.yang.compiler.utils.UtilConstants.OPEN_PARENTHESIS;
+import static org.onosproject.yang.compiler.utils.UtilConstants.OVERRIDE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
+import static org.onosproject.yang.compiler.utils.UtilConstants.PUBLIC;
+import static org.onosproject.yang.compiler.utils.UtilConstants.QUOTES;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SEMI_COLON;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SET_METHOD_PREFIX;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SPACE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.STATIC;
+import static org.onosproject.yang.compiler.utils.UtilConstants.STRING_DATA_TYPE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SUFFIX_S;
+import static org.onosproject.yang.compiler.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
+import static org.onosproject.yang.compiler.utils.UtilConstants.VALUE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.VOID;
/**
* Unit tests for generated methods from the file type.
@@ -67,7 +96,6 @@
public void callPrivateConstructors()
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
-
Class<?>[] classesToConstruct = {MethodsGenerator.class};
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
@@ -81,12 +109,13 @@
*/
@Test
public void getTypeConstructorTest() {
-
JavaAttributeInfo testAttr = getTestAttribute();
String test = MethodsGenerator.getTypeConstructorStringAndJavaDoc(
- testAttr, CLASS_NAME, GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS, 0);
- assertThat(true, is(test.contains(UtilConstants.PUBLIC + UtilConstants.SPACE + CLASS_NAME +
- UtilConstants.OPEN_PARENTHESIS)));
+ testAttr, CLASS_NAME, GENERATE_TYPEDEF_CLASS, 0);
+ StringBuilder builder = new StringBuilder()
+ .append(PUBLIC).append(SPACE).append(CLASS_NAME)
+ .append(OPEN_PARENTHESIS);
+ assertThat(true, is(test.contains(builder.toString())));
}
/**
@@ -96,9 +125,11 @@
public void getTypeConstructorForUnionTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String test = MethodsGenerator.getTypeConstructorStringAndJavaDoc(
- testAttr, CLASS_NAME, GeneratedJavaFileType.GENERATE_UNION_CLASS, 0);
- assertThat(true, is(test.contains(UtilConstants.PUBLIC + UtilConstants.SPACE + CLASS_NAME +
- UtilConstants.OPEN_PARENTHESIS)));
+ testAttr, CLASS_NAME, GENERATE_UNION_CLASS, 0);
+ StringBuilder builder = new StringBuilder()
+ .append(PUBLIC).append(SPACE).append(CLASS_NAME)
+ .append(OPEN_PARENTHESIS);
+ assertThat(true, is(test.contains(builder.toString())));
assertThat(true, is(test.contains(SET)));
}
@@ -108,11 +139,12 @@
@Test
public void getCheckNotNullTest() {
String method = StringGenerator.getCheckNotNull(CLASS_NAME);
- assertThat(true, is(method.equals(
- UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.CHECK_NOT_NULL_STRING +
- UtilConstants.OPEN_PARENTHESIS + CLASS_NAME + UtilConstants.COMMA + UtilConstants.SPACE +
- CLASS_NAME + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLON +
- UtilConstants.NEW_LINE)));
+ StringBuilder builder = new StringBuilder()
+ .append(EIGHT_SPACE_INDENTATION).append(CHECK_NOT_NULL_STRING)
+ .append(OPEN_PARENTHESIS).append(CLASS_NAME).append(COMMA)
+ .append(SPACE).append(CLASS_NAME).append(CLOSE_PARENTHESIS)
+ .append(SEMI_COLON).append(NEW_LINE);
+ assertThat(true, is(method.equals(builder.toString())));
}
/**
@@ -122,9 +154,11 @@
public void getEqualsMethodTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = MethodsGenerator.getEqualsMethod(testAttr);
- assertThat(true, is(method.contains(
- UtilConstants.SIXTEEN_SPACE_INDENTATION + UtilConstants.OBJECT_STRING + UtilConstants.SUFFIX_S +
- UtilConstants.PERIOD + UtilConstants.EQUALS_STRING + UtilConstants.OPEN_PARENTHESIS)));
+ StringBuilder builder = new StringBuilder()
+ .append(SIXTEEN_SPACE_INDENTATION).append(OBJECT_STRING)
+ .append(SUFFIX_S).append(PERIOD).append(EQUALS_STRING)
+ .append(OPEN_PARENTHESIS);
+ assertThat(true, is(method.contains(builder.toString())));
}
/**
@@ -134,11 +168,13 @@
public void getToStringMethodTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = MethodsGenerator.getToStringMethod(testAttr);
- assertThat(true, is(method.equals(
- UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.PERIOD + UtilConstants.ADD_STRING +
- UtilConstants.OPEN_PARENTHESIS + UtilConstants.QUOTES + testAttr.getAttributeName() +
- UtilConstants.QUOTES + UtilConstants.COMMA + UtilConstants.SPACE +
- testAttr.getAttributeName() + UtilConstants.CLOSE_PARENTHESIS)));
+ StringBuilder builder = new StringBuilder()
+ .append(TWELVE_SPACE_INDENTATION).append(PERIOD)
+ .append(ADD_STRING).append(OPEN_PARENTHESIS).append(QUOTES)
+ .append(testAttr.getAttributeName()).append(EQUAL)
+ .append(QUOTES).append(SPACE).append(ADD).append(SPACE)
+ .append(testAttr.getAttributeName()).append(CLOSE_PARENTHESIS);
+ assertThat(true, is(method.equals(builder.toString())));
}
/**
@@ -159,10 +195,11 @@
@Test
public void getGetterForClassTest() {
JavaAttributeInfo testAttr = getTestAttribute();
- String method = getGetterForClass(testAttr, GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER);
- assertThat(true, is(method.contains(UtilConstants.PUBLIC + UtilConstants.SPACE +
- UtilConstants.STRING_DATA_TYPE +
- UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX)));
+ String method = getGetterForClass(testAttr, GENERATE_SERVICE_AND_MANAGER);
+ StringBuilder builder = new StringBuilder()
+ .append(PUBLIC).append(SPACE).append(STRING_DATA_TYPE)
+ .append(SPACE).append(GET_METHOD_PREFIX);
+ assertThat(true, is(method.contains(builder.toString())));
}
/**
@@ -170,10 +207,12 @@
*/
@Test
public void getGetterForInterfaceTest() {
- String method = getGetterForInterface(CLASS_NAME, UtilConstants.STRING_DATA_TYPE, false,
- GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER, null);
- assertThat(true, is(method.contains(UtilConstants.STRING_DATA_TYPE + UtilConstants.SPACE +
- UtilConstants.GET_METHOD_PREFIX)));
+ String method = getGetterForInterface(CLASS_NAME, STRING_DATA_TYPE, false,
+ GENERATE_SERVICE_AND_MANAGER, null);
+ StringBuilder builder = new StringBuilder()
+ .append(STRING_DATA_TYPE).append(SPACE)
+ .append(GET_METHOD_PREFIX);
+ assertThat(true, is(method.contains(builder.toString())));
}
/**
@@ -183,13 +222,13 @@
public void getSetterForClassTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getSetterForClass(
- testAttr, GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER);
- assertThat(true, is(
- method.contains(UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.VOID +
- UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX +
- CLASS_NAME + UtilConstants.OPEN_PARENTHESIS +
- UtilConstants.STRING_DATA_TYPE + UtilConstants.SPACE +
- ATTRIBUTE_NAME)));
+ testAttr, GENERATE_SERVICE_AND_MANAGER);
+ StringBuilder builder = new StringBuilder()
+ .append(PUBLIC).append(SPACE).append(VOID).append(SPACE)
+ .append(SET_METHOD_PREFIX).append(CLASS_NAME)
+ .append(OPEN_PARENTHESIS).append(STRING_DATA_TYPE).append(SPACE)
+ .append(ATTRIBUTE_NAME);
+ assertThat(true, is(method.contains(builder.toString())));
}
/**
@@ -197,11 +236,13 @@
*/
@Test
public void getSetterForInterfaceTest() {
- String method = getSetterForInterface(CLASS_NAME, UtilConstants.STRING_DATA_TYPE,
+ String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE,
CLASS_NAME, false,
- GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER, null);
- assertThat(true, is(method.contains(UtilConstants.VOID + UtilConstants.SPACE +
- UtilConstants.SET_METHOD_PREFIX + CLASS_NAME)));
+ GENERATE_SERVICE_AND_MANAGER, null);
+ StringBuilder builder = new StringBuilder()
+ .append(VOID).append(SPACE).append(SET_METHOD_PREFIX)
+ .append(CLASS_NAME);
+ assertThat(true, is(method.contains(builder.toString())));
}
/**
@@ -210,12 +251,14 @@
@Test
public void getOfMethodTest() {
JavaAttributeInfo testAttr = getTestAttribute();
- String method = MethodsGenerator.getOfMethodStringAndJavaDoc(testAttr, CLASS_NAME);
- assertThat(true, is(method.contains(
- UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.STATIC + UtilConstants.SPACE + CLASS_NAME +
- UtilConstants.SPACE + UtilConstants.OF + UtilConstants.OPEN_PARENTHESIS +
- UtilConstants.STRING_DATA_TYPE + UtilConstants.SPACE + UtilConstants.VALUE +
- UtilConstants.CLOSE_PARENTHESIS)));
+ String method = MethodsGenerator.getOfMethodStringAndJavaDoc(testAttr,
+ CLASS_NAME);
+ StringBuilder builder = new StringBuilder()
+ .append(PUBLIC).append(SPACE).append(STATIC).append(SPACE)
+ .append(CLASS_NAME).append(SPACE).append(OF)
+ .append(OPEN_PARENTHESIS).append(STRING_DATA_TYPE)
+ .append(SPACE).append(VALUE).append(CLOSE_PARENTHESIS);
+ assertThat(true, is(method.contains(builder.toString())));
}
/**
@@ -225,8 +268,10 @@
public void getSetterForTypeDefClassTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = MethodsGenerator.getSetterForTypeDefClass(testAttr);
- assertThat(true, is(method.contains(UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.VOID +
- UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX)));
+ StringBuilder builder = new StringBuilder()
+ .append(PUBLIC).append(SPACE).append(VOID).append(SPACE)
+ .append(SET_METHOD_PREFIX);
+ assertThat(true, is(method.contains(builder.toString())));
}
/**
@@ -235,7 +280,7 @@
@Test
public void getOverRideStringTest() {
String method = StringGenerator.getOverRideString();
- assertThat(true, is(method.contains(UtilConstants.OVERRIDE)));
+ assertThat(true, is(method.contains(OVERRIDE)));
}
/**
@@ -259,8 +304,8 @@
*/
private JavaQualifiedTypeInfoTranslator getTestJavaQualifiedTypeInfo() {
JavaQualifiedTypeInfoTranslator info = new JavaQualifiedTypeInfoTranslator();
- info.setPkgInfo(UtilConstants.JAVA_LANG);
- info.setClassInfo(UtilConstants.STRING_DATA_TYPE);
+ info.setPkgInfo(JAVA_LANG);
+ info.setClassInfo(STRING_DATA_TYPE);
return info;
}
@@ -271,7 +316,7 @@
*/
private YangType<?> getTestYangType() {
YangType<?> attrType = new YangType<>();
- attrType.setDataTypeName(UtilConstants.STRING_DATA_TYPE);
+ attrType.setDataTypeName(STRING_DATA_TYPE);
attrType.setDataType(STRING);
return attrType;
}
diff --git a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
index 81844ba..f81f5e7 100644
--- a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
+++ b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
@@ -1355,36 +1355,11 @@
*/
public static final String HASH_MAP = "HashMap";
-
/**
- * Static attribute for more object import package.
+ * Static attribute for new string joiner object.
*/
- public static final String GOOGLE_MORE_OBJECT_IMPORT_PKG =
- "com.google.common.base";
-
- /**
- * Static attribute for more object import class.
- */
- public static final String GOOGLE_MORE_OBJECT_IMPORT_CLASS =
- "MoreObjects";
-
- /**
- * Static attribute for more object import class.
- */
- public static final String MORE_OBJ_ATTR =
- "MoreObjects.ToStringHelper helper = ";
-
- /**
- * Static attribute for to string method.
- */
- public static final String GOOGLE_MORE_OBJECT_METHOD_STRING =
- "MoreObjects.toStringHelper(getClass())";
-
- /**
- * Static attribute for to string method.
- */
- public static final String GOOGLE_MORE_OBJECT_METHOD_STATIC_STRING =
- "MoreObjects.toStringHelper";
+ public static final String NEW_STRING_JOINER_OBJECT =
+ "new StringJoiner(\", \", getClass().getSimpleName() +\"{\", \"}\")";
/**
* Static attribute for java utilities import package.
@@ -1969,6 +1944,7 @@
public static final String MODEL_OBJECT_DATA = "ModelObjectData";
public static final String DEFAULT_MODEL_OBJECT_DATA =
"DefaultModelObjectData";
+ public static final String STRING_JOINER_CLASS = "StringJoiner";
// No instantiation.
private UtilConstants() {