public class CodeJavaOrKotlinGenerator extends Object
| Constructor and Description |
|---|
CodeJavaOrKotlinGenerator() |
| 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 |
castToType(String typeName,
String objCode,
boolean isJava)
cast object to a type
|
static String |
codeBlockEnd(boolean isJava) |
static String |
codeBlockStart(boolean isJava) |
static String |
enumValue(String enumTypeName,
String itemName) |
static String |
fieldAccess(String obj,
String filedName,
boolean isJava,
boolean objIsNullable,
boolean isNonNullAsserted) |
static String |
getGetClientMethod(String controllerVarName,
String interfaceName)
process the code to get RPC client
|
static String |
getIndent(int indent) |
static String |
getStatementLast(boolean isJava)
handle last of statement for Java or kotlin
|
static List<String> |
getStringListWithIndent(List<String> codes,
int indent) |
static String |
handleClassNameWithGeneric(String fullName,
List<String> genericTypes)
representation of class with generic
|
static String |
handleEscapeCharInString(String orgValue,
boolean isJava)
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,
boolean isJava) |
static String |
junitAssertNull(String variableName,
boolean isJava) |
static String |
junitAssertNumbersMatch(String expectedValue,
String variableName,
boolean isJava)
junit does not support equal assertions for double type, then employ numbersMatch here
|
static String |
methodInvocation(String obj,
String methodName,
String params,
boolean isJava,
boolean objIsNullable,
boolean isNotNullAsserted) |
static String |
newArray(String fullName,
int length,
boolean isJava) |
static String |
newBuilderProto3(String fullName,
String varBuilderName,
boolean isJava) |
static String |
newList(boolean isJava,
String genericType) |
static String |
newMap(boolean isJava,
String keyGenericType,
String valueGenericType) |
static String |
newObjectConsParams(String fullName,
String params,
boolean isJava)
process new Object(p1, p2)
|
static String |
newSet(boolean isJava,
String genericType) |
static String |
oneLineInstance(boolean isDeclaration,
boolean doesIncludeName,
String fullName,
String varName,
String value,
boolean isJava,
boolean isNullable)
create an instance with one line
eg, fullName varName = value;
|
static String |
oneLineInstance(boolean isDeclaration,
boolean doesIncludeName,
String fullName,
String varName,
String value,
Boolean isPrimitive,
boolean isJava,
boolean isNullable)
create an instance with one line
eg, fullName varName = value;
|
static String |
oneLineSetterInstance(String setterMethodName,
String fullName,
String varName,
String value,
boolean isJava,
boolean isNullable)
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,
boolean isJava)
process [varName] = [instance]; or [instance];
|
static String |
setInstance(String varName,
String instance,
boolean isJava)
process [varName] = [instance]
|
static String |
setInstanceObject(String fullName,
String varName,
boolean isJava)
process [varName] = new Object()
|
static String |
typeNameOfArrayOrCollection(String collectionType,
boolean isArray,
String genericType,
boolean isJava) |
static String |
withLengthInAssertion(String variableName,
boolean isJava,
boolean isNullable) |
static String |
withSizeInAssertion(String variableName,
boolean isJava,
boolean isNullable) |
public static String handleClassNameWithGeneric(String fullName, List<String> genericTypes)
public static String handleEscapeCharInString(String orgValue, boolean isJava)
orgValue - is an original stringisJava - public static String typeNameOfArrayOrCollection(String collectionType, boolean isArray, String genericType, boolean isJava)
public 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, boolean isJava, boolean isNullable)
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 instanceisJava - isNullable - public static String oneLineInstance(boolean isDeclaration, boolean doesIncludeName, String fullName, String varName, String value, Boolean isPrimitive, boolean isJava, boolean isNullable)
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 instanceisPrimitive - indicates whether it is primitive typeisJava - isNullable - public static String oneLineSetterInstance(String setterMethodName, String fullName, String varName, String value, boolean isJava, boolean isNullable)
setterMethodName - is the setter method namefullName - is full name of the instancevarName - is variable namevalue - of the instanceisJava - isNullable - public static String setInstanceObject(String fullName, String varName, boolean isJava)
fullName - specifies the full name of the classvarName - specifies the variable nameisJava - public static String getStatementLast(boolean isJava)
public static String newBuilderProto3(String fullName, String varBuilderName, boolean isJava)
fullName - is the full name of the dtovarBuilderName - is the variable name for the builderisJava - public static String setInstance(String varName, String instance, boolean isJava)
varName - specifies the variable nameinstance - specifies the instanceisJava - public static String setInstance(boolean includeVarName, String varName, String instance, boolean isJava)
includeVarName - specifies whether to set instance to variablevarName - specifies the variable nameinstance - specifies the instanceisJava - public static String newObjectConsParams(String fullName, String params, boolean isJava)
fullName - is a full name of the type of objectparams - is a string which could represent a list of params divided with ,isJava - public static String newArray(String fullName, int length, boolean isJava)
fullName - is full name of the typelength - is length of array to newisJava - public static String newSet(boolean isJava, String genericType)
public static String newMap(boolean isJava, String keyGenericType, String valueGenericType)
public static String newList(boolean isJava, String genericType)
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 String codeBlockStart(boolean isJava)
public static String codeBlockEnd(boolean isJava)
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, boolean isJava)
typeName - to castobjCode - is the code representing object to castisJava - public 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, boolean isJava, boolean objIsNullable, boolean isNotNullAsserted)
obj - specifies an object which owns the method. it is nullablemethodName - specifies a name of the methodparams - specifies a list of paramsisJava - objIsNullable - isNotNullAsserted - public static String fieldAccess(String obj, String filedName, boolean isJava, boolean objIsNullable, boolean isNonNullAsserted)
public static String junitAssertEquals(String expectedValue, String variableName, boolean isJava)
expectedValue - is the excepted valuevariableName - is the variable name to be checkedisJava - public static String junitAssertNull(String variableName, boolean isJava)
variableName - is the variable name to be checkedisJava - public static String withSizeInAssertion(String variableName, boolean isJava, boolean isNullable)
variableName - is the variable which has size() methodisJava - isNullable - public static String withLengthInAssertion(String variableName, boolean isJava, boolean isNullable)
variableName - is the variable which has length fieldisJava - isNullable - public static String junitAssertNumbersMatch(String expectedValue, String variableName, boolean isJava)
expectedValue - is the excepted valuevariableName - is the variable name to be checkedisJava - public static String handleVariableName(String original)
original - is the original name of the variableCopyright © 2016–2025. All rights reserved.