Package org.faktorips.codegen
Class JavaCodeFragmentBuilder
java.lang.Object
org.faktorips.codegen.JavaCodeFragmentBuilder
A builder to create JavaCodeFragments with a uniform coding style.
JavaCodeFragmentBuilder uses the method chaining pattern: Every method modifying the
JavaCodeFragment returns this JavaCodeFragmentBuilder so you could chain the methods as
follows:
javaCodeFragmentBuilder.methodBegin(<method signature parameter>).appendLn(<one line>).methodEnd();.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new fragment builder to build Java source code.JavaCodeFragmentBuilder(boolean indent) Creates a new fragment builder to build Java source code. -
Method Summary
Modifier and TypeMethodDescriptionAdds an import entry to the code fragment under construction.Adds an import entry to the code fragment under construction.annotation(Class<?> annotation, JavaCodeFragment params) Writes the annotation with the indicated parameters and a line separator. '@' character and a line feed will be automatically added.annotation(String[] annotations) Writes the annotations.annotation(String annotation, String paramName, String stringValue) Writes the annotation with the indicated parameter of type String. '@' character will be automatically added.annotation(String annotation, JavaCodeFragment params) Writes the annotation with the indicated parameters. '@' character and a line feed will be automatically added.annotationClassValueLn(String annotation, String paramName, String qualifiedClassName) Writes the annotation for a class value. '@' character and a line feed will be automatically added.annotationLn(Class<?>... annotations) Writes each annotation with a line separator.annotationLn(Class<?> annotation, String params) Writes the annotation with the indicated parameters and a line separator. '@' character and a line feed will be automatically added.annotationLn(Class<?> annotation, String paramName, String stringValue) Writes the annotation with the indicated parameter of type String and adds a line separator. '@' character and a line feed will be automatically added.annotationLn(Class<?> annotation, JavaCodeFragment params) Writes the annotation with the indicated parameters and a line separator. '@' character and a line feed will be automatically added.annotationLn(String annotation) Writes the annotation.annotationLn(String annotation, String params) annotationLn(String annotation, String paramName, String stringValue) Writes the annotation with the indicated parameter of type String. '@' character and a line feed will be automatically added.annotationLn(String annotation, JavaCodeFragment params) Writes the annotation with the indicated parameters. '@' character and a line feed will be automatically added.append(char c) Appends the given char to the fragment's source code.append(int i) Appends the given int to the fragment's source code.Appends the given String to the fragment's source code.append(JavaCodeFragment fragment) Appends the given fragment to the fragment under construction and indents it properly.appendClassName(Class<?> clazz) Appends the class' unqualified name to the source code and updates the import declaration (if necessary).appendClassName(String qualifiedClassName) Appends the unqualified class name to the source code and updates the import declaration (if necessary).appendGenerics(Class<?>... classes) Appends the generic parameters to the builder: <class1, class2, ...>.appendGenerics(String... classNames) Appends the generic parameters to the builder: <className1, className2, ...>.appendJavaModifier(int modifier) Append the Java modifier translated to a String, e.g. for java.lang.reflect.Modifier.PUBLIC "public" is appended.appendJoin(List<JavaCodeFragment> parts, String separator) appendln()Appends a line separator to fragment's source code.appendln(char c) Appends the given char to the fragment's source code.Appends the given String and a line separator to the fragment's source code.appendParameters(String[] parameters) appendParameters(JavaCodeFragment[] parameters) Encloses the given String with double quotes (") and appends it to fragment.assignment(String variable, String value) Creates a new variable declaration.assignment(String variable, JavaCodeFragment expression) Appends a new assignment.classBegin(int modifier, String className) Appends the source code for the beginning of a new class at the end of the fragment under construction.classBegin(int modifier, String className, Class<?> extendsClass, Class<?>[] interfaces) Appends the source code for the beginning of a new class at the end of the fragment under construction.classBegin(int modifier, String className, String extendsClassName, String[] interfaces) Appends the source code for the beginning of a new class at the end of the fragment under construction.classEnd()Writes the code at the end of a class.Adds a closing bracket and decreases the indentation level by one afterwards.constructorCall(String className, String[] parameters, boolean finishLine) append a constructor call: new <name>(parameters[0], parameters[1], ...)constructorCall(String className, List<String> parameters, boolean finishLine) Appends the source code for the beginning of a new enum at the end of the fragment under construction.Returns the fragment under construction.interfaceBegin(String interfaceName) Appends the source code for the beginning of a new interface at the end of the fragment under construction.interfaceBegin(String interfaceName, String extendsInterfaceName) Appends the source code for the beginning of a new interface at the end of the fragment under construction.interfaceBegin(String interfaceName, String[] extendedInterfaces) Appends the source code for the beginning of a new interface at the end of the fragment under construction.Puts the given text and annotations into a java doc comment.method(int modifier, Class<?> returnType, String methodName, String[] argName, Class<?>[] argClass, Class<?>[] exceptionClasses, JavaCodeFragment body, String javadoc) Creates the Java source code for a method including signature, body and java doc.method(int modifier, Class<?> returnType, String methodName, String[] argName, Class<?>[] argClass, JavaCodeFragment body, String javadoc) Creates the Java source code for a method including signature, body and java doc.method(int modifier, Class<?> returnType, String methodName, String[] argName, Class<?>[] argClass, JavaCodeFragment body, String javadoc, String... javaDocAnnotations) Creates the Java source code for a method including signature, body and java doc.method(int modifier, Class<?> returnType, String methodName, String[] argName, Class<?>[] argClass, JavaCodeFragment body, String javadoc, String[] javaDocAnnotations, String[] annotations) Creates the Java source code for a method including signature, body and java doc.method(int modifier, String returnType, String methodName, String[] argName, String[] argClass, JavaCodeFragment body, String javadoc) Creates the Java source code for a method including signature, body and java doc.method(int modifier, String returnType, String methodName, String[] argName, String[] argClass, JavaCodeFragment body, String javadoc, String... javaDocAnnotations) Creates the Java source code for a method including signature, body and java doc.method(int modifier, String returnType, String methodName, String[] argName, String[] argClass, JavaCodeFragment body, String javadoc, String[] javaDocAnnotations, String[] annotations) Creates the Java source code for a method including signature, body and java doc.methodBegin(int modifier, Class<?> returnType, String methodName, String[] argName, Class<?>[] argClass) Creates the Java source code for a method signature.methodBegin(int modifier, Class<?> returnType, String methodName, String[] argName, Class<?>[] argClass, Class<?>[] exceptionClasses) Creates the Java source code for a method signature.methodBegin(int modifier, Class<?> returnType, String methodName, String[] argName, Class<?>[] argClass, String javaDoc, String[] javaDocAnnotations) Creates the Java source code for a method signature.methodBegin(int modifier, String returnType, String methodName, String[] argName, String[] argClass) Creates the Java source code for a method signature.methodBegin(int modifier, String returnType, String methodName, String[] argName, String[] argClass, String javaDoc) Creates the Java source code for a method signature.methodBegin(int modifier, String returnType, String methodName, String[] argName, String[] argClass, String[] exceptionClasses) Creates the Java source code for a method signature.methodBegin(int modifier, String returnType, String methodName, String[] argName, String[] argClass, String javaDoc, String[] javaDocAnnotations) Creates the Java source code for a method signature.methodCall(String name, String[] parameters, boolean finishLine) Writes a method call to the java code fragment builder.methodCall(String name, List<String> parameters, boolean finishLine) methodCall(String name, JavaCodeFragment[] parameterFragments, boolean finishLine) Writes a method call to the java code fragment builder.Appends the source code for the the end of a method.multiLineComment(String comment) Adds an opening bracket followed by a newline and increases the indentation level by one afterwards.Creates the Java source code for a method signature.signature(int modifier, String returnType, String methodName, String[] argName, String[] argClass, boolean argFinal) Creates the Java source code for a method signature.signature(int modifier, String returnType, String methodName, String[] argName, String[] argClass, String[] exceptionClasses) Creates the Java source code for a method signature.signature(int modifier, String returnType, String methodName, String[] argName, String[] argClass, String javaDoc, String[] javaDocAnnotations) Creates the Java source code for a method signature.signature(int modifier, JavaCodeFragment returnType, String methodName, String[] argName, String[] argClass) Creates the Java source code for a method signature.signature(int modifier, JavaCodeFragment returnType, String methodName, String[] argName, String[] argClass, String[] exceptionClasses) Creates the Java source code for a method signature.singleLineComment(String comment) toString()varDeclaration(int modifier, Class<?> clazz, String varName) Creates a new variable declaration.varDeclaration(int modifier, Class<?> clazz, String varName, JavaCodeFragment expression) Creates a new variable declaration.varDeclaration(int modifier, String className, String varName) Creates a new variable declaration.varDeclaration(int modifier, String className, String varName, JavaCodeFragment expression) Creates a new variable declaration.varDeclaration(int modifier, JavaCodeFragment className, String varName, JavaCodeFragment expression) Creates a new variable declaration.varDefinition(Class<?> varClass, String varName, String varValue) Writes a variable definition.varDefinition(String classOrTypeName, String variableName, String variableValue) Writes a variable definition.
-
Constructor Details
-
JavaCodeFragmentBuilder
public JavaCodeFragmentBuilder()Creates a new fragment builder to build Java source code. -
JavaCodeFragmentBuilder
public JavaCodeFragmentBuilder(boolean indent) Creates a new fragment builder to build Java source code.
-
-
Method Details
-
getFragment
Returns the fragment under construction. -
addImport
Adds an import entry to the code fragment under construction.- Parameters:
qualifiedClassName- the java class that is added to the import declaration
-
addImport
Adds an import entry to the code fragment under construction. -
appendln
Appends a line separator to fragment's source code. -
append
Appends the given String to the fragment's source code. -
appendQuoted
Encloses the given String with double quotes (") and appends it to fragment. -
append
Appends the given char to the fragment's source code. -
append
Appends the given int to the fragment's source code. -
appendClassName
Appends the class' unqualified name to the source code and updates the import declaration (if necessary). -
appendClassName
Appends the unqualified class name to the source code and updates the import declaration (if necessary). -
appendln
Appends the given String and a line separator to the fragment's source code. -
appendln
Appends the given char to the fragment's source code. -
append
Appends the given fragment to the fragment under construction and indents it properly. -
appendJavaModifier
Append the Java modifier translated to a String, e.g. for java.lang.reflect.Modifier.PUBLIC "public" is appended.- Parameters:
modifier- Modifier according to java.lang.reflect.Modifier- See Also:
-
openBracket
Adds an opening bracket followed by a newline and increases the indentation level by one afterwards. -
closeBracket
Adds a closing bracket and decreases the indentation level by one afterwards. -
method
public JavaCodeFragmentBuilder method(int modifier, String returnType, String methodName, String[] argName, String[] argClass, JavaCodeFragment body, String javadoc) Creates the Java source code for a method including signature, body and java doc.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructormethodName- the name of the method.argName- Argument names.argClass- Argument classes.body- the method bodyjavadoc- the java documentation
-
methodBegin
public JavaCodeFragmentBuilder methodBegin(int modifier, Class<?> returnType, String methodName, String[] argName, Class<?>[] argClass) Creates the Java source code for a method signature.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- The className that the methods returns an instance of ornullto indicate no return type in case of a constructor. The return typevoidis indicated byjava.lang.Void.class:argName- Argument names.argClass- Argument classes.
-
methodBegin
public JavaCodeFragmentBuilder methodBegin(int modifier, Class<?> returnType, String methodName, String[] argName, Class<?>[] argClass, Class<?>[] exceptionClasses) Creates the Java source code for a method signature.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- The className that the methods returns an instance of ornullto indicate no return type in case of a constructor. The return typevoidis indicated byjava.lang.Void.class:argName- Argument names.argClass- Argument classes.
-
method
public JavaCodeFragmentBuilder method(int modifier, Class<?> returnType, String methodName, String[] argName, Class<?>[] argClass, JavaCodeFragment body, String javadoc) Creates the Java source code for a method including signature, body and java doc.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.methodName- the name of the method.argName- Argument names.argClass- Argument classes.body- the method bodyjavadoc- the java documentation
-
method
public JavaCodeFragmentBuilder method(int modifier, Class<?> returnType, String methodName, String[] argName, Class<?>[] argClass, Class<?>[] exceptionClasses, JavaCodeFragment body, String javadoc) Creates the Java source code for a method including signature, body and java doc.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.methodName- the name of the method.argName- Argument names.argClass- Argument classes.exceptionClasses- Exception classes that can be thrown by the generated methodbody- the method bodyjavadoc- the java documentation
-
method
public JavaCodeFragmentBuilder method(int modifier, Class<?> returnType, String methodName, String[] argName, Class<?>[] argClass, JavaCodeFragment body, String javadoc, String... javaDocAnnotations) Creates the Java source code for a method including signature, body and java doc.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.methodName- the name of the method.argName- Argument names.argClass- Argument classes.body- the method bodyjavadoc- the java documentationjavaDocAnnotations- annotations of the java documentation
-
method
public JavaCodeFragmentBuilder method(int modifier, Class<?> returnType, String methodName, String[] argName, Class<?>[] argClass, JavaCodeFragment body, String javadoc, String[] javaDocAnnotations, String[] annotations) Creates the Java source code for a method including signature, body and java doc.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.methodName- the name of the method.argName- Argument names.argClass- Argument classes.body- the method bodyjavadoc- the java documentationjavaDocAnnotations- annotations of the java documentationannotations- Java 5 annotations
-
method
public JavaCodeFragmentBuilder method(int modifier, String returnType, String methodName, String[] argName, String[] argClass, JavaCodeFragment body, String javadoc, String... javaDocAnnotations) Creates the Java source code for a method including signature, body and java doc.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructormethodName- the name of the method.argName- Argument names.argClass- Argument classes.body- the method bodyjavadoc- the java documentationjavaDocAnnotations- annotations of the java documentation
-
method
public JavaCodeFragmentBuilder method(int modifier, String returnType, String methodName, String[] argName, String[] argClass, JavaCodeFragment body, String javadoc, String[] javaDocAnnotations, String[] annotations) Creates the Java source code for a method including signature, body and java doc.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructormethodName- the name of the method.argName- Argument names.argClass- Argument classes.body- the method bodyjavadoc- the java documentationjavaDocAnnotations- annotations of the java documentationannotations- Java 5 annotations
-
methodBegin
public JavaCodeFragmentBuilder methodBegin(int modifier, String returnType, String methodName, String[] argName, String[] argClass, String javaDoc) Creates the Java source code for a method signature. If the method is non abstract the generated code ends with an opening bracket '{'. If the method is abstract the code ends with the argument list's closing bracket ')'.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.argName- Argument names.argClass- Argument classes.javaDoc- the java documentation for this method signature
-
methodBegin
public JavaCodeFragmentBuilder methodBegin(int modifier, String returnType, String methodName, String[] argName, String[] argClass, String javaDoc, String[] javaDocAnnotations) Creates the Java source code for a method signature. If the method is non abstract the generated code ends with an opening bracket '{'. If the method is abstract the code ends with the argument list's closing bracket ')'.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.argName- Argument names.argClass- Argument classes.javaDoc- the java documentation for this method signaturejavaDocAnnotations- annotations of the java documentation
-
methodBegin
public JavaCodeFragmentBuilder methodBegin(int modifier, Class<?> returnType, String methodName, String[] argName, Class<?>[] argClass, String javaDoc, String[] javaDocAnnotations) Creates the Java source code for a method signature. If the method is non abstract the generated code ends with an opening bracket '{'. If the method is abstract the code ends with the argument list's closing bracket ')'.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.argName- Argument names.argClass- Argument classes.javaDoc- the java documentation for this method signaturejavaDocAnnotations- annotations of the java documentation
-
methodBegin
public JavaCodeFragmentBuilder methodBegin(int modifier, String returnType, String methodName, String[] argName, String[] argClass) Creates the Java source code for a method signature. If the method is non abstract the generated code ends with an opening bracket '{'. If the method is abstract the code ends with the argument list's closing bracket ')'.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.argName- Argument names.argClass- Argument classes.
-
methodBegin
public JavaCodeFragmentBuilder methodBegin(int modifier, String returnType, String methodName, String[] argName, String[] argClass, String[] exceptionClasses) Creates the Java source code for a method signature. If the method is non abstract the generated code ends with an opening bracket '{'. If the method is abstract the code ends with the argument list's closing bracket ')'.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.argName- Argument names.argClass- Argument classes.
-
signature
public JavaCodeFragmentBuilder signature(int modifier, String returnType, String methodName, String[] argName, String[] argClass) Creates the Java source code for a method signature.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.argName- Argument names.argClass- Argument classes.
-
signature
public JavaCodeFragmentBuilder signature(int modifier, JavaCodeFragment returnType, String methodName, String[] argName, String[] argClass) Creates the Java source code for a method signature.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.argName- Argument names.argClass- Argument classes.
-
signature
public JavaCodeFragmentBuilder signature(int modifier, String returnType, String methodName, String[] argName, String[] argClass, boolean argFinal) Creates the Java source code for a method signature.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.argName- Argument names.argClass- Argument classes.argFinal- indicates if the arguments are prefix be a final modifier
-
signature
public JavaCodeFragmentBuilder signature(int modifier, String returnType, String methodName, String[] argName, String[] argClass, String[] exceptionClasses) Creates the Java source code for a method signature.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.argName- Argument names.argClass- Argument classes.exceptionClasses- the thrown exceptions
-
signature
public JavaCodeFragmentBuilder signature(int modifier, JavaCodeFragment returnType, String methodName, String[] argName, String[] argClass, String[] exceptionClasses) Creates the Java source code for a method signature.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.argName- Argument names.argClass- Argument classes.exceptionClasses- the thrown exceptions
-
signature
public JavaCodeFragmentBuilder signature(int modifier, String returnType, String methodName, String[] argName, String[] argClass, String javaDoc, String[] javaDocAnnotations) Creates the Java source code for a method signature. If the method is non abstract the generated code ends with an opening bracket '{'. If the method is abstract the code ends with the argument list's closing bracket ')'.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.returnType- the className that the methods returns an instance of or null to indicate no return type in case of a constructor.argName- Argument names.argClass- Argument classes.javaDoc- the java documentation for this method signaturejavaDocAnnotations- annotations of the java documentation
-
methodEnd
Appends the source code for the the end of a method. If the method is abstract a semicolon is generated, otherwise a closing bracket. If the method is abstract or not, is determined from the modifier used in the last call to methodBegin(). -
classBegin
Appends the source code for the beginning of a new class at the end of the fragment under construction. -
classBegin
public JavaCodeFragmentBuilder classBegin(int modifier, String className, Class<?> extendsClass, Class<?>[] interfaces) Appends the source code for the beginning of a new class at the end of the fragment under construction. -
classBegin
public JavaCodeFragmentBuilder classBegin(int modifier, String className, String extendsClassName, String[] interfaces) Appends the source code for the beginning of a new class at the end of the fragment under construction. -
enumBegin
public JavaCodeFragmentBuilder enumBegin(int modifier, String className, String extendsClassName, String[] interfaces) Appends the source code for the beginning of a new enum at the end of the fragment under construction. -
classEnd
Writes the code at the end of a class. -
interfaceBegin
Appends the source code for the beginning of a new interface at the end of the fragment under construction. -
interfaceBegin
Appends the source code for the beginning of a new interface at the end of the fragment under construction. -
interfaceBegin
Appends the source code for the beginning of a new interface at the end of the fragment under construction. -
varDeclaration
Creates a new variable declaration.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.clazz- The class the variable is an instance ofvarName- the variable's name.
-
varDeclaration
public JavaCodeFragmentBuilder varDeclaration(int modifier, Class<?> clazz, String varName, JavaCodeFragment expression) Creates a new variable declaration.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.clazz- The class the variable is an instance ofvarName- the variable's name.expression- the initial value of the variable
-
varDeclaration
public JavaCodeFragmentBuilder varDeclaration(int modifier, String className, String varName, JavaCodeFragment expression) Creates a new variable declaration.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.className- The class' name the variable is an instance ofvarName- the variable's name.expression- the initial value of the variable
-
varDeclaration
public JavaCodeFragmentBuilder varDeclaration(int modifier, JavaCodeFragment className, String varName, JavaCodeFragment expression) Creates a new variable declaration.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.className- The class' name the variable is an instance ofvarName- the variable's name.expression- the initial value of the variable
-
varDeclaration
Creates a new variable declaration.- Parameters:
modifier- Access modifier according to java.lang.reflect.Modifier.className- The class' name the variable is an instance ofvarName- the variable's name.
-
varDefinition
Writes a variable definition. -
varDefinition
public JavaCodeFragmentBuilder varDefinition(String classOrTypeName, String variableName, String variableValue) Writes a variable definition. -
assignment
Appends a new assignment.varName = value; -
assignment
Creates a new variable declaration.varName = value; -
singleLineComment
-
multiLineComment
-
javaDoc
Puts the given text and annotations into a java doc comment. For an annotation only the annotation name and optionally separated by a space character an annotation text needs to be specified. The '@' character will be automatically added. -
annotationLn
Writes each annotation with a line separator. Import statements are added automatically to the code fragment (if needed). -
annotationLn
Writes the annotation with the indicated parameters and a line separator. '@' character and a line feed will be automatically added. Import statements are added automatically to the code fragment (if needed).- Parameters:
annotation- The annotation classparams- Parameters for the annotation without parenthesis. Ifnullor an empty String, parenthesis aren't added.
-
annotationLn
Writes the annotation with the indicated parameters and a line separator. '@' character and a line feed will be automatically added. Import statements are added automatically to the code fragment (if needed).- Parameters:
annotation- The annotation classparams- Parameters for the annotation without parenthesis. If empty, parenthesis aren't added.
-
annotation
Writes the annotation with the indicated parameters and a line separator. '@' character and a line feed will be automatically added. Import statements are added automatically to the code fragment (if needed).- Parameters:
annotation- The annotation classparams- Parameters for the annotation without parenthesis. If empty, parenthesis aren't added.
-
annotationLn
public JavaCodeFragmentBuilder annotationLn(Class<?> annotation, String paramName, String stringValue) Writes the annotation with the indicated parameter of type String and adds a line separator. '@' character and a line feed will be automatically added. Import statements are added automatically to the code fragment (if needed).Example annotation : javax.xml.bind.annotation.XmlRootElement paramName : name stringValue: policy Result: @XmlElement(name="Policy")
- Parameters:
annotation- The annotation classparamName- The name of the parameterstringValue- The unquoted string value for the parameter. This method generates the quotes.
-
annotationLn
Writes the annotation with the indicated parameters. '@' character and a line feed will be automatically added. Import statements are added automatically to the code fragment (if needed).- Parameters:
annotation- The annotation classparams- Parameters for the annotation without parenthesis. Ifnullor an empty String, parenthesis aren't added.
-
annotation
Writes the annotation with the indicated parameters. '@' character and a line feed will be automatically added. Import statements are added automatically to the code fragment (if needed).- Parameters:
annotation- The annotation classparams- Parameters for the annotation without parenthesis. Ifnullor an empty String, parenthesis aren't added.
-
annotationLn
-
annotationLn
public JavaCodeFragmentBuilder annotationLn(String annotation, String paramName, String stringValue) Writes the annotation with the indicated parameter of type String. '@' character and a line feed will be automatically added. Import statements are added automatically to the code fragment (if needed).Example annotation : javax.xml.bind.annotation.XmlRootElement paramName : name stringValue: policy Result: @XmlElement(name="policy")
- Parameters:
annotation- The annotation classparamName- The name of the parameterstringValue- The unquoted string value for the parameter. This method generates the quotes.
-
annotation
Writes the annotation with the indicated parameter of type String. '@' character will be automatically added. Import statements are added automatically to the code fragment (if needed).Example annotation : javax.xml.bind.annotation.XmlRootElement paramName : name stringValue: policy Result: @XmlElement(name="policy")
- Parameters:
annotation- The annotation classparamName- The name of the parameterstringValue- The unquoted string value for the parameter. This method generates the quotes.
-
annotationClassValueLn
public JavaCodeFragmentBuilder annotationClassValueLn(String annotation, String paramName, String qualifiedClassName) Writes the annotation for a class value. '@' character and a line feed will be automatically added. Import statements are added automatically to the code fragment (if needed).Example annotation : javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter paramName : value qualifiedClassName: EnumValueXmlAdapter Result: @XmlJavaTypeAdapter(value = EnumValueXmlAdapter.class)
- Parameters:
annotation- The annotation classparamName- The name of the parameterqualifiedClassName- The class value for the parameter
-
annotation
Writes the annotations. For an annotation only the annotation name needs to be specified. The '@' character and a line feed will be automatically added. -
annotationLn
Writes the annotation. For an annotation the (fully qualified) annotation class name needs to be specified. The '@' character and a line feed will be automatically added. The annotation may contain parameters in parenthesis.- Parameters:
annotation- The fully qualified annotation name with parameters
-
methodCall
Writes a method call to the java code fragment builder.- Parameters:
name- The name of the method to callparameters- the parameters for the method call- Returns:
- the fragment builder for method chaining
-
methodCall
public JavaCodeFragmentBuilder methodCall(String name, JavaCodeFragment[] parameterFragments, boolean finishLine) Writes a method call to the java code fragment builder.- Parameters:
name- The name of the method to callparameterFragments- the parameters for the method call- Returns:
- the fragment builder for method chaining
-
methodCall
- Parameters:
name- the name of the methodparameters- the list of parameters- Returns:
- the fragment builder for method chaining
- See Also:
-
constructorCall
public JavaCodeFragmentBuilder constructorCall(String className, String[] parameters, boolean finishLine) append a constructor call: new <name>(parameters[0], parameters[1], ...)- Parameters:
finishLine- append a semicolon and new line if true- Returns:
- the JavaCodeFragmentBuilder for Method chaining
-
constructorCall
public JavaCodeFragmentBuilder constructorCall(String className, List<String> parameters, boolean finishLine) - Returns:
- The created instance of
JavaCodeFragmentBuilder - See Also:
-
appendParameters
-
appendParameters
-
appendGenerics
Appends the generic parameters to the builder: <className1, className2, ...>. An import statement is added if a given class has not yet been imported.Note: You have to make sure that generics are supported by target compiler
-
appendGenerics
Appends the generic parameters to the builder: <class1, class2, ...>. An import statement is added if a given class has not yet been imported.Note: You have to make sure that generics are supported by target compiler
-
appendJoin
-
toString
-