Class JavaComposer
The factory for the various JavaComposer artefacts.
Instances of this class do not maintain a state, therefore they are thread-safe without any synchronisation.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: JavaComposer.java 1105 2024-02-28 12:58:46Z tquadrat $
- Since:
- 0.2.0
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.javacomposer.JavaComposer"
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe Javadoc tag for inherited documentation: "{@inheritDoc}".static final StringThe Javadoc tag for a constant value: "{@value}".private final booleanIf set totrue, some debug information will be added to the output.private final Lazy<AnnotationSpec> The@ClassVersionannotation.private final Lazy<AnnotationSpec> The@UtilityClassannotation.private final CodeProcessorPREVIEWThe code processor associated with this composer instance.The Javadoc comment for an overriding method.private final LayoutThe layout that is used to format the output.private intThe maximum number of fields for a class; if this number is exceeded, an annotation@SuppressWarningswithSuppressableWarnings.CLASS_WITH_TOO_MANY_FIELDSwill be added to the class.private intThe maximum number of methods for a class; if this number is exceeded, an annotation@SuppressWarningswithSuppressableWarnings.CLASS_WITH_TOO_MANY_METHODSwill be added to the class.private final Lazy<MethodSpec> A predefinedequals()method.private final Lazy<MethodSpec> A predefinedhashCode()method.private final Lazy<MethodSpec> A predefinedtoString()method.static final StringMessage: "Cannot override method on final class \'%s\'".static final StringMessage: "Cannot override method with modifier \'%s\'". -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance ofJavaComposerthat uses the defaultLayout.JavaComposer(boolean addDebugOutput) Creates a new instance ofJavaComposerthat uses the defaultLayoutand adds some debug information to the output.JavaComposer(Layout layout) Creates a new instance ofJavaComposer.JavaComposer(Layout layout, boolean addDebugOutput) Creates a new instance ofJavaComposer. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanReturns the flag that controls whether the output should be enhanced with some debug information.final AnnotationSpec.BuilderannotationBuilder(Class<?> type) Creates a builder for an instance of an implementation forAnnotationSpecfrom the givenClassinstance.final AnnotationSpec.BuilderannotationBuilder(ClassName type) Creates a builder for an instance of an implementation forAnnotationSpecfrom the givenClassNameinstance.final TypeSpec.BuilderCreates a builder for an annotation.final TypeSpec.BuilderannotationTypeBuilder(ClassName className) Creates a builder for an annotation.final TypeSpec.BuilderanonymousClassBuilder(String format, Object... args) Creates a builder for an anonymous class.final TypeSpec.BuilderanonymousClassBuilder(CodeBlock typeArguments) Creates a builder for an anonymous class.final TypeSpec.BuilderclassBuilder(CharSequence name) Creates a builder for a regular class.final TypeSpec.BuilderclassBuilder(ClassName className) Creates a builder for a regular class.final CodeBlock.BuilderCreates a builder for an instance ofCodeBlock.final CodeBlockcodeBlockOf(String format, Object... args) Creates a newCodeBlockinstance from the given format and arguments.final MethodSpec.BuilderCreates a builder that builds an instance ofMethodSpecfor a constructor.final AnnotationSpeccreateAnnotation(Annotation annotation) Creates an instance ofAnnotationSpecfrom the givenAnnotationinstance.final AnnotationSpeccreateAnnotation(Annotation annotation, boolean includeDefaultValues) Creates an instance ofAnnotationSpecfrom the givenAnnotationinstance.final AnnotationSpeccreateAnnotation(AnnotationMirror annotation) Creates an instance ofAnnotationSpecfrom the givenAnnotationMirrorinstance.final AnnotationSpecReturns a@ClassVersionannotation with a default text forClassVersion.sourceVersion().final AnnotationSpeccreateClassVersionAnnotation(String sourceVersion) Returns a@ClassVersionannotation with the text forClassVersion.sourceVersion().private final CodeBlockcreateComment4Constant(CodeBlock comment) Creates the comment for a constant.final FieldSpeccreateConstant(CharSequence name, int value, CodeBlock comment) Creates an integer constant.final FieldSpeccreateConstant(CharSequence name, Type type, CodeBlock value, CodeBlock comment) Creates a constant.final FieldSpeccreateConstant(CharSequence name, String value, CodeBlock comment) Creates a String constant.private final FieldSpeccreateConstant(CharSequence name, TypeName type, Number value, CodeBlock comment) Creates a numerical constant.final FieldSpeccreateConstant(CharSequence name, TypeName type, CodeBlock value, CodeBlock comment) Creates a constant.
A constant is an initialisedpublic final staticfield.final MethodSpec.BuilderReturns a builder for an implementation of the methodObject.equals(Object)that just needs the method body for completion.final MethodSpeccreateEqualsMethod(CodeBlock body) Returns aMethodSpecinstance for an implementation of the methodObject.equals(Object).final MethodSpec.BuilderReturns a builder for an implementation of the methodObject.hashCode()that just needs the method body for completion.final MethodSpeccreateHashCodeMethod(Collection<? extends FieldSpec> fields) Returns aMethodSpecinstance for an implementation of the methodObject.hashCode().final MethodSpecReturns aMethodSpecinstance for an implementation of the methodObject.hashCode().final MethodSpeccreateHashCodeMethod(FieldSpec... fields) Returns aMethodSpecinstance for an implementation of the methodObject.hashCode().final CodeBlockReturns a code block with a comment for overriding methods:final MethodSpeccreateMethod(ExecutableElement method) Creates aMethodSpecfor the givenExecutableElement.final ParameterSpeccreateParameter(Parameter parameter) Creates an instance ofParameterSpecfrom the givenParameterinstance.final ParameterSpeccreateParameter(VariableElement element) Creates an instance ofParameterSpecfrom the givenVariableElementinstance.final CodeBlockCreates a return statement with a comment, usingretValueas the name for the return variable.final CodeBlockCreates a return statement with a comment.final TypeSpec.BuildercreateStaticClassBuilder(CharSequence className) Returns a builder for a static class.final Optional<AnnotationSpec> Returns a@SuppressWarningsannotation with the given values.final Optional<AnnotationSpec> createSuppressWarningsAnnotation(SuppressableWarnings... warnings) Returns a@SuppressWarningsannotation with the given values.final MethodSpec.BuilderReturns a builder for an implementation of the methodObject.toString()that just needs the method body for completion.final MethodSpecReturns aMethodSpecinstance for an implementation of the methodObject.toString().final AnnotationSpecReturns a@UtilityClassannotation.final CodeBlockReturns an emptyCodeBlock.final TypeSpec.BuilderenumBuilder(CharSequence name) Creates a builder for anenumtype.final TypeSpec.BuilderenumBuilder(ClassName className) Creates a builder for anenumtype.final booleanfinal FieldSpec.BuilderfieldBuilder(Type type, CharSequence name, Modifier... modifiers) Creates a builder for an instance ofFieldSpecfrom the given type, name and modifiers.final FieldSpec.BuilderfieldBuilder(TypeName type, CharSequence name, Modifier... modifiers) Creates a builder for an instance ofFieldSpecfrom the given type, name and modifiers.final FieldSpec.BuilderfieldBuilder(TypeSpec type, CharSequence name, Modifier... modifiers) Creates a builder for an instance ofFieldSpecfrom the given type, name and modifiers.final CodeProcessorPREVIEWProvides access to the code processor for this composer instance.final LayoutReturns the layout that is used to format the output.final intReturns the maximum number of fields for a class.final intReturns the maximum number of methods for a class.final inthashCode()final TypeSpec.BuilderinterfaceBuilder(CharSequence name) Creates a builder for an interface.final TypeSpec.BuilderinterfaceBuilder(ClassName className) Creates a builder for an interface.final JavaFile.BuilderjavaFileBuilder(CharSequence packageName, TypeSpec typeSpec) Creates a builder for a new instance ofJavaFilefrom the given package name and class definition.final LambdaSpec.BuilderCreates a builder for an instance ofLambdaSpec.final MethodSpec.BuildermethodBuilder(CharSequence name) Returns a builder for a regular method.final MethodSpec.BuilderoverridingMethodBuilder(Method method) Returns a new method builder for a method that overrides the given method.final MethodSpec.BuilderReturns a new method builder for a method that overrides the given method.final MethodSpec.BuilderoverridingMethodBuilder(ExecutableElement method, DeclaredType enclosing, Types typeUtils) Returns a new method builder that overrides the given method as a member of of the given enclosing class.final ParameterSpec.BuilderparameterBuilder(Type type, CharSequence name, Modifier... modifiers) Creates a builder for a newParameterSpecinstance.final ParameterSpec.BuilderparameterBuilder(TypeName type, CharSequence name, Modifier... modifiers) Creates a builder for a newParameterSpecinstance.final ParameterSpecparameterOf(Type type, CharSequence name, Modifier... modifiers) Creates a newParameterSpecinstance for the given arguments.final ParameterSpecparameterOf(TypeName type, CharSequence name, Modifier... modifiers) Creates a newParameterSpecinstance for the given arguments.final List<ParameterSpec> parametersOf(Method method) Retrieves the parameters from the given method.final List<ParameterSpec> parametersOf(ExecutableElement method) Retrieves th e parameters from the given method.final TypeSpec.BuilderrecordBuilder(CharSequence name) Creates a builder for a record.final TypeSpec.BuilderrecordBuilder(ClassName className) Creates a builder for a record.final voidsetMaxFields(int value) Sets the maximum number of fields for a class.final voidsetMaxMethods(int value) Sets the maximum number of methods for a class.final CodeBlockstatementOf(String format, Object... args) Creates a newCodeBlockinstance from the given format and arguments, usingCodeBlock.Builder.addStatement(String, Object...).
-
Field Details
-
JAVADOC_TAG_INHERITDOC
The Javadoc tag for inherited documentation: "{@inheritDoc}".- See Also:
-
JAVADOC_TAG_VALUE
The Javadoc tag for a constant value: "{@value}".- See Also:
-
MSG_CannotOverrideFinalClass
Message: "Cannot override method on final class \'%s\'".- See Also:
-
MSG_CannotOverrideMethod
Message: "Cannot override method with modifier \'%s\'".- See Also:
-
m_AddDebugOutput
If set totrue, some debug information will be added to the output. -
m_Annotation_ClassVersion
The@ClassVersionannotation. -
m_Annotation_UtilityClass
The@UtilityClassannotation. -
m_CodeProcessor
The code processor associated with this composer instance. -
m_JavaDoc_InheritDoc
The Javadoc comment for an overriding method. -
m_Layout
The layout that is used to format the output. -
m_MaxFields
The maximum number of fields for a class; if this number is exceeded, an annotation@SuppressWarningswithSuppressableWarnings.CLASS_WITH_TOO_MANY_FIELDSwill be added to the class. -
m_MaxMethods
The maximum number of methods for a class; if this number is exceeded, an annotation@SuppressWarningswithSuppressableWarnings.CLASS_WITH_TOO_MANY_METHODSwill be added to the class. -
m_Method_Equals
A predefinedequals()method. -
m_Method_HashCode
A predefinedhashCode()method. -
m_Method_ToString
A predefinedtoString()method.
-
-
Constructor Details
-
JavaComposer
public JavaComposer()Creates a new instance ofJavaComposerthat uses the defaultLayout. -
JavaComposer
Creates a new instance ofJavaComposer.- Parameters:
layout- The layout that is used to format the output.
-
JavaComposer
Creates a new instance ofJavaComposerthat uses the defaultLayoutand adds some debug information to the output.- Parameters:
addDebugOutput-trueif debug information should be added,falseif not.
-
JavaComposer
Creates a new instance ofJavaComposer.- Parameters:
layout- The layout that is used to format the output.addDebugOutput-trueif debug information should be added,falseif not.
-
-
Method Details
-
addDebugOutput
Returns the flag that controls whether the output should be enhanced with some debug information.- Returns:
trueif the debug information should be added to the output,falseotherwise.
-
annotationBuilder
Creates a builder for an instance of an implementation for
AnnotationSpecfrom the givenClassNameinstance.This builder generates the code for the use of an annotation, while the builders returned from
annotationTypeBuilder(CharSequence)andannotationTypeBuilder(ClassName)will generate new annotation types.- Parameters:
type- The class name.- Returns:
- The new builder.
-
annotationBuilder
Creates a builder for an instance of an implementation for
AnnotationSpecfrom the givenClassinstance.This builder generates the code for the use of an annotation, while the builders returned from
annotationTypeBuilder(CharSequence)andannotationTypeBuilder(ClassName)will generate new annotation types.- Parameters:
type- The class.- Returns:
- The new builder.
-
annotationTypeBuilder
Creates a builder for an annotation.
This method creates a builder for a new annotation, while
annotationBuilder(ClassName)andannotationBuilder(Class)will create the builder for the use of an annotation.- Parameters:
className- The name of the annotation.- Returns:
- The builder.
-
annotationTypeBuilder
Creates a builder for an annotation.
This method creates a builder for a new annotation, while
annotationBuilder(ClassName)andannotationBuilder(Class)will create the builder for the use of an annotation.- Parameters:
name- The name of the annotation.- Returns:
- The builder.
-
anonymousClassBuilder
Creates a builder for an anonymous class.- Parameters:
typeArguments- The type arguments.- Returns:
- The builder.
-
anonymousClassBuilder
Creates a builder for an anonymous class. This method is the shortcut for
CodeBlock codeBlock = codeBlockBuilder() .add( format, args ) .build(); TypeSpec.Builder builder = anonymousClassBuilder( codeBlock );- Parameters:
format- The format for the code; may be empty.args- The arguments for the code.- Returns:
- The builder.
- See Also:
-
classBuilder
Creates a builder for a regular class.- Parameters:
className- The name of the class.- Returns:
- The builder.
-
classBuilder
Creates a builder for a regular class.- Parameters:
name- The name of the class.- Returns:
- The builder.
-
codeBlockBuilder
Creates a builder for an instance ofCodeBlock.- Returns:
- The new builder.
-
codeBlockOf
Creates a newCodeBlockinstance from the given format and arguments.- Note:
-
- No debug info will be added.
- Parameters:
format- The format.args- The arguments.- Returns:
- The new code block.
-
constructorBuilder
Creates a builder that builds an instance ofMethodSpecfor a constructor.- Returns:
- The builder.
-
createAnnotation
Creates an instance ofAnnotationSpecfrom the givenAnnotationinstance.- Parameters:
annotation- The annotation.- Returns:
- The new instance of
AnnotationSpec.
-
createAnnotation
Creates an instance ofAnnotationSpecfrom the givenAnnotationinstance.- Parameters:
annotation- The annotation.includeDefaultValues-trueto include the annotation's default values,falseto ignore them.- Returns:
- The new instance of
AnnotationSpec.
-
createAnnotation
Creates an instance ofAnnotationSpecfrom the givenAnnotationMirrorinstance.- Parameters:
annotation- The annotation mirror.- Returns:
- The new instance of
AnnotationSpec.
-
createClassVersionAnnotation
Returns a@ClassVersionannotation with a default text forClassVersion.sourceVersion().- Returns:
- The annotation.
- See Also:
-
createClassVersionAnnotation
Returns a@ClassVersionannotation with the text forClassVersion.sourceVersion().- Parameters:
sourceVersion- The text.- Returns:
- The annotation.
- See Also:
-
createComment4Constant
Creates the comment for a constant.- Parameters:
comment- The already existing comment; can benull.- Returns:
- The comment for the new constant.
-
createConstant
Creates a String constant.
A constant is an initialised
public static finalfield.- Parameters:
name- The name of the constant.value- The value of the constant.comment- The description for the constant.- Returns:
- The field spec for the new constant.
-
createConstant
private final FieldSpec createConstant(CharSequence name, TypeName type, Number value, CodeBlock comment) Creates a numerical constant.
A constant is an initialised
public static finalfield.- Parameters:
name- The name of the constant.type- The type of the constant.value- The value of the constant.comment- The description for the constant.- Returns:
- The field spec for the new constant.
-
createConstant
Creates an integer constant.
A constant is an initialised
public static finalfield.- Parameters:
name- The name of the constant.value- The value of the constant.comment- The description for the constant.- Returns:
- The field spec for the new constant.
-
createConstant
public final FieldSpec createConstant(CharSequence name, Type type, CodeBlock value, CodeBlock comment) Creates a constant.
A constant is an initialised
public static finalfield.- Parameters:
name- The name of the constant.type- The type of the constant.value- The value of the constant.comment- The description for the constant.- Returns:
- The field spec for the new constant.
-
createConstant
public final FieldSpec createConstant(CharSequence name, TypeName type, CodeBlock value, CodeBlock comment) Creates a constant.
A constant is an initialisedpublic final staticfield.- Parameters:
name- The name of the constant.type- The type of the constant.value- The value of the constant.comment- The description for the constant.- Returns:
- The field spec for the new constant.
-
createEqualsBuilder
Returns a builder for an implementation of the method
Object.equals(Object)that just needs the method body for completion.The argument has the name "
o".- Returns:
- The method builder.
-
createEqualsMethod
Returns a
MethodSpecinstance for an implementation of the methodObject.equals(Object).The argument has the name "
o".- Parameters:
body- The method body.- Returns:
- The method specification.
-
createHashCodeBuilder
Returns a builder for an implementation of the methodObject.hashCode()that just needs the method body for completion.- Returns:
- The method builder.
-
createHashCodeMethod
Returns aMethodSpecinstance for an implementation of the methodObject.hashCode().- Parameters:
body- The method body.- Returns:
- The method specification.
-
createHashCodeMethod
Returns a
MethodSpecinstance for an implementation of the methodObject.hashCode().The created method uses
Objects.hash(Object...)for the implementation.- Parameters:
fields- The fields that are used for the calculation of the hash code value.- Returns:
- The method specification.
-
createHashCodeMethod
Returns a
MethodSpecinstance for an implementation of the methodObject.hashCode().The created method uses
Objects.hash(Object...)for the implementation.- Parameters:
fields- The fields that are used for the calculation of the hash code value.- Returns:
- The method specification.
-
createInheritDocComment
Returns a code block with a comment for overriding methods:/** * {@inheritDoc} */- Returns:
- The comment.
-
createMethod
Creates a
MethodSpecfor the givenExecutableElement.This method copies visibility modifiers, type parameters, return type, name, parameters, and
throwsdeclarations, but not the body (if any).- Note:
-
- The annotations will not be copied and must be added separately.
- Parameters:
method- The method to override.- Returns:
- The builder.
-
createParameter
Creates an instance ofParameterSpecfrom the givenVariableElementinstance.- Parameters:
element- The variable element.- Returns:
- The parameter spec.
-
createParameter
Creates an instance ofParameterSpecfrom the givenParameterinstance.- Parameters:
parameter- The variable element.- Returns:
- The parameter spec.
-
createReturnStatement
Creates a return statement with a comment, usingretValueas the name for the return variable.- Returns:
- The return statement.
-
createReturnStatement
Creates a return statement with a comment.- Parameters:
name- The name of the variable that is returned.- Returns:
- The return statement.
-
createStaticClassBuilder
Returns a builder for a static class.
A static class is a
finalclass with aprivateconstructor that has onlystaticmembers; no instances are allowed for such a class, so none of thestaticmethods are factories for that class.This would be the skeleton for the new static class:
<package what.ever.package.was.chosen>; import org.tquadrat.foundation.annotation.ClassVersion; import org.tquadrat.foundation.annotation.UtilityClass; import org.tquadrat.foundation.exception.PrivateConstructorForStaticClassCalledError; @UtilityClass @ClassVersion(sourceVersion = "Generated with JavaComposer", isGenerated = true) public final class StaticClass { /** * No instance allowed for this class! */ private StaticClass() { throw new PrivateConstructorForStaticClassCalledError( StaticClass.class ); } }- Parameters:
className- The name of the new class.- Returns:
- The builder.
- See Also:
-
createSuppressWarningsAnnotation
public final Optional<AnnotationSpec> createSuppressWarningsAnnotation(Collection<SuppressableWarnings> warnings) Returns a
@SuppressWarningsannotation with the given values. No annotation will be created if the given collection is empty.- Parameters:
warnings- The warnings to suppress.- Returns:
- An instance of
Optionalthat holds the new annotation.
-
createSuppressWarningsAnnotation
public final Optional<AnnotationSpec> createSuppressWarningsAnnotation(SuppressableWarnings... warnings) Returns a
@SuppressWarningsannotation with the given values. No annotation will be created if the given collection is empty.- Parameters:
warnings- The warnings to suppress.- Returns:
- An instance of
Optionalthat holds the new annotation.
-
createToStringBuilder
Returns a builder for an implementation of the methodObject.toString()that just needs the method body for completion.- Returns:
- The method builder.
-
createToStringMethod
Returns aMethodSpecinstance for an implementation of the methodObject.toString().- Parameters:
body- The method body.- Returns:
- The method specification.
-
createUtilityClassAnnotation
Returns a@UtilityClassannotation.- Returns:
- The annotation.
- See Also:
-
emptyCodeBlock
Returns an emptyCodeBlock.- Returns:
- An empty code block.
-
enumBuilder
Creates a builder for anenumtype.- Parameters:
className- The name of the class.- Returns:
- The builder.
-
enumBuilder
Creates a builder for anenumtype.- Parameters:
name- The name of the class.- Returns:
- The builder.
-
equals
-
fieldBuilder
Creates a builder for an instance ofFieldSpecfrom the given type, name and modifiers.- Parameters:
type- The type of theFieldSpecto build.name- The name for the new field.modifiers- The modifiers.- Returns:
- The new builder.
-
fieldBuilder
public final FieldSpec.Builder fieldBuilder(TypeName type, CharSequence name, Modifier... modifiers) Creates a builder for an instance ofFieldSpecfrom the given type, name and modifiers.- Parameters:
type- The type of theFieldSpecto build.name- The name for the new field.modifiers- The modifiers.- Returns:
- The new builder.
-
fieldBuilder
public final FieldSpec.Builder fieldBuilder(TypeSpec type, CharSequence name, Modifier... modifiers) Creates a builder for an instance ofFieldSpecfrom the given type, name and modifiers.- Parameters:
type- The type of theFieldSpecto build.name- The name for the new field.modifiers- The modifiers.- Returns:
- The new builder.
-
getCodeProcessor
Provides access to the code processor for this composer instance.- Returns:
- The code processor.
-
getLayout
Returns the layout that is used to format the output.- Returns:
- The layout.
-
getMaxFields
Returns the maximum number of fields for a class. If this number is exceeded, an annotation
@SuppressWarningswithSuppressableWarnings.CLASS_WITH_TOO_MANY_FIELDSwill be added to the class.- Returns:
- The maximum number of fields.
-
getMaxMethods
Returns the maximum number of methods for a class. If this number is exceeded, an annotation
@SuppressWarningswithSuppressableWarnings.CLASS_WITH_TOO_MANY_METHODSwill be added to the class.- Returns:
- The maximum number of fields.
-
hashCode
-
interfaceBuilder
Creates a builder for an interface.- Parameters:
className- The name of the class.- Returns:
- The builder.
-
interfaceBuilder
Creates a builder for an interface.- Parameters:
name- The name of the class.- Returns:
- The builder.
-
javaFileBuilder
Creates a builder for a new instance ofJavaFilefrom the given package name and class definition.- Parameters:
packageName- The package name; may be empty for the default package.typeSpec- The class definition.- Returns:
- The builder.
-
lambdaBuilder
Creates a builder for an instance ofLambdaSpec.- Returns:
- The new builder.
-
methodBuilder
Returns a builder for a regular method.- Parameters:
name- The name for the method.- Returns:
- The builder.
-
overridingMethodBuilder
Returns a new method builder for a method that overrides the given method.
This new builder will copy visibility modifiers, type parameters, return type, name, parameters, and
throwsdeclarations. AnOverrideannotation will be added.- Note:
-
- In JavaPoet 1.2 through 1.7 this method retained annotations from the method and parameters of the overridden method. Since JavaPoet 1.8 and in JavaComposer annotations must be added separately.
- Parameters:
method- The method to override.- Returns:
- The builder.
-
overridingMethodBuilder
public final MethodSpec.Builder overridingMethodBuilder(ExecutableElement method, DeclaredType enclosing, Types typeUtils) Returns a new method builder that overrides the given method as a member of of the given enclosing class. This will resolve type parameters: for example overriding
Comparable.compareTo(T)in a type that implementsComparable<Movie>, theTparameter will be resolved toMovie.This will copy its visibility modifiers, type parameters, return type, name, parameters, and
throwsdeclarations. AnOverrideannotation will be added.- Note:
-
- In JavaPoet 1.2 through 1.7 this method retained annotations from the method and parameters of the overridden method. Since JavaPoet 1.8 and in JavaComposer annotations must be added separately.
- Parameters:
method- The method to override.enclosing- The enclosing class for the method.typeUtils- An implementation of some utility methods for operating on types, as provided by the processing environment of an annotation processor.- Returns:
- The builder.
-
overridingMethodBuilder
Returns a new method builder for a method that overrides the given method.
This new builder will copy visibility modifiers, type parameters, return type, name, parameters, and
throwsdeclarations. AnOverrideannotation will be added, but any other annotation will be omitted; this is consistent with the behaviour ofoverridingMethodBuilder(ExecutableElement)andoverridingMethodBuilder(ExecutableElement, DeclaredType, Types).- Parameters:
method- The method to override.- Returns:
- The builder.
-
parameterBuilder
public final ParameterSpec.Builder parameterBuilder(Type type, CharSequence name, Modifier... modifiers) Creates a builder for a newParameterSpecinstance.- Parameters:
type- The type of the new parameter.name- The name of the new parameter.modifiers- The modifiers for the new parameter.- Returns:
- The builder.
-
parameterBuilder
public final ParameterSpec.Builder parameterBuilder(TypeName type, CharSequence name, Modifier... modifiers) Creates a builder for a newParameterSpecinstance.- Parameters:
type- The type of the new parameter.name- The name of the new parameter.modifiers- The modifiers for the new parameter.- Returns:
- The builder.
-
parameterOf
Creates a newParameterSpecinstance for the given arguments.- Parameters:
type- The type of the new parameter.name- The name of the new parameter.modifiers- The modifiers for the new parameter.- Returns:
- The parameter specification.
-
parameterOf
Creates a newParameterSpecinstance for the given arguments.- Parameters:
type- The type of the new parameter.name- The name of the new parameter.modifiers- The modifiers for the new parameter.- Returns:
- The parameter specification.
-
parametersOf
Retrieves th e parameters from the given method.- Parameters:
method- The method.- Returns:
- The parameters of the given method; the returned list can be
empty, but it will not be
null.
-
parametersOf
Retrieves the parameters from the given method.- Parameters:
method- The method.- Returns:
- The parameters of the given method; the returned list can be
empty, but it will not be
null.
-
recordBuilder
Creates a builder for a record.- Parameters:
className- The name of the record type.- Returns:
- The builder.
-
recordBuilder
Creates a builder for a record.- Parameters:
name- The name of the record type.- Returns:
- The builder.
-
setMaxFields
Sets the maximum number of fields for a class. If this number is exceeded, an annotation
@SuppressWarningswithSuppressableWarnings.CLASS_WITH_TOO_MANY_FIELDSwill be added to the class.Setting the value to 0 or a negative value will disable this feature.
- Parameters:
value- The value.
-
setMaxMethods
Sets the maximum number of methods for a class. If this number is exceeded, an annotation
@SuppressWarningswithSuppressableWarnings.CLASS_WITH_TOO_MANY_METHODSwill be added to the class.Setting the value to 0 or a negative value will disable this feature.
- Parameters:
value- The value.
-
statementOf
Creates a newCodeBlockinstance from the given format and arguments, usingCodeBlock.Builder.addStatement(String, Object...).- Note:
-
- No debug info will be added.
- Parameters:
format- The format.args- The arguments.- Returns:
- The new code block.
-
