Class TypeSpec.Builder

  • Enclosing class:
    TypeSpec

    public static final class TypeSpec.Builder
    extends java.lang.Object
    • Field Detail

      • name

        private final java.lang.String name
      • anonymousTypeArguments

        private final CodeBlock anonymousTypeArguments
      • superclass

        private TypeName superclass
      • enumConstants

        public final java.util.Map<java.lang.String,​TypeSpec> enumConstants
      • annotations

        public final java.util.List<AnnotationSpec> annotations
      • modifiers

        public final java.util.List<javax.lang.model.element.Modifier> modifiers
      • superinterfaces

        public final java.util.List<TypeName> superinterfaces
      • fieldSpecs

        public final java.util.List<FieldSpec> fieldSpecs
      • methodSpecs

        public final java.util.List<MethodSpec> methodSpecs
      • typeSpecs

        public final java.util.List<TypeSpec> typeSpecs
      • originatingElements

        public final java.util.List<javax.lang.model.element.Element> originatingElements
      • alwaysQualifiedNames

        public final java.util.Set<java.lang.String> alwaysQualifiedNames
    • Constructor Detail

    • Method Detail

      • addJavadoc

        public TypeSpec.Builder addJavadoc​(java.lang.String format,
                                           java.lang.Object... args)
      • addAnnotation

        public TypeSpec.Builder addAnnotation​(java.lang.Class<?> annotation)
      • addModifiers

        public TypeSpec.Builder addModifiers​(javax.lang.model.element.Modifier... modifiers)
      • superclass

        public TypeSpec.Builder superclass​(java.lang.reflect.Type superclass)
      • superclass

        public TypeSpec.Builder superclass​(java.lang.reflect.Type superclass,
                                           boolean avoidNestedTypeNameClashes)
      • superclass

        public TypeSpec.Builder superclass​(javax.lang.model.type.TypeMirror superclass)
      • superclass

        public TypeSpec.Builder superclass​(javax.lang.model.type.TypeMirror superclass,
                                           boolean avoidNestedTypeNameClashes)
      • addSuperinterfaces

        public TypeSpec.Builder addSuperinterfaces​(java.lang.Iterable<? extends TypeName> superinterfaces)
      • addSuperinterface

        public TypeSpec.Builder addSuperinterface​(java.lang.reflect.Type superinterface)
      • addSuperinterface

        public TypeSpec.Builder addSuperinterface​(java.lang.reflect.Type superinterface,
                                                  boolean avoidNestedTypeNameClashes)
      • getRawType

        private java.lang.Class<?> getRawType​(java.lang.reflect.Type type)
      • addSuperinterface

        public TypeSpec.Builder addSuperinterface​(javax.lang.model.type.TypeMirror superinterface)
      • addSuperinterface

        public TypeSpec.Builder addSuperinterface​(javax.lang.model.type.TypeMirror superinterface,
                                                  boolean avoidNestedTypeNameClashes)
      • addEnumConstant

        public TypeSpec.Builder addEnumConstant​(java.lang.String name)
      • addField

        public TypeSpec.Builder addField​(TypeName type,
                                         java.lang.String name,
                                         javax.lang.model.element.Modifier... modifiers)
      • addField

        public TypeSpec.Builder addField​(java.lang.reflect.Type type,
                                         java.lang.String name,
                                         javax.lang.model.element.Modifier... modifiers)
      • addOriginatingElement

        public TypeSpec.Builder addOriginatingElement​(javax.lang.model.element.Element originatingElement)
      • alwaysQualify

        public TypeSpec.Builder alwaysQualify​(java.lang.String... simpleNames)
      • avoidClashesWithNestedClasses

        public TypeSpec.Builder avoidClashesWithNestedClasses​(javax.lang.model.element.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 - the TypeElement with nested types to avoid clashes with.
        Returns:
        this builder instance.
      • avoidClashesWithNestedClasses

        public TypeSpec.Builder avoidClashesWithNestedClasses​(java.lang.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 - the Class with nested types to avoid clashes with.
        Returns:
        this builder instance.