Top Description Inners Fields Constructors Methods
com.squareup.javapoet

public final Class TypeSpec

extends Object
Class Inheritance
Imports
java.io.IOException, java.lang.reflect.ParameterizedType, .Type, java.util.ArrayList, .Arrays, .Collections, .EnumSet, .HashSet, .Iterator, .LinkedHashMap, .LinkedHashSet, .List, .Locale, .Map, .Set, javax.lang.model.SourceVersion, javax.lang.model.element.Element, .Modifier, .TypeElement, javax.lang.model.type.DeclaredType, .NoType, .TypeMirror, javax.lang.model.util.ElementFilter

A generated class, interface, or enum declaration.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static enum

Field Summary

Modifier and TypeField and Description
public final Set<String>
public final List<AnnotationSpec>
public final CodeBlock
public final Map<String, TypeSpec>
public final List<FieldSpec>
public final CodeBlock
public final CodeBlock
public final TypeSpec.Kind
public final List<MethodSpec>
public final Set<Modifier>
public final String
pack-priv final Set<String>
public final List<Element>
public final CodeBlock
public final TypeName
public final List<TypeName>
public final List<TypeSpec>
public final List<TypeVariableName>

Constructor Summary

AccessConstructor and Description
private
private
TypeSpec(TypeSpec type)

Creates a dummy type spec for type-resolution only (in CodeWriter) while emitting the type declaration but before entering the type body.

Method Summary

Modifier and TypeMethod and Description
public static TypeSpec.Builder
public static TypeSpec.Builder
public static TypeSpec.Builder
anonymousClassBuilder(String typeArgumentsFormat, Object... args)

public static TypeSpec.Builder
public static TypeSpec.Builder
public static TypeSpec.Builder
pack-priv void
emit(CodeWriter codeWriter, String enumName, Set<Modifier> implicitModifiers)

public static TypeSpec.Builder
public static TypeSpec.Builder
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean
public static TypeSpec.Builder
public static TypeSpec.Builder
public TypeSpec.Builder
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

alwaysQualifiedNamesback to summary
public final Set<String> alwaysQualifiedNames
annotationsback to summary
public final List<AnnotationSpec> annotations
anonymousTypeArgumentsback to summary
public final CodeBlock anonymousTypeArguments
enumConstantsback to summary
public final Map<String, TypeSpec> enumConstants
fieldSpecsback to summary
public final List<FieldSpec> fieldSpecs
initializerBlockback to summary
public final CodeBlock initializerBlock
javadocback to summary
public final CodeBlock javadoc
kindback to summary
public final TypeSpec.Kind kind
methodSpecsback to summary
public final List<MethodSpec> methodSpecs
modifiersback to summary
public final Set<Modifier> modifiers
nameback to summary
public final String name
nestedTypesSimpleNamesback to summary
pack-priv final Set<String> nestedTypesSimpleNames
originatingElementsback to summary
public final List<Element> originatingElements
staticBlockback to summary
public final CodeBlock staticBlock
superclassback to summary
public final TypeName superclass
superinterfacesback to summary
public final List<TypeName> superinterfaces
typeSpecsback to summary
public final List<TypeSpec> typeSpecs
typeVariablesback to summary
public final List<TypeVariableName> typeVariables

Constructor Detail

TypeSpecback to summary
private TypeSpec(TypeSpec.Builder builder)
TypeSpecback to summary
private TypeSpec(TypeSpec type)

Creates a dummy type spec for type-resolution only (in CodeWriter) while emitting the type declaration but before entering the type body.

Method Detail

annotationBuilderback to summary
public static TypeSpec.Builder annotationBuilder(String name)
annotationBuilderback to summary
public static TypeSpec.Builder annotationBuilder(ClassName className)
anonymousClassBuilderback to summary
public static TypeSpec.Builder anonymousClassBuilder(String typeArgumentsFormat, Object... args)
anonymousClassBuilderback to summary
public static TypeSpec.Builder anonymousClassBuilder(CodeBlock typeArguments)
classBuilderback to summary
public static TypeSpec.Builder classBuilder(String name)
classBuilderback to summary
public static TypeSpec.Builder classBuilder(ClassName className)
emitback to summary
pack-priv void emit(CodeWriter codeWriter, String enumName, Set<Modifier> implicitModifiers) throws IOException
enumBuilderback to summary
public static TypeSpec.Builder enumBuilder(String name)
enumBuilderback to summary
public static TypeSpec.Builder enumBuilder(ClassName className)
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
hasModifierback to summary
public boolean hasModifier(Modifier modifier)
interfaceBuilderback to summary
public static TypeSpec.Builder interfaceBuilder(String name)
interfaceBuilderback to summary
public static TypeSpec.Builder interfaceBuilder(ClassName className)
toBuilderback to summary
public TypeSpec.Builder toBuilder()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.squareup.javapoet back to summary

public final Class TypeSpec.Builder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public final Set<String>
public final List<AnnotationSpec>
private final CodeBlock
public final Map<String, TypeSpec>
public final List<FieldSpec>
private final CodeBlock.Builder
private final CodeBlock.Builder
private final TypeSpec.Kind
public final List<MethodSpec>
public final List<Modifier>
private final String
public final List<Element>
private final CodeBlock.Builder
private TypeName
public final List<TypeName>
public final List<TypeSpec>
public final List<TypeVariableName>

Constructor Summary

AccessConstructor and Description
private
Builder(TypeSpec.Kind kind, String name, CodeBlock anonymousTypeArguments)

Method Summary

Modifier and TypeMethod and Description
public TypeSpec.Builder
addAnnotation(AnnotationSpec annotationSpec)

public TypeSpec.Builder
public TypeSpec.Builder
addAnnotation(Class<?> annotation)

public TypeSpec.Builder
public TypeSpec.Builder
public TypeSpec.Builder
public TypeSpec.Builder
addField(FieldSpec fieldSpec)

public TypeSpec.Builder
addField(TypeName type, String name, Modifier... modifiers)

public TypeSpec.Builder
addField(Type type, String name, Modifier... modifiers)

public TypeSpec.Builder
public TypeSpec.Builder
public TypeSpec.Builder
addJavadoc(String format, Object... args)

public TypeSpec.Builder
public TypeSpec.Builder
addMethod(MethodSpec methodSpec)

public TypeSpec.Builder
public TypeSpec.Builder
addModifiers(Modifier... modifiers)

public TypeSpec.Builder
addOriginatingElement(Element originatingElement)

public TypeSpec.Builder
public TypeSpec.Builder
addSuperinterface(TypeName superinterface)

public TypeSpec.Builder
addSuperinterface(Type superinterface)

public TypeSpec.Builder
addSuperinterface(Type superinterface, boolean avoidNestedTypeNameClashes)

public TypeSpec.Builder
addSuperinterface(TypeMirror superinterface)

public TypeSpec.Builder
addSuperinterface(TypeMirror superinterface, boolean avoidNestedTypeNameClashes)

public TypeSpec.Builder
addSuperinterfaces(Iterable<? extends TypeName> superinterfaces)

public TypeSpec.Builder
addType(TypeSpec typeSpec)

public TypeSpec.Builder
public TypeSpec.Builder
public TypeSpec.Builder
public TypeSpec.Builder
alwaysQualify(String... simpleNames)

public TypeSpec.Builder

Returns:

this builder instance.
avoidClashesWithNestedClasses
(TypeElement
the TypeElement with nested types to avoid clashes with.
typeElement
)

Call this to always fully qualify any types that would conflict with possibly nested types of this typeElement.

public TypeSpec.Builder

Returns:

this builder instance.
avoidClashesWithNestedClasses
(Class<?>
the Class with nested types to avoid clashes with.
clazz
)

Call this to always fully qualify any types that would conflict with possibly nested types of this typeElement.

public TypeSpec
private Class<?>
public TypeSpec.Builder
superclass(TypeName superclass)

public TypeSpec.Builder
superclass(Type superclass)

public TypeSpec.Builder
superclass(Type superclass, boolean avoidNestedTypeNameClashes)

public TypeSpec.Builder
superclass(TypeMirror superclass)

public TypeSpec.Builder
superclass(TypeMirror superclass, boolean avoidNestedTypeNameClashes)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

alwaysQualifiedNamesback to summary
public final Set<String> alwaysQualifiedNames
annotationsback to summary
public final List<AnnotationSpec> annotations
anonymousTypeArgumentsback to summary
private final CodeBlock anonymousTypeArguments
enumConstantsback to summary
public final Map<String, TypeSpec> enumConstants
fieldSpecsback to summary
public final List<FieldSpec> fieldSpecs
initializerBlockback to summary
private final CodeBlock.Builder initializerBlock
javadocback to summary
private final CodeBlock.Builder javadoc
kindback to summary
private final TypeSpec.Kind kind
methodSpecsback to summary
public final List<MethodSpec> methodSpecs
modifiersback to summary
public final List<Modifier> modifiers
nameback to summary
private final String name
originatingElementsback to summary
public final List<Element> originatingElements
staticBlockback to summary
private final CodeBlock.Builder staticBlock
superclassback to summary
private TypeName superclass
superinterfacesback to summary
public final List<TypeName> superinterfaces
typeSpecsback to summary
public final List<TypeSpec> typeSpecs
typeVariablesback to summary
public final List<TypeVariableName> typeVariables

Constructor Detail

Builderback to summary
private Builder(TypeSpec.Kind kind, String name, CodeBlock anonymousTypeArguments)

Method Detail

addAnnotationback to summary
public TypeSpec.Builder addAnnotation(AnnotationSpec annotationSpec)
addAnnotationback to summary
public TypeSpec.Builder addAnnotation(ClassName annotation)
addAnnotationback to summary
public TypeSpec.Builder addAnnotation(Class<?> annotation)
addAnnotationsback to summary
public TypeSpec.Builder addAnnotations(Iterable<AnnotationSpec> annotationSpecs)
addEnumConstantback to summary
public TypeSpec.Builder addEnumConstant(String name)
addEnumConstantback to summary
public TypeSpec.Builder addEnumConstant(String name, TypeSpec typeSpec)
addFieldback to summary
public TypeSpec.Builder addField(FieldSpec fieldSpec)
addFieldback to summary
public TypeSpec.Builder addField(TypeName type, String name, Modifier... modifiers)
addFieldback to summary
public TypeSpec.Builder addField(Type type, String name, Modifier... modifiers)
addFieldsback to summary
public TypeSpec.Builder addFields(Iterable<FieldSpec> fieldSpecs)
addInitializerBlockback to summary
public TypeSpec.Builder addInitializerBlock(CodeBlock block)
addJavadocback to summary
public TypeSpec.Builder addJavadoc(String format, Object... args)
addJavadocback to summary
public TypeSpec.Builder addJavadoc(CodeBlock block)
addMethodback to summary
public TypeSpec.Builder addMethod(MethodSpec methodSpec)
addMethodsback to summary
public TypeSpec.Builder addMethods(Iterable<MethodSpec> methodSpecs)
addModifiersback to summary
public TypeSpec.Builder addModifiers(Modifier... modifiers)
addOriginatingElementback to summary
public TypeSpec.Builder addOriginatingElement(Element originatingElement)
addStaticBlockback to summary
public TypeSpec.Builder addStaticBlock(CodeBlock block)
addSuperinterfaceback to summary
public TypeSpec.Builder addSuperinterface(TypeName superinterface)
addSuperinterfaceback to summary
public TypeSpec.Builder addSuperinterface(Type superinterface)
addSuperinterfaceback to summary
public TypeSpec.Builder addSuperinterface(Type superinterface, boolean avoidNestedTypeNameClashes)
addSuperinterfaceback to summary
public TypeSpec.Builder addSuperinterface(TypeMirror superinterface)
addSuperinterfaceback to summary
public TypeSpec.Builder addSuperinterface(TypeMirror superinterface, boolean avoidNestedTypeNameClashes)
addSuperinterfacesback to summary
public TypeSpec.Builder addSuperinterfaces(Iterable<? extends TypeName> superinterfaces)
addTypeback to summary
public TypeSpec.Builder addType(TypeSpec typeSpec)
addTypesback to summary
public TypeSpec.Builder addTypes(Iterable<TypeSpec> typeSpecs)
addTypeVariableback to summary
public TypeSpec.Builder addTypeVariable(TypeVariableName typeVariable)
addTypeVariablesback to summary
public TypeSpec.Builder addTypeVariables(Iterable<TypeVariableName> typeVariables)
alwaysQualifyback to summary
public TypeSpec.Builder alwaysQualify(String... simpleNames)
avoidClashesWithNestedClassesback to summary
public TypeSpec.Builder avoidClashesWithNestedClasses(TypeElement typeElement)

Call this to always fully qualify any types that would conflict with possibly nested types of this typeElement. For example - if the following type was passed in as the typeElement:


  class Foo {
    class NestedTypeA {

    }
    class NestedTypeB {

    }
  }

Then this would add "NestedTypeA" and "NestedTypeB" as names that should always be qualified via alwaysQualify(String...). This way they would avoid possible import conflicts when this JavaFile is written.

Parameters
typeElement:TypeElement

the TypeElement with nested types to avoid clashes with.

Returns:TypeSpec.Builder

this builder instance.

avoidClashesWithNestedClassesback to summary
public TypeSpec.Builder avoidClashesWithNestedClasses(Class<?> clazz)

Call this to always fully qualify any types that would conflict with possibly nested types of this typeElement. For example - if the following type was passed in as the typeElement:


  class Foo {
    class NestedTypeA {

    }
    class NestedTypeB {

    }
  }

Then this would add "NestedTypeA" and "NestedTypeB" as names that should always be qualified via alwaysQualify(String...). This way they would avoid possible import conflicts when this JavaFile is written.

Parameters
clazz:Class<?>

the Class with nested types to avoid clashes with.

Returns:TypeSpec.Builder

this builder instance.

buildback to summary
public TypeSpec build()
getRawTypeback to summary
private Class<?> getRawType(Type type)
superclassback to summary
public TypeSpec.Builder superclass(TypeName superclass)
superclassback to summary
public TypeSpec.Builder superclass(Type superclass)
superclassback to summary
public TypeSpec.Builder superclass(Type superclass, boolean avoidNestedTypeNameClashes)
superclassback to summary
public TypeSpec.Builder superclass(TypeMirror superclass)
superclassback to summary
public TypeSpec.Builder superclass(TypeMirror superclass, boolean avoidNestedTypeNameClashes)
com.squareup.javapoet back to summary

public final Enum TypeSpec.Kind

extends Enum<TypeSpec.Kind>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final TypeSpec.Kind
private final Set<Modifier>
public static final TypeSpec.Kind
public static final TypeSpec.Kind
private final Set<Modifier>
private final Set<Modifier>
private final Set<Modifier>
public static final TypeSpec.Kind

Constructor Summary

AccessConstructor and Description
private
Kind(Set<Modifier> implicitFieldModifiers, Set<Modifier> implicitMethodModifiers, Set<Modifier> implicitTypeModifiers, Set<Modifier> asMemberModifiers)

Method Summary

Modifier and TypeMethod and Description
public static TypeSpec.Kind
public static TypeSpec.Kind[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ANNOTATIONback to summary
public static final TypeSpec.Kind ANNOTATION
asMemberModifiersback to summary
private final Set<Modifier> asMemberModifiers
CLASSback to summary
public static final TypeSpec.Kind CLASS
ENUMback to summary
public static final TypeSpec.Kind ENUM
implicitFieldModifiersback to summary
private final Set<Modifier> implicitFieldModifiers
implicitMethodModifiersback to summary
private final Set<Modifier> implicitMethodModifiers
implicitTypeModifiersback to summary
private final Set<Modifier> implicitTypeModifiers
INTERFACEback to summary
public static final TypeSpec.Kind INTERFACE

Constructor Detail

Kindback to summary
private Kind(Set<Modifier> implicitFieldModifiers, Set<Modifier> implicitMethodModifiers, Set<Modifier> implicitTypeModifiers, Set<Modifier> asMemberModifiers)

Method Detail

valueOfback to summary
public static TypeSpec.Kind valueOf(String name)
valuesback to summary
public static TypeSpec.Kind[] values()