public class HasBuilderGenerator extends Object
HasBuilder
.Modifier and Type | Field and Description |
---|---|
protected Class<A> |
annotationType |
protected Elements |
elements |
protected Messager |
messager |
protected Types |
types |
protected TypeUtils |
typeUtils |
Constructor and Description |
---|
HasBuilderGenerator(Elements elements,
Types types,
Messager messager) |
Modifier and Type | Method and Description |
---|---|
protected com.squareup.javapoet.MethodSpec.Builder |
addBuilderMethodReturn(TypeElement builderType,
com.squareup.javapoet.MethodSpec.Builder builder)
Adds the return statement for the builder method.
|
protected void |
addSuppressWarnings(com.squareup.javapoet.MethodSpec.Builder builder) |
protected void |
copyDeprecatedAnnotation(PropertyGenModel property,
com.squareup.javapoet.MethodSpec.Builder methodSpecBuilder) |
protected void |
copyDeprecatedAnnotation(PropertyGenModel property,
com.squareup.javapoet.TypeSpec.Builder typeSpecBuilder) |
protected void |
copyJsonAnnotation(PropertyGenModel property,
com.squareup.javapoet.MethodSpec.Builder builder) |
protected List<com.squareup.javapoet.MethodSpec> |
createBuilderMethods(TypeElement returnType,
PropertyGenModel property)
Creates a builder method for the given getter method.
|
protected com.squareup.javapoet.MethodSpec |
createBuildMethod(com.squareup.javapoet.TypeName returnType,
com.squareup.javapoet.TypeName implType,
List<ExecutableElement> propertyMethods) |
protected com.squareup.javapoet.MethodSpec |
createConstructor(List<PropertyGenModel> properties) |
protected com.squareup.javapoet.MethodSpec |
createConstructor(List<PropertyGenModel> properties,
List<Modifier> modifiers) |
protected com.squareup.javapoet.MethodSpec |
createCopyFactoryMethod(TypeElement typeElement,
com.squareup.javapoet.ClassName returnType,
List<ExecutableElement> propertyMethods) |
protected com.squareup.javapoet.MethodSpec |
createCopyFactoryMethod(TypeElement typeElement,
com.squareup.javapoet.ClassName returnType,
List<ExecutableElement> propertyMethods,
List<PropertyGenModel> propertyGenModels) |
protected com.squareup.javapoet.MethodSpec |
createDefaultConstructor(List<Modifier> modifiers) |
protected com.squareup.javapoet.MethodSpec |
createFactoryMethod(FactoryMethod factoryMethod,
List<PropertyGenModel> properties,
com.squareup.javapoet.ClassName returnType) |
protected com.squareup.javapoet.MethodSpec |
createFactoryMethod(List<PropertyGenModel> properties,
com.squareup.javapoet.ClassName returnType,
List<String> parameterNames,
String methodName,
boolean useLowercaseBooleans) |
protected List<com.squareup.javapoet.MethodSpec> |
createFactoryMethods(FactoryMethod[] factoryMethods,
List<PropertyGenModel> properties,
com.squareup.javapoet.ClassName returnType) |
protected com.squareup.javapoet.FieldSpec |
createField(PropertyGenModel property) |
protected com.squareup.javapoet.FieldSpec |
createField(PropertyGenModel property,
List<Modifier> modifiers) |
protected com.squareup.javapoet.FieldSpec |
createField(PropertyGenModel property,
Modifier modifier) |
protected com.squareup.javapoet.FieldSpec.Builder |
createFieldBuilder(PropertyGenModel property,
Modifier modifier) |
protected com.squareup.javapoet.MethodSpec |
createGetMethod(PropertyGenModel property) |
protected com.squareup.javapoet.AnnotationSpec |
createJsonPropertyAnnotation(String jsonName) |
protected com.squareup.javapoet.ParameterSpec |
createParameter(PropertyGenModel property,
boolean useLowercaseBooleans,
boolean copyNullable) |
protected com.squareup.javapoet.ParameterSpec |
createParameter(PropertyGenModel property,
com.squareup.javapoet.TypeName parameterType,
boolean copyNullable) |
protected List<com.squareup.javapoet.ParameterSpec> |
createParameters(List<PropertyGenModel> properties,
boolean useLowercaseBooleans,
boolean copyNullable) |
protected String |
escapeJavaKeyword(String name)
Escapes the given name with an
"_" if it's a java keyword (e.g. |
com.squareup.javapoet.JavaFile |
generate(T annotatedElement)
Generates code for the given annotated type element.
|
com.squareup.javapoet.TypeSpec |
generateType(TypeElement builderType) |
protected List<ExecutableElement> |
getAllPropertyMethodsSorted(TypeElement typeElement)
Returns all property methods - including inherited methods - sorted by their property name.
|
protected A |
getAnnotationValue(TypeElement typeElement)
Returns the annotation value from the given type element used by this generator.
|
protected String |
getPackageName(Element element) |
protected List<PropertyGenModel> |
getPropertyGenModels(List<ExecutableElement> propertyMethods) |
protected List<ExecutableElement> |
getPropertyMethodsSorted(TypeElement typeElement)
Returns property methods - not included inherited methods - sorted by their property name.
|
protected final Class<A extends Annotation> annotationType
protected final Elements elements
protected final Types types
protected final Messager messager
protected final TypeUtils typeUtils
public com.squareup.javapoet.TypeSpec generateType(TypeElement builderType)
protected com.squareup.javapoet.MethodSpec.Builder addBuilderMethodReturn(TypeElement builderType, com.squareup.javapoet.MethodSpec.Builder builder)
builderType
- the builder typebuilder
- the builder to add the return statementprotected A getAnnotationValue(TypeElement typeElement)
typeElement
- protected com.squareup.javapoet.MethodSpec createBuildMethod(com.squareup.javapoet.TypeName returnType, com.squareup.javapoet.TypeName implType, List<ExecutableElement> propertyMethods)
protected List<com.squareup.javapoet.MethodSpec> createBuilderMethods(TypeElement returnType, PropertyGenModel property)
property
- the getter methodreturnType
- the returned type from the builderpublic final com.squareup.javapoet.JavaFile generate(T annotatedElement)
annotatedElement
- the annotated type elementprotected com.squareup.javapoet.FieldSpec createField(PropertyGenModel property)
protected com.squareup.javapoet.FieldSpec createField(PropertyGenModel property, Modifier modifier)
protected com.squareup.javapoet.FieldSpec.Builder createFieldBuilder(PropertyGenModel property, Modifier modifier)
protected String escapeJavaKeyword(String name)
"_"
if it's a java keyword (e.g. default
.name
- the name to escapeprotected List<ExecutableElement> getAllPropertyMethodsSorted(TypeElement typeElement)
typeElement
- the type elementPropertyGenModel.getPropertyName(ExecutableElement)
protected List<ExecutableElement> getPropertyMethodsSorted(TypeElement typeElement)
typeElement
- the type elementPropertyGenModel.getPropertyName(ExecutableElement)
protected List<PropertyGenModel> getPropertyGenModels(List<ExecutableElement> propertyMethods)
protected com.squareup.javapoet.MethodSpec createGetMethod(PropertyGenModel property)
protected void copyJsonAnnotation(PropertyGenModel property, com.squareup.javapoet.MethodSpec.Builder builder)
protected void addSuppressWarnings(com.squareup.javapoet.MethodSpec.Builder builder)
protected void copyDeprecatedAnnotation(PropertyGenModel property, com.squareup.javapoet.TypeSpec.Builder typeSpecBuilder)
protected void copyDeprecatedAnnotation(PropertyGenModel property, com.squareup.javapoet.MethodSpec.Builder methodSpecBuilder)
protected com.squareup.javapoet.ParameterSpec createParameter(PropertyGenModel property, boolean useLowercaseBooleans, boolean copyNullable)
property
- the property to generate the parameteruseLowercaseBooleans
- FactoryMethod.useLowercaseBooleans()
copyNullable
- if true, an existing Nullable
annotation on the model will be copied to the parameterprotected com.squareup.javapoet.ParameterSpec createParameter(PropertyGenModel property, com.squareup.javapoet.TypeName parameterType, boolean copyNullable)
protected com.squareup.javapoet.FieldSpec createField(PropertyGenModel property, List<Modifier> modifiers)
protected com.squareup.javapoet.MethodSpec createDefaultConstructor(List<Modifier> modifiers)
protected com.squareup.javapoet.MethodSpec createConstructor(List<PropertyGenModel> properties, List<Modifier> modifiers)
protected List<com.squareup.javapoet.ParameterSpec> createParameters(List<PropertyGenModel> properties, boolean useLowercaseBooleans, boolean copyNullable)
protected com.squareup.javapoet.MethodSpec createConstructor(List<PropertyGenModel> properties)
protected com.squareup.javapoet.AnnotationSpec createJsonPropertyAnnotation(String jsonName)
protected List<com.squareup.javapoet.MethodSpec> createFactoryMethods(FactoryMethod[] factoryMethods, List<PropertyGenModel> properties, com.squareup.javapoet.ClassName returnType)
protected com.squareup.javapoet.MethodSpec createFactoryMethod(FactoryMethod factoryMethod, List<PropertyGenModel> properties, com.squareup.javapoet.ClassName returnType)
protected com.squareup.javapoet.MethodSpec createFactoryMethod(List<PropertyGenModel> properties, com.squareup.javapoet.ClassName returnType, List<String> parameterNames, String methodName, boolean useLowercaseBooleans)
protected com.squareup.javapoet.MethodSpec createCopyFactoryMethod(TypeElement typeElement, com.squareup.javapoet.ClassName returnType, List<ExecutableElement> propertyMethods)
protected com.squareup.javapoet.MethodSpec createCopyFactoryMethod(TypeElement typeElement, com.squareup.javapoet.ClassName returnType, List<ExecutableElement> propertyMethods, List<PropertyGenModel> propertyGenModels)