Class MethodSpecImpl.BuilderImpl
java.lang.Object
org.tquadrat.foundation.javacomposer.internal.MethodSpecImpl.BuilderImpl
- All Implemented Interfaces:
MethodSpec.Builder
- Enclosing class:
MethodSpecImpl
@ClassVersion(sourceVersion="$Id: MethodSpecImpl.java 1105 2024-02-28 12:58:46Z tquadrat $")
@API(status=INTERNAL,
since="0.0.5")
public static final class MethodSpecImpl.BuilderImpl
extends Object
implements MethodSpec.Builder
The implementation for
MethodSpec.Builder- Author:
- Square,Inc.
- Modified by:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: MethodSpecImpl.java 1105 2024-02-28 12:58:46Z tquadrat $
- Since:
- 0.0.5
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.javacomposer.internal.MethodSpecImpl.BuilderImpl"
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Collection<AnnotationSpecImpl> The annotations for the method.private final CodeBlockImpl.BuilderImplThe code for the method.private final JavaComposerThe reference to the factory.private CodeBlockImplThe default value for the method; this is for annotations only.private final Collection<TypeNameImpl> The declared exceptions for the method.private final CodeBlockImpl.BuilderImplThe Javadoc comment for the method.The modifiers for the method.private final StringThe name for the method.private final List<ParameterSpecImpl> The parameters for the method.private final CodeBlockImpl.BuilderImplThe comment for the return value for the method.private TypeNameImplThe return type for the method.private final Collection<String> The static imports.private final Collection<TypeVariableNameImpl> The type variables for the method.private booleanThe flag that indicates whether a parameter (the last one) is avarargsparameter. -
Constructor Summary
ConstructorsConstructorDescriptionBuilderImpl(JavaComposer composer, CharSequence name) Creates a newBuilderImplinstance. -
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.final MethodSpecImplbuild()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.final Collection<TypeNameImpl> Returns a reference to the declared exceptions.nextControlFlow(String controlFlow, Object... args) Begins another control flow for the method.final List<ParameterSpecImpl> Returns a reference tothe parameters.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.varargs()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.
-
Field Details
-
m_Annotations
The annotations for the method. -
m_Code
The code for the method. -
m_Composer
The reference to the factory. -
m_DefaultValue
The default value for the method; this is for annotations only. -
m_Exceptions
The declared exceptions for the method. -
m_Javadoc
The Javadoc comment for the method. -
m_Modifiers
The modifiers for the method. -
m_Name
The name for the method. -
m_Parameters
The parameters for the method. -
m_ReturnComment
The comment for the return value for the method. -
m_ReturnType
The return type for the method. -
m_StaticImports
The static imports. -
m_TypeVariables
The type variables for the method. -
m_Varargs
The flag that indicates whether a parameter (the last one) is avarargsparameter.
-
-
Constructor Details
-
BuilderImpl
Creates a newBuilderImplinstance.- Parameters:
composer- The reference to the factory that created this builder instance.name- The name for the method.
-
-
Method Details
-
addAnnotation
Adds an annotation for the method.- Specified by:
addAnnotationin interfaceMethodSpec.Builder- Parameters:
annotationSpec- The annotation.- Returns:
- This
Builderinstance.
-
addAnnotation
Adds an annotation for the method.- Specified by:
addAnnotationin interfaceMethodSpec.Builder- Parameters:
annotation- The annotation.- Returns:
- This
Builderinstance.
-
addAnnotation
Adds an annotation for the method.- Specified by:
addAnnotationin interfaceMethodSpec.Builder- Parameters:
annotationClass- The annotation.- Returns:
- This
Builderinstance.
-
addAnnotations
public final MethodSpecImpl.BuilderImpl addAnnotations(Iterable<? extends AnnotationSpec> annotationSpecs) Adds annotations for the method.- Specified by:
addAnnotationsin interfaceMethodSpec.Builder- Parameters:
annotationSpecs- The annotations.- Returns:
- This
Builderinstance.
-
addCode
Adds code for the method.- Specified by:
addCodein interfaceMethodSpec.Builder- Parameters:
codeBlock- The code.- Returns:
- This
Builderinstance.
-
addCode
Adds code for the method.- Specified by:
addCodein interfaceMethodSpec.Builder- Parameters:
format- The format.args- The arguments.- Returns:
- This
Builderinstance.
-
addComment
Adds a comment for the method.- Specified by:
addCommentin interfaceMethodSpec.Builder- Parameters:
format- The format.args- The arguments.- Returns:
- This
Builderinstance.
-
addException
Adds the declaration for an exception for the method.- Specified by:
addExceptionin interfaceMethodSpec.Builder- Parameters:
exception- The exception.- Returns:
- This
Builderinstance.
-
addException
Adds the declaration for an exception for the method.- Specified by:
addExceptionin interfaceMethodSpec.Builder- Parameters:
exception- The exception.- Returns:
- This
Builderinstance.
-
addExceptions
Adds the declarations for exceptions for the method.- Specified by:
addExceptionsin interfaceMethodSpec.Builder- Parameters:
exceptions- The exceptions.- Returns:
- This
Builderinstance.
-
addJavadoc
Adds a Javadoc comment for the method.- Specified by:
addJavadocin interfaceMethodSpec.Builder- Parameters:
block- The Javadoc comment.- Returns:
- This
Builderinstance.
-
addJavadoc
Adds a Javadoc comment for the method.- Specified by:
addJavadocin interfaceMethodSpec.Builder- Parameters:
format- The format.args- The arguments.- Returns:
- This
Builderinstance.
-
addModifiers
Adds modifiers for the method.- Specified by:
addModifiersin interfaceMethodSpec.Builder- Parameters:
modifiers- The modifiers.- Returns:
- This
Builderinstance.
-
addModifiers
Adds modifiers for the method.- Specified by:
addModifiersin interfaceMethodSpec.Builder- 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.- Specified by:
addNamedCodein interfaceMethodSpec.Builder- Parameters:
format- The format.args- The arguments.- Returns:
- This
Builderinstance.
-
addParameter
Adds a parameter for the method.- Specified by:
addParameterin interfaceMethodSpec.Builder- Parameters:
parameterSpec- The parameter.- Returns:
- This
Builderinstance.
-
addParameter
Adds a parameter for the method.- Specified by:
addParameterin interfaceMethodSpec.Builder- Parameters:
type- The type of the parameter.name- The name of the parameter.modifiers- The modifiers for the parameter.- Returns:
- This
Builderinstance.
-
addParameter
public final MethodSpecImpl.BuilderImpl addParameter(TypeName type, String name, Modifier... modifiers) Adds a parameter for the method.- Specified by:
addParameterin interfaceMethodSpec.Builder- Parameters:
type- The type of the parameter.name- The name of the parameter.modifiers- The modifiers for the parameter.- Returns:
- This
Builderinstance.
-
addParameters
public final MethodSpecImpl.BuilderImpl addParameters(Iterable<? extends ParameterSpec> parameterSpecs) Adds parameters for the method.- Specified by:
addParametersin interfaceMethodSpec.Builder- Parameters:
parameterSpecs- The parameters.- Returns:
- This
Builderinstance.
-
addStatement
Adds a statement to the code for the method.- Specified by:
addStatementin interfaceMethodSpec.Builder- Parameters:
format- The format.args- The arguments.- Returns:
- This
Builderinstance.
-
addStaticImport
@API(status=STABLE, since="0.2.0") public final MethodSpecImpl.BuilderImpl addStaticImport(Class<?> clazz, String... names) Adds a static import.- Specified by:
addStaticImportin interfaceMethodSpec.Builder- Parameters:
clazz- The class.names- The names of the elements from the given class that are to be imported.- Returns:
- This
Builderinstance.
-
addStaticImport
@API(status=STABLE, since="0.2.0") public final MethodSpecImpl.BuilderImpl addStaticImport(ClassName className, String... names) Adds a static import.- Specified by:
addStaticImportin interfaceMethodSpec.Builder- Parameters:
className- The class.names- The names of the elements from the given class that are to be imported.- Returns:
- This
Builderinstance.
-
addStaticImport
@API(status=STABLE, since="0.2.0") public final MethodSpecImpl.BuilderImpl addStaticImport(Enum<?> constant) Adds a static import for the givenenumvalue.- Specified by:
addStaticImportin interfaceMethodSpec.Builder- Parameters:
constant- Theenumvalue.- Returns:
- This
Builderinstance.
-
addTypeVariable
Adds a type variable for the method.- Specified by:
addTypeVariablein interfaceMethodSpec.Builder- Parameters:
typeVariable- The type variable.- Returns:
- This
Builderinstance.
-
addTypeVariables
Adds type variables for the method.- Specified by:
addTypeVariablesin interfaceMethodSpec.Builder- Parameters:
typeVariables- The type variables.- Returns:
- This
Builderinstance.
-
beginControlFlow
Adds the beginning of a control flow for the method.- Specified by:
beginControlFlowin interfaceMethodSpec.Builder- 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.- Specified by:
buildin interfaceMethodSpec.Builder- Returns:
- The
MethodSpecinstance.
-
defaultValue
Sets the default value for this method.- Specified by:
defaultValuein interfaceMethodSpec.Builder- Parameters:
defaultValue- The default value.- Returns:
- This
Builderinstance.
-
defaultValue
Sets the default value for this method.- Specified by:
defaultValuein interfaceMethodSpec.Builder- Parameters:
format- The format.args- The arguments.- Returns:
- This
Builderinstance.
-
endControlFlow
Ends the current control flow for the method.- Specified by:
endControlFlowin interfaceMethodSpec.Builder- Returns:
- This
Builderinstance. - See Also:
-
endControlFlow
Ends the current control flow for the method; this version is only used fordo-whileconstructs.- Specified by:
endControlFlowin interfaceMethodSpec.Builder- 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:
-
exceptions
Returns a reference to the declared exceptions.- Returns:
- The exceptions.
-
nextControlFlow
Begins another control flow for the method.- Specified by:
nextControlFlowin interfaceMethodSpec.Builder- 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:
-
parameters
Returns a reference tothe parameters.- Returns:
- The parameters.
-
returns
Sets the return type for the method.- Specified by:
returnsin interfaceMethodSpec.Builder- Parameters:
returnType- The return type.- Returns:
- This
Builderinstance.
-
returns
Sets the return type for the method and adds the respective Javadoc comment.- Specified by:
returnsin interfaceMethodSpec.Builder- 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.- Specified by:
returnsin interfaceMethodSpec.Builder- Parameters:
returnType- The return type.- Returns:
- This
Builderinstance.
-
returns
Sets the return type for the method and adds the respective Javadoc comment.- Specified by:
returnsin interfaceMethodSpec.Builder- 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.- Specified by:
varargsin interfaceMethodSpec.Builder- Returns:
- This
Builderinstance.
-
varargs
Sets the flag that indicates whether a parameter (the last one) is avarargsparameter.- Specified by:
varargsin interfaceMethodSpec.Builder- Parameters:
varargs-trueif the last parameter is avarargsparameter,falseif not.- Returns:
- This
Builderinstance.
-
