checkers.types
Class AnnotatedTypeMirror

java.lang.Object
  extended by checkers.types.AnnotatedTypeMirror
Direct Known Subclasses:
AnnotatedTypeMirror.AnnotatedArrayType, AnnotatedTypeMirror.AnnotatedDeclaredType, AnnotatedTypeMirror.AnnotatedExecutableType, AnnotatedTypeMirror.AnnotatedNoType, AnnotatedTypeMirror.AnnotatedNullType, AnnotatedTypeMirror.AnnotatedPrimitiveType, AnnotatedTypeMirror.AnnotatedTypeVariable, AnnotatedTypeMirror.AnnotatedWildcardType

public abstract class AnnotatedTypeMirror
extends Object

Represents an annotated type in the Java programming language. Types include primitive types, declared types (class and interface types), array types, type variables, and the null type. Also represented are wildcard type arguments, the signature and return types of executables, and pseudo-types corresponding to packages and to the keyword void.

Types should be compared using the utility methods in AnnotatedTypes. There is no guarantee that any particular type will always be represented by the same object.

To implement operations based on the class of an AnnotatedTypeMirror object, either use a visitor or use the result of the getKind() method.

Since:
1.6
See Also:
TypeMirror

Nested Class Summary
static class AnnotatedTypeMirror.AnnotatedArrayType
          Represents Array types in java.
static class AnnotatedTypeMirror.AnnotatedDeclaredType
          Represents a declared type (whether class or interface).
static class AnnotatedTypeMirror.AnnotatedExecutableType
          Represents a type of an executable.
static class AnnotatedTypeMirror.AnnotatedNoType
          A pseudo-type used where no actual type is appropriate.
static class AnnotatedTypeMirror.AnnotatedNullType
          Represents the null type.
static class AnnotatedTypeMirror.AnnotatedPrimitiveType
          Represents a primitive type.
static interface AnnotatedTypeMirror.AnnotatedReferenceType
           
static class AnnotatedTypeMirror.AnnotatedTypeVariable
          Represents a type variable.
static class AnnotatedTypeMirror.AnnotatedWildcardType
          Represents a wildcard type argument.
 
Field Summary
protected  TypeMirror actualType
          Actual type wrapped with this AnnotatedTypeMirror
protected  AnnotationUtils annotationFactory
          The factory to use for lazily creating annotations.
protected  Set<AnnotationMirror> annotations
          The annotations on this type.
protected  Element element
          the Element associated with this instance value, if one exists
protected  AnnotatedTypeMirror enclosingType
          The enclosing Type
protected  ProcessingEnvironment env
          Processing Environment of the current round
protected  AnnotatedTypeFactory typeFactory
          The factory to use for lazily creating annotated types.
 
Method Summary
abstract
<R,P> R
accept(AnnotatedTypeVisitor<R,P> v, P p)
          Applies a visitor to this type.
 void addAnnotation(AnnotationMirror a)
          Adds an annotation to this type.
 void addAnnotations(Iterable<? extends AnnotationMirror> annotations)
          Adds multiple annotations to this type.
 void clearAnnotations()
          Removes all annotations on this type
protected  AnnotatedTypeMirror copyFields(AnnotatedTypeMirror type, boolean annotation)
          Copy the fields on this type onto the passed type.
static AnnotatedTypeMirror createType(TypeMirror type, ProcessingEnvironment env, AnnotatedTypeFactory typeFactory)
          Creates the appropriate AnnotatedTypeMirror specific wrapper for the provided type
protected  AnnotatedTypeMirror.AnnotatedDeclaredType createTypeOfObject()
           
 List<? extends AnnotatedTypeMirror> directSuperTypes()
           
protected  List<AnnotatedTypeMirror.AnnotatedDeclaredType> directSuperTypes(AnnotatedTypeMirror.AnnotatedDeclaredType type)
           
 boolean equals(Object o)
           
protected static String formatAnnotationString(Collection<? extends AnnotationMirror> lst)
           
 AnnotationMirror getAnnotation(Name annotationName)
           
 AnnotationMirror getAnnotation(String annotationName)
          Returns the actual annotation mirror used to annotate this type, whose name equals the passed annotationName if one exist, null otherwise.
 Set<AnnotationMirror> getAnnotations()
          Returns the annotations on this type.
abstract  AnnotatedTypeMirror getCopy(boolean annotation)
          Returns a shallow copy of this type.
 Element getElement()
          Returns the element associated with the value the type represent, if any.
 AnnotatedTypeMirror getEnclosingType()
          Returns the enclosing type, as in the type of A in the type A.B.
 AnnotatedTypeMirror getErased()
          Returns the erasure type of the this type, according to JLS specifications.
 TypeKind getKind()
          Returns the kind of this type
 TypeMirror getUnderlyingType()
          Returns the underlying unannotated Java type wrapped with this
 boolean hasAnnotation(AnnotationMirror a)
          Determines whether this type contains an annotation with the same annotation type as a particular annotation.
 int hashCode()
           
 boolean removeAnnotation(AnnotationMirror a)
          Removes an annotation from the type.
 boolean removeAnnotations(Iterable<? extends AnnotationMirror> annotations)
          Removes multiple annotations from the type.
 AnnotatedTypeMirror substitute(Map<? extends AnnotatedTypeMirror,? extends AnnotatedTypeMirror> mappings)
          Sub
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

env

protected final ProcessingEnvironment env
Processing Environment of the current round


annotationFactory

protected final AnnotationUtils annotationFactory
The factory to use for lazily creating annotations.


typeFactory

protected final AnnotatedTypeFactory typeFactory
The factory to use for lazily creating annotated types.


actualType

protected final TypeMirror actualType
Actual type wrapped with this AnnotatedTypeMirror


element

protected Element element
the Element associated with this instance value, if one exists


enclosingType

protected AnnotatedTypeMirror enclosingType
The enclosing Type


annotations

protected final Set<AnnotationMirror> annotations
The annotations on this type.

Method Detail

createType

public static AnnotatedTypeMirror createType(TypeMirror type,
                                             ProcessingEnvironment env,
                                             AnnotatedTypeFactory typeFactory)
Creates the appropriate AnnotatedTypeMirror specific wrapper for the provided type

Parameters:
type -
env -
typeFactory -
Returns:
[to document]

directSuperTypes

public List<? extends AnnotatedTypeMirror> directSuperTypes()

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

accept

public abstract <R,P> R accept(AnnotatedTypeVisitor<R,P> v,
                               P p)
Applies a visitor to this type.

Type Parameters:
R - the return type of the visitor's methods
P - the type of the additional parameter to the visitor's methods
Parameters:
v - the visitor operating on this type
p - additional parameter to the visitor
Returns:
a visitor-specified result

getKind

public TypeKind getKind()
Returns the kind of this type

Returns:
the kind of this type

getUnderlyingType

public TypeMirror getUnderlyingType()
Returns the underlying unannotated Java type wrapped with this

Returns:
the underlying type

getEnclosingType

public AnnotatedTypeMirror getEnclosingType()
Returns the enclosing type, as in the type of A in the type A.B.

Returns:
enclosingType the enclosing type

getAnnotations

public Set<AnnotationMirror> getAnnotations()
Returns the annotations on this type. It does not include annotations in deep types (type arguments, array components, etc).

Returns:
a set of the annotations on this

getAnnotation

public AnnotationMirror getAnnotation(String annotationName)
Returns the actual annotation mirror used to annotate this type, whose name equals the passed annotationName if one exist, null otherwise.

Parameters:
annotationName -
Returns:
the annotation mirror for annotationName

getAnnotation

public AnnotationMirror getAnnotation(Name annotationName)

hasAnnotation

public boolean hasAnnotation(AnnotationMirror a)
Determines whether this type contains an annotation with the same annotation type as a particular annotation. This method does not consider an annotation's values.

Parameters:
a - the annotation to check for
Returns:
true iff the type contains an annotation with the same type as the annotation given by a

addAnnotation

public void addAnnotation(AnnotationMirror a)
Adds an annotation to this type. If the annotation does not have the TypeQualifier meta-annotation, this method has no effect.

Parameters:
a - the annotation to add

addAnnotations

public void addAnnotations(Iterable<? extends AnnotationMirror> annotations)
Adds multiple annotations to this type.

Parameters:
annotations - the annotations to add

removeAnnotation

public boolean removeAnnotation(AnnotationMirror a)
Removes an annotation from the type.

Parameters:
a - the annotation to remove
Returns:
true if the annotation was removed, false if the type's annotations were unchanged

removeAnnotations

public boolean removeAnnotations(Iterable<? extends AnnotationMirror> annotations)
Removes multiple annotations from the type.

Parameters:
annotations - the annotations to remove
Returns:
true if at least one annotation was removed, false if the type's annotations were unchanged

clearAnnotations

public void clearAnnotations()
Removes all annotations on this type


formatAnnotationString

protected static final String formatAnnotationString(Collection<? extends AnnotationMirror> lst)

toString

public String toString()
Overrides:
toString in class Object

getElement

public Element getElement()
Returns the element associated with the value the type represent, if any. I.e. For 'Integer i;' the element would be for 'i' not 'Integer'

Returns:
the Element of the value of this type, if one exists

getErased

public AnnotatedTypeMirror getErased()
Returns the erasure type of the this type, according to JLS specifications.

Returns:
the erasure of this

copyFields

protected AnnotatedTypeMirror copyFields(AnnotatedTypeMirror type,
                                         boolean annotation)
Copy the fields on this type onto the passed type. This method needs to be overriden by any subclass of AnnotatedTypeMirror

Parameters:
type - an empty type where fields of this are copied to
annotation - whether annotations are copied or not

getCopy

public abstract AnnotatedTypeMirror getCopy(boolean annotation)
Returns a shallow copy of this type.

Parameters:
annotation - whether copy should have annotations

createTypeOfObject

protected AnnotatedTypeMirror.AnnotatedDeclaredType createTypeOfObject()

substitute

public AnnotatedTypeMirror substitute(Map<? extends AnnotatedTypeMirror,? extends AnnotatedTypeMirror> mappings)
Sub

Parameters:
mappings -

directSuperTypes

protected final List<AnnotatedTypeMirror.AnnotatedDeclaredType> directSuperTypes(AnnotatedTypeMirror.AnnotatedDeclaredType type)