Interface MethodSpec.Builder
- All Known Implementing Classes:
MethodSpecImpl.BuilderImpl
- Enclosing interface:
MethodSpec
@ClassVersion(sourceVersion="$Id: MethodSpec.java 1085 2024-01-05 16:23:28Z tquadrat $")
@API(status=STABLE,
since="0.0.5")
public static sealed interface MethodSpec.Builder
permits MethodSpecImpl.BuilderImpl
The builder for an instance of
MethodSpec- Author:
- Square,Inc.
- Modified by:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: MethodSpec.java 1085 2024-01-05 16:23:28Z tquadrat $
- Since:
- 0.0.5
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.javacomposer.MethodSpec.Builder"
-
Method Summary
Modifier and TypeMethodDescriptionaddAnnotation(Class<?> annotation) Adds an annotation for the method.addAnnotation(AnnotationSpec annotationSpec) Adds an annotation for the method.addAnnotation(ClassName annotationClass) Adds an annotation for the method.addAnnotations(Iterable<? extends AnnotationSpec> annotationSpecs) Adds annotations for the method.Adds code for the method.Adds code for the method.addComment(String format, Object... args) Adds a comment for the method.addException(Type exception) Adds the declaration for an exception for the method.addException(TypeName exception) Adds the declaration for an exception for the method.addExceptions(Iterable<? extends TypeName> exceptions) Adds the declarations for exceptions for the method.addJavadoc(String format, Object... args) Adds a Javadoc comment for the method.addJavadoc(CodeBlock block) Adds a Javadoc comment for the method.addModifiers(Iterable<Modifier> modifiers) Adds modifiers for the method.addModifiers(Modifier... modifiers) Adds modifiers for the method.addNamedCode(String format, Map<String, ?> args) Adds code using named arguments for the method.addParameter(Type type, String name, Modifier... modifiers) Adds a parameter for the method.addParameter(ParameterSpec parameterSpec) Adds a parameter for the method.addParameter(TypeName type, String name, Modifier... modifiers) Adds a parameter for the method.addParameters(Iterable<? extends ParameterSpec> parameterSpecs) Adds parameters for the method.addStatement(String format, Object... args) Adds a statement to the code for the method.addStaticImport(Class<?> clazz, String... names) Adds a static import.addStaticImport(Enum<?> constant) Adds a static import for the givenenumvalue.addStaticImport(ClassName className, String... names) Adds a static import.addTypeVariable(TypeVariableName typeVariable) Adds a type variable for the method.addTypeVariables(Iterable<TypeVariableName> typeVariables) Adds type variables for the method.beginControlFlow(String controlFlow, Object... args) Adds the beginning of a control flow for the method.build()Creates a newMethodSpecinstance from the components that have been added to this builder.defaultValue(String format, Object... args) Sets the default value for this method.defaultValue(CodeBlock defaultValue) Sets the default value for this method.Ends the current control flow for the method.endControlFlow(String controlFlow, Object... args) Ends the current control flow for the method; this version is only used fordo-whileconstructs.nextControlFlow(String controlFlow, Object... args) Begins another control flow for the method.Sets the return type for the method.Sets the return type for the method and adds the respective Javadoc comment.Sets the return type for the method.Sets the return type for the method and adds the respective Javadoc comment.default MethodSpec.Buildervarargs()Sets the flag that indicates whether a parameter (the last one) is avarargsparameter totrue.varargs(boolean varargs) Sets the flag that indicates whether a parameter (the last one) is avarargsparameter.
-
Method Details
-
addAnnotation
Adds an annotation for the method.- Note:
-
- No debug information can be added when adding an annotation.
- Parameters:
annotationSpec- The annotation.- Returns:
- This
Builderinstance.
-
addAnnotation
Adds an annotation for the method.- Note:
-
- No debug information can be added when adding an annotation.
- Parameters:
annotation- The annotation.- Returns:
- This
Builderinstance.
-
addAnnotation
Adds an annotation for the method.- Note:
-
- No debug information can be added when adding an annotation.
- Parameters:
annotationClass- The annotation.- Returns:
- This
Builderinstance.
-
addAnnotations
Adds annotations for the method.- Note:
-
- No debug information can be added when adding an annotation.
- Parameters:
annotationSpecs- The annotations.- Returns:
- This
Builderinstance.
-
addCode
Adds code for the method.- Parameters:
codeBlock- The code.- Returns:
- This
Builderinstance.
-
addCode
Adds code for the method.- Parameters:
format- The format.args- The arguments.- Returns:
- This
Builderinstance.
-
addComment
Adds a comment for the method.- Note:
-
- No debug info is added when a comment is added.
- Parameters:
format- The format.args- The arguments.- Returns:
- This
Builderinstance.
-
addException
Adds the declaration for an exception for the method.- Note:
-
- No debug info is added when an exception is added.
- Parameters:
exception- The exception.- Returns:
- This
Builderinstance.
-
addException
Adds the declaration for an exception for the method.- Note:
-
- No debug info is added when an exception is added.
- Parameters:
exception- The exception.- Returns:
- This
Builderinstance.
-
addExceptions
Adds the declarations for exceptions for the method.- Note:
-
- No debug info is added when an exception is added.
- Parameters:
exceptions- The exceptions.- Returns:
- This
Builderinstance.
-
addJavadoc
Adds a Javadoc comment for the method.- Note:
-
- No debug info is added when a comment is added.
- Parameters:
block- The Javadoc comment.- Returns:
- This
Builderinstance.
-
addJavadoc
Adds a Javadoc comment for the method.- Note:
-
- No debug info is added when a comment is added.
- Parameters:
format- The format.args- The arguments.- Returns:
- This
Builderinstance.
-
addModifiers
Adds modifiers for the method.- Parameters:
modifiers- The modifiers.- Returns:
- This
Builderinstance.
-
addModifiers
Adds modifiers for the method.- Parameters:
modifiers- The modifiers.- Returns:
- This
Builderinstance.
-
addNamedCode
Adds code using named arguments for the method.
Named arguments specify their name after the '$' followed by a colon
":"and the corresponding type character. Argument names consist of characters ina-z, A-Z, 0-9, and _and must start with a lowercase character.For example, to refer to the type
Integerwith the argument nameclazzuse a format string containing$clazz:Tand include the keyclazzwith valuejava.lang.Integer.classin the argument map.- Parameters:
format- The format.args- The arguments.- Returns:
- This
Builderinstance.
-
addParameter
Adds a parameter for the method.- Note:
-
- No debug info is added when a parameter is added.
- Parameters:
parameterSpec- The parameter.- Returns:
- This
Builderinstance.
-
addParameter
Adds a parameter for the method.- Note:
-
- No debug info is added when a parameter is added.
- Parameters:
type- The type of the parameter.name- The name of the parameter.modifiers- The modifiers for the parameter.- Returns:
- This
Builderinstance.
-
addParameter
Adds a parameter for the method.- Note:
-
- No debug info is added when a parameter is added.
- Parameters:
type- The type of the parameter.name- The name of the parameter.modifiers- The modifiers for the parameter.- Returns:
- This
Builderinstance.
-
addParameters
Adds parameters for the method.- Note:
-
- No debug info is added when a parameter is added.
- Parameters:
parameterSpecs- The parameters.- Returns:
- This
Builderinstance.
-
addStatement
Adds a statement to the code for the method.- Parameters:
format- The format.args- The arguments.- Returns:
- This
Builderinstance.
-
addStaticImport
@API(status=STABLE, since="0.2.0") MethodSpec.Builder addStaticImport(Class<?> clazz, String... names) Adds a static import.- Parameters:
clazz- The class.names- The names of the elements from the given class that are to be imported.- Returns:
- This
Builderinstance. - Since:
- 0.2.0
-
addStaticImport
@API(status=STABLE, since="0.2.0") MethodSpec.Builder addStaticImport(ClassName className, String... names) Adds a static import.- Parameters:
className- The class.names- The names of the elements from the given class that are to be imported.- Returns:
- This
Builderinstance. - Since:
- 0.2.0
-
addStaticImport
Adds a static import for the givenenumvalue.- Parameters:
constant- Theenumvalue.- Returns:
- This
Builderinstance. - Since:
- 0.2.0
-
addTypeVariable
Adds a type variable for the method.- Note:
-
- No debug info is added when a type variable is added.
- Parameters:
typeVariable- The type variable.- Returns:
- This
Builderinstance.
-
addTypeVariables
Adds type variables for the method.- Note:
-
- No debug info is added when a parameter is added.
- Parameters:
typeVariables- The type variables.- Returns:
- This
Builderinstance.
-
beginControlFlow
Adds the beginning of a control flow for the method.- Parameters:
controlFlow- The control flow construct and its code, such as "if (foo == 5)"; it should not contain braces or newline characters.args- The arguments.- Returns:
- This
Builderinstance. - See Also:
-
build
Creates a newMethodSpecinstance from the components that have been added to this builder.- Returns:
- The
MethodSpecinstance.
-
defaultValue
Sets the default value for this method.- Parameters:
defaultValue- The default value.- Returns:
- This
Builderinstance.
-
defaultValue
Sets the default value for this method.- Parameters:
format- The format.args- The arguments.- Returns:
- This
Builderinstance.
-
endControlFlow
Ends the current control flow for the method.- Returns:
- This
Builderinstance. - See Also:
-
endControlFlow
Ends the current control flow for the method; this version is only used fordo-whileconstructs.- Parameters:
controlFlow- The optional control flow construct and its code, such as "while(foo == 20)"; it should not contain braces or newline characters.args- The arguments.- Returns:
- This
Builderinstance. - See Also:
-
nextControlFlow
Begins another control flow for the method.- Parameters:
controlFlow- The control flow construct and its code, such as "else if (foo == 10)"; it should not contain braces or newline characters.args- The arguments.- Returns:
- This
Builderinstance. - See Also:
-
returns
Sets the return type for the method.- Parameters:
returnType- The return type.- Returns:
- This
Builderinstance.
-
returns
Sets the return type for the method and adds the respective Javadoc comment.- Parameters:
returnType- The return type.format- The format for the return comment.args- The arguments for the return comment.- Returns:
- This
Builderinstance.
-
returns
Sets the return type for the method.- Parameters:
returnType- The return type.- Returns:
- This
Builderinstance.
-
returns
Sets the return type for the method and adds the respective Javadoc comment.- Parameters:
returnType- The return type.format- The format for the return comment.args- The arguments for the return comment.- Returns:
- This
Builderinstance.
-
varargs
Sets the flag that indicates whether a parameter (the last one) is avarargsparameter totrue.- Returns:
- This
Builderinstance.
-
varargs
Sets the flag that indicates whether a parameter (the last one) is avarargsparameter.- Parameters:
varargs-trueif the last parameter is avarargsparameter,falseif not.- Returns:
- This
Builderinstance.
-
