public class CodeJavaGenerator extends Object
| Constructor and Description |
|---|
CodeJavaGenerator() |
| Modifier and Type | Method and Description |
|---|---|
static List<String> |
addCode(List<String> codes,
String code,
int indent) |
static List<String> |
addComment(List<String> codes,
String comment,
int indent) |
static String |
appendLast()
handle last for java
|
static String |
castToType(String typeName,
String objCode)
cast object to a type
|
static String |
enumValue(String enumTypeName,
String itemName) |
static String |
getGetClientMethod(String controllerVarName,
String interfaceName)
process the code to get RPC client
|
static String |
getIndent(int indent) |
static List<String> |
getStringListWithIndent(List<String> codes,
int indent) |
static String |
handleEscapeCharInString(String orgValue)
handle escape char in string in java
https://docs.oracle.com/javase/tutorial/java/data/characters.html
|
static String |
handleVariableName(String original)
some variable name might contain invalid symbol such as ., then need to reformat them
|
static String |
junitAssertEquals(String expectedValue,
String variableName) |
static String |
junitAssertNull(String variableName) |
static String |
junitAssertNumbersMatch(String expectedValue,
String variableName)
junit does not support equal assertions for double type, then employ numbersMatch here
|
static String |
methodInvocation(String obj,
String methodName,
String params) |
static String |
newArray(String fullName,
int length) |
static String |
newList() |
static String |
newMap() |
static String |
newObject(String fullName)
process new Object()
|
static String |
newObjectConsParams(String fullName,
String params)
process new Object(p1, p2)
|
static String |
newSet() |
static String |
oneLineInstance(boolean isDeclaration,
boolean doesIncludeName,
String fullName,
String varName,
String value)
create an instance with one line
eg, fullName varName = value;
|
static String |
oneLineSetterInstance(String setterMethodName,
String fullName,
String varName,
String value)
set instance with setter
eg, varName.setterMethodName((fullName)value)
|
static List<Integer> |
randomNInt(int max,
int n)
select n int from a range [0, max)
Note that this is only used for deciding a number of data in collection to be asserted
then it should not have any side-effect to randomness of search
|
static String |
setInstance(boolean includeVarName,
String varName,
String instance)
process [varName] = [instance]; or [instance];
|
static String |
setInstance(String varName,
String instance)
process [varName] = [instance]
|
static String |
setInstanceObject(String fullName,
String varName)
process [varName] = new Object()
|
static String |
withLength(String variableName) |
static String |
withSize(String variableName) |
public static String handleEscapeCharInString(String orgValue)
orgValue - is an original stringpublic static String enumValue(String enumTypeName, String itemName)
enumTypeName - the enum nameitemName - the item name of the enumpublic static String oneLineInstance(boolean isDeclaration, boolean doesIncludeName, String fullName, String varName, String value)
isDeclaration - whether the instance is also for declarationdoesIncludeName - whether to include variable namefullName - is the full name of the variablevarName - is the variable namevalue - is string to create the instancepublic static String oneLineSetterInstance(String setterMethodName, String fullName, String varName, String value)
setterMethodName - is the setter method namefullName - is full name of the instancevarName - is variable namevalue - of the instancepublic static String setInstanceObject(String fullName, String varName)
varName - specifies the variable namefullName - specifies the full name of the classpublic static String setInstance(String varName, String instance)
varName - specifies the variable nameinstance - specifies the instancepublic static String setInstance(boolean includeVarName, String varName, String instance)
includeVarName - specifies whether to set instance to variablevarName - specifies the variable nameinstance - specifies the instancepublic static String newObject(String fullName)
fullName - is a full name of the type of objectpublic static String newObjectConsParams(String fullName, String params)
fullName - is a full name of the type of objectparams - is a string which could represent a list of params divided with ,public static String newArray(String fullName, int length)
fullName - is full name of the typelength - is length of array to newpublic static String newSet()
public static String newMap()
public static String newList()
public static String getIndent(int indent)
indent - is a number of indent (here we use space)public static List<String> getStringListWithIndent(List<String> codes, int indent)
codes - a list of codes, could be a blockindent - is a number of indent for the codespublic static List<String> addCode(List<String> codes, String code, int indent)
codes - is a list of current codecode - is one line code to be appended to the [codes]indent - is a number of indent for the [code]public static List<String> addComment(List<String> codes, String comment, int indent)
codes - is a list of current codecomment - is one line commentindent - is a number of indent for the [code]public static String castToType(String typeName, String objCode)
typeName - to castobjCode - is the code representing object to castpublic static String getGetClientMethod(String controllerVarName, String interfaceName)
controllerVarName - specifies the controller variable nameinterfaceName - specifies the interface name to get its corresponding clientpublic static String methodInvocation(String obj, String methodName, String params)
obj - specifies an object which owns the method. it is nullablemethodName - specifies a name of the methodparams - specifies a list of paramspublic static String appendLast()
public static String junitAssertEquals(String expectedValue, String variableName)
expectedValue - is the excepted valuevariableName - is the variable name to be checkedpublic static String junitAssertNull(String variableName)
variableName - is the variable name to be checkedpublic static String withSize(String variableName)
variableName - is the variable which has size() methodpublic static String withLength(String variableName)
variableName - is the variable which has length fieldpublic static String junitAssertNumbersMatch(String expectedValue, String variableName)
expectedValue - is the excepted valuevariableName - is the variable name to be checkedpublic static String handleVariableName(String original)
original - is the original name of the variableCopyright © 2016–2022. All rights reserved.