Class Method.Builder
java.lang.Object
be.imgn.gaia.processing.source.Method.Builder
- Enclosing class:
Method
-
Method Summary
Modifier and TypeMethodDescriptionaddAnnotation(Annotation annotation) Adds an annotation.addAnnotation(ClassName annotation) Adds an annotation without members.addAnnotation(Class<? extends Annotation> annotation) Adds an annotation without members.addAnnotations(Iterable<Annotation> more) Adds annotations.Adds code to the body.Adds code to the body.addComment(String format, @Nullable Object... args) Adds a line comment to the body; seeCodeBlock.Builder.addComment(String, Object...).addException(TypeName exception) Adds an exception to thethrowsclause, unless it is there already.addException(Class<? extends Throwable> exception) Adds an exception to thethrowsclause.addException(Type exception) Adds an exception to thethrowsclause, such as a generic exception type of a method.addExceptions(Iterable<? extends TypeName> more) Adds exceptions to thethrowsclause, except those there already.addJavadoc(CodeBlock text) Adds Javadoc text.addJavadoc(String format, @Nullable Object... args) Adds Javadoc text.addModifiers(Iterable<Modifier> more) Adds modifiers.addModifiers(Modifier... more) Adds modifiers.addNamedCode(String format, Map<String, ?> arguments) Adds code whose placeholders name their arguments; seeCodeBlock.Builder.addNamed(String, Map).addParameter(Parameter parameter) Adds a parameter.addParameter(TypeName type, String name, Modifier... modifiers) Adds a parameter.addParameter(Type type, String name, Modifier... modifiers) Adds a parameter.addParameters(Iterable<Parameter> more) Adds parameters.addStatement(CodeBlock statement) Adds a statement to the body: the code, a semicolon and a new line.addStatement(String format, @Nullable Object... args) Adds a statement to the body: the code, a semicolon and a new line.addTypeVariable(TypeVariableName typeVariable) Declares a type variable, such asTin<T> T first(List<T> list).Declares type variables.beginControlFlow(CodeBlock controlFlow) Opens a block in the body; seeCodeBlock.Builder.beginControlFlow(CodeBlock).beginControlFlow(String controlFlow, @Nullable Object... args) Opens a block in the body; seeCodeBlock.Builder.beginControlFlow(String, Object...).build()Builds the method.defaultValue(CodeBlock value) Sets the default value of an annotation type member.defaultValue(String format, @Nullable Object... args) Sets the default value of an annotation type member.Closes a block in the body.endControlFlow(CodeBlock controlFlow) Closes a block in the body with code after its closing brace; seeCodeBlock.Builder.endControlFlow(CodeBlock).endControlFlow(String controlFlow, @Nullable Object... args) Closes a block in the body with code after its closing brace; seeCodeBlock.Builder.endControlFlow(String, Object...).Renames the method, such as a copy made withMethod.toBuilder().nextControlFlow(CodeBlock controlFlow) Closes a block in the body and opens the next one; seeCodeBlock.Builder.nextControlFlow(CodeBlock).nextControlFlow(String controlFlow, @Nullable Object... args) Closes a block in the body and opens the next one; seeCodeBlock.Builder.nextControlFlow(String, Object...).Sets the return type.Sets the return type.varargs()Makes the last parameter variable arity.varargs(boolean isVarargs) Makes the last parameter variable arity, or not.
-
Method Details
-
name
Renames the method, such as a copy made withMethod.toBuilder().- Parameters:
newName- the new name- Returns:
- this builder
- Throws:
IllegalArgumentException- if the name is not a valid identifierIllegalStateException- if this is a constructor
-
addModifiers
Adds modifiers.- Parameters:
more- the modifiers- Returns:
- this builder
- Throws:
IllegalArgumentException- if a modifier is not allowed on a method, or on a constructor if this is one; is repeated; or conflicts with another one, such aspublicwithprivateorabstractwithfinalIllegalStateException- if a modifier isabstractornativeand the method has code, or it isstaticand the method has a receiver parameter
-
addModifiers
Adds modifiers.- Parameters:
more- the modifiers- Returns:
- this builder
- Throws:
IllegalArgumentException- if a modifier is not allowed on a method, or on a constructor if this is one; is repeated; or conflicts with another one, such aspublicwithprivateorabstractwithfinalIllegalStateException- if a modifier isabstractornativeand the method has code, or it isstaticand the method has a receiver parameter
-
addAnnotation
Adds an annotation.- Parameters:
annotation- the annotation- Returns:
- this builder
-
addAnnotation
Adds an annotation without members.- Parameters:
annotation- the annotation type- Returns:
- this builder
- Throws:
IllegalArgumentException- if the class is not an annotation type
-
addAnnotation
Adds an annotation without members.- Parameters:
annotation- the annotation type- Returns:
- this builder
-
addAnnotations
Adds annotations.- Parameters:
more- the annotations- Returns:
- this builder
-
addJavadoc
Adds Javadoc text. End each line with\n.- Parameters:
format- the text, with placeholdersargs- the arguments of the placeholders- Returns:
- this builder
- Throws:
IllegalArgumentException- if the format and the arguments do not match
-
addJavadoc
Adds Javadoc text. End each line with\n.- Parameters:
text- the text- Returns:
- this builder
-
addTypeVariable
Declares a type variable, such asTin<T> T first(List<T> list).- Parameters:
typeVariable- the type variable, with its bounds- Returns:
- this builder
- Throws:
IllegalStateException- if this is a compact constructor
-
addTypeVariables
Declares type variables.- Parameters:
more- the type variables, with their bounds- Returns:
- this builder
- Throws:
IllegalStateException- if this is a compact constructor and there are type variables
-
returns
Sets the return type.- Parameters:
type- the return type- Returns:
- this builder
- Throws:
IllegalArgumentException- if the type is a wildcardIllegalStateException- if this is a constructor
-
returns
Sets the return type.- Parameters:
type- the return type: a class, or a generic type- Returns:
- this builder
- Throws:
IllegalArgumentException- if the type names a local or anonymous class, asTypeName.of(java.lang.reflect.Type)names itIllegalStateException- if this is a constructor
-
addParameter
Adds a parameter.- Parameters:
parameter- the parameter- Returns:
- this builder
- Throws:
IllegalStateException- if this is a compact constructor, or the parameter is a receiver parameter but is not first or the method is static
-
addParameter
Adds a parameter.- Parameters:
type- the typename- the namemodifiers- the modifiers: none, orfinal- Returns:
- this builder
- Throws:
IllegalArgumentException- if the name is not a valid identifier, the type isvoidor a wildcard, or a modifier is notfinal, is repeated, or is given to a receiver parameterIllegalStateException- if this is a compact constructor, or the parameter is a receiver parameter but is not first or the method is static
-
addParameter
Adds a parameter.- Parameters:
type- the type: a class, or a generic typename- the namemodifiers- the modifiers: none, orfinal- Returns:
- this builder
- Throws:
IllegalArgumentException- if the type isvoid, or names a local or anonymous class, asTypeName.of(java.lang.reflect.Type)names it; the name is not a valid identifier; or a modifier is notfinal, is repeated, or is given to a receiver parameterIllegalStateException- if this is a compact constructor, or the parameter is a receiver parameter but is not first or the method is static
-
addParameters
Adds parameters.- Parameters:
more- the parameters- Returns:
- this builder
- Throws:
IllegalStateException- if this is a compact constructor and there are parameters, or a receiver parameter is not first or the method is static
-
varargs
Makes the last parameter variable arity, or not. Its type must be an array.- Parameters:
isVarargs- whether the last parameter is variable arity- Returns:
- this builder
-
varargs
Makes the last parameter variable arity. Its type must be an array.- Returns:
- this builder
-
addException
Adds an exception to thethrowsclause, unless it is there already.- Parameters:
exception- the exception type: a class or a type variable- Returns:
- this builder
- Throws:
IllegalArgumentException- if the exception type is not a class or a type variableIllegalStateException- if this is a compact constructor
-
addException
Adds an exception to thethrowsclause.- Parameters:
exception- the exception type- Returns:
- this builder
- Throws:
IllegalArgumentException- if the class is local or anonymousIllegalStateException- if this is a compact constructor
-
addException
Adds an exception to thethrowsclause, such as a generic exception type of a method.- Parameters:
exception- the exception type: a class or a type variable- Returns:
- this builder
- Throws:
IllegalArgumentException- if the type is a class that is not aThrowable, or is neither a class nor a type variable, or names a local or anonymous classIllegalStateException- if this is a compact constructor
-
addExceptions
Adds exceptions to thethrowsclause, except those there already.- Parameters:
more- the exception types: classes or type variables- Returns:
- this builder
- Throws:
IllegalArgumentException- if an exception type is not a class or a type variableIllegalStateException- if this is a compact constructor and there are exceptions
-
addCode
Adds code to the body.- Parameters:
format- the code, with placeholdersargs- the arguments of the placeholders- Returns:
- this builder
- Throws:
IllegalArgumentException- if the format and the arguments do not matchIllegalStateException- if the method is abstract or native
-
addCode
Adds code to the body.- Parameters:
block- the code- Returns:
- this builder
- Throws:
IllegalStateException- if the method is abstract or native
-
addNamedCode
Adds code whose placeholders name their arguments; seeCodeBlock.Builder.addNamed(String, Map).- Parameters:
format- the code, with named placeholdersarguments- the arguments, by name- Returns:
- this builder
- Throws:
IllegalArgumentException- if a name is not valid, or a placeholder has no argumentIllegalStateException- if the method is abstract or native
-
addStatement
Adds a statement to the body: the code, a semicolon and a new line.- Parameters:
format- the statement, without its semicolon, with placeholdersargs- the arguments of the placeholders- Returns:
- this builder
- Throws:
IllegalArgumentException- if the format and the arguments do not matchIllegalStateException- if the method is abstract or native
-
addStatement
Adds a statement to the body: the code, a semicolon and a new line.- Parameters:
statement- the statement, without its semicolon- Returns:
- this builder
- Throws:
IllegalStateException- if the method is abstract or native
-
addComment
Adds a line comment to the body; seeCodeBlock.Builder.addComment(String, Object...).- Parameters:
format- the comment, without//, with placeholdersargs- the arguments of the placeholders- Returns:
- this builder
- Throws:
IllegalArgumentException- if the format and the arguments do not match, or the comment has a line breakIllegalStateException- if the method is abstract or native
-
beginControlFlow
Opens a block in the body; seeCodeBlock.Builder.beginControlFlow(String, Object...).- Parameters:
controlFlow- the code before the opening brace, with placeholdersargs- the arguments of the placeholders- Returns:
- this builder
- Throws:
IllegalArgumentException- if the format and the arguments do not matchIllegalStateException- if the method is abstract or native
-
beginControlFlow
Opens a block in the body; seeCodeBlock.Builder.beginControlFlow(CodeBlock).- Parameters:
controlFlow- the code before the opening brace- Returns:
- this builder
- Throws:
IllegalStateException- if the method is abstract or native
-
nextControlFlow
Closes a block in the body and opens the next one; seeCodeBlock.Builder.nextControlFlow(String, Object...).- Parameters:
controlFlow- the code between the braces, with placeholdersargs- the arguments of the placeholders- Returns:
- this builder
- Throws:
IllegalArgumentException- if the format and the arguments do not matchIllegalStateException- if the method is abstract or native
-
nextControlFlow
Closes a block in the body and opens the next one; seeCodeBlock.Builder.nextControlFlow(CodeBlock).- Parameters:
controlFlow- the code between the braces- Returns:
- this builder
- Throws:
IllegalStateException- if the method is abstract or native
-
endControlFlow
Closes a block in the body.- Returns:
- this builder
- Throws:
IllegalStateException- if the method is abstract or native
-
endControlFlow
Closes a block in the body with code after its closing brace; seeCodeBlock.Builder.endControlFlow(String, Object...).- Parameters:
controlFlow- the code after the closing brace, without its semicolon, with placeholdersargs- the arguments of the placeholders- Returns:
- this builder
- Throws:
IllegalArgumentException- if the format and the arguments do not matchIllegalStateException- if the method is abstract or native
-
endControlFlow
Closes a block in the body with code after its closing brace; seeCodeBlock.Builder.endControlFlow(CodeBlock).- Parameters:
controlFlow- the code after the closing brace, without its semicolon- Returns:
- this builder
- Throws:
IllegalStateException- if the method is abstract or native
-
defaultValue
Sets the default value of an annotation type member.- Parameters:
format- the value afterdefault, with placeholdersargs- the arguments of the placeholders- Returns:
- this builder
- Throws:
IllegalArgumentException- if the format and the arguments do not match, or the value is not balancedIllegalStateException- if this is a constructor
-
defaultValue
Sets the default value of an annotation type member.- Parameters:
value- the value afterdefault- Returns:
- this builder
- Throws:
IllegalArgumentException- if the value is not balancedIllegalStateException- if this is a constructor
-
build
Builds the method.- Returns:
- the method
- Throws:
IllegalStateException- if it is varargs but its last parameter is not an array, or its Javadoc or code is not balanced
-