checkers.igj
Class IGJAnnotatedTypeFactory

java.lang.Object
  extended by checkers.types.AnnotatedTypeFactory
      extended by checkers.igj.IGJAnnotatedTypeFactory

public class IGJAnnotatedTypeFactory
extends AnnotatedTypeFactory

Adds implicit and default IGJ annotations, only if the user does not annotate the type explicitly. This factory will add the Immutable annotation to a type if the input is 1. a primitive type, 2. a known immutable type, if the class type is annotated as Immutable, or 3. an enumerator type. It will add the ReadOnly annotation to a type if the input is 1. a method receiver for an immutable class 2. a result of unification of different immutabilities (e.g. within Conditional Expressions) It will add the Mutable annotation to a type if the input is a use of a mutable type. As an implementation detail, it adds a special annotation, IGJPlaceHolder, Furthermore, it resolves I annotation to the proper annotation


Field Summary
protected static String IMMUTABILITY_KEY
           
 
Fields inherited from class checkers.types.AnnotatedTypeFactory
annotations, atypes, checker, elements, env, qualHierarchy, root, trees, types, visitorState
 
Constructor Summary
IGJAnnotatedTypeFactory(IGJChecker checker, CompilationUnitTree root)
          Constructor for IGJAnnotatedTypeFactory object.
 
Method Summary
protected  void annotateImplicit(Element element, AnnotatedTypeMirror type)
          Adds implicit annotations to a type obtained from a Element.
protected  void annotateImplicit(Tree tree, AnnotatedTypeMirror type)
          Adds implicit annotations to a type obtained from a Tree.
protected  void annotateInheritedFromClass(AnnotatedTypeMirror type)
          Override the default behavior of implicitly adding annotations on the class type to the declared types within the passed type.
 AnnotatedTypeMirror.AnnotatedDeclaredType getSelfType(Tree tree)
          Returns the type of field this, for the scope of this tree.
 AnnotatedTypeMirror.AnnotatedExecutableType methodFromUse(MethodInvocationTree tree)
          Resolves @I in the type of the method type base on the method invocation tree parameters.
 void postAsMemberOf(AnnotatedTypeMirror elementType, AnnotatedTypeMirror owner, Element element)
          Resolve the instances of @I in the elementType based on owner, according to is specification.
protected  void postDirectSuperTypes(AnnotatedTypeMirror type, List<? extends AnnotatedTypeMirror> supertypes)
          Replace all instances of @I in the super types with the immutability of the current type
 Collection<AnnotationMirror> unify(Collection<AnnotationMirror> c1, Collection<AnnotationMirror> c2)
          Returns the type qualifiers to be least upper bound for c1 and c2 qualifiers.
 
Methods inherited from class checkers.types.AnnotatedTypeFactory
constructorFromUse, createLRUCache, declarationFromElement, fromClass, fromElement, fromElement, fromElement, fromExpression, fromMember, fromTypeTree, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFromTypeTree, getBoxedType, getCurrentClassType, getCurrentMethodReceiver, getPath, getReceiver, getUnboxedType, getVisitorState, isSupportedQualifier, type
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IMMUTABILITY_KEY

protected static final String IMMUTABILITY_KEY
See Also:
Constant Field Values
Constructor Detail

IGJAnnotatedTypeFactory

public IGJAnnotatedTypeFactory(IGJChecker checker,
                               CompilationUnitTree root)
Constructor for IGJAnnotatedTypeFactory object.

Parameters:
checker - the checker to which this factory belongs
root - the compilation unit the annotation processor is processing currently
Method Detail

annotateImplicit

protected void annotateImplicit(Tree tree,
                                AnnotatedTypeMirror type)
Description copied from class: AnnotatedTypeFactory
Adds implicit annotations to a type obtained from a Tree. By default, this method does nothing. Subclasses should use this method to implement implicit annotations specific to their type systems.

Overrides:
annotateImplicit in class AnnotatedTypeFactory
Parameters:
tree - an AST node
type - the type obtained from tree

annotateImplicit

protected void annotateImplicit(Element element,
                                AnnotatedTypeMirror type)
Description copied from class: AnnotatedTypeFactory
Adds implicit annotations to a type obtained from a Element. By default, this method does nothing. Subclasses should use this method to implement implicit annotations specific to their type systems.

Overrides:
annotateImplicit in class AnnotatedTypeFactory
Parameters:
element - an element
type - the type obtained from elt

postDirectSuperTypes

protected void postDirectSuperTypes(AnnotatedTypeMirror type,
                                    List<? extends AnnotatedTypeMirror> supertypes)
Replace all instances of @I in the super types with the immutability of the current type

Overrides:
postDirectSuperTypes in class AnnotatedTypeFactory
Parameters:
type - the type whose supertypes are requested
supertypes - the supertypes of type

postAsMemberOf

public void postAsMemberOf(AnnotatedTypeMirror elementType,
                           AnnotatedTypeMirror owner,
                           Element element)
Resolve the instances of @I in the elementType based on owner, according to is specification.

Overrides:
postAsMemberOf in class AnnotatedTypeFactory
Parameters:
elementType - the annotated type of the element
owner - the annotated type of the receiver of the accessing tree
element - the element of the field or method

annotateInheritedFromClass

protected void annotateInheritedFromClass(AnnotatedTypeMirror type)
Override the default behavior of implicitly adding annotations on the class type to the declared types within the passed type.

Overrides:
annotateInheritedFromClass in class AnnotatedTypeFactory
Parameters:
type - the type for which class annotations will be inherited if there are no annotations already present

methodFromUse

public AnnotatedTypeMirror.AnnotatedExecutableType methodFromUse(MethodInvocationTree tree)
Resolves @I in the type of the method type base on the method invocation tree parameters. Any unresolved @Is is resolved to a place holder type. It resolves @I annotation in the following way:

Overrides:
methodFromUse in class AnnotatedTypeFactory
Parameters:
tree - the method invocation tree
Returns:
the method type being invoked with tree

getSelfType

public AnnotatedTypeMirror.AnnotatedDeclaredType getSelfType(Tree tree)
Returns the type of field this, for the scope of this tree. In IGJ, the self type is the method receiver in this scope.

Overrides:
getSelfType in class AnnotatedTypeFactory

unify

public Collection<AnnotationMirror> unify(Collection<AnnotationMirror> c1,
                                          Collection<AnnotationMirror> c2)
Description copied from class: AnnotatedTypeFactory
Returns the type qualifiers to be least upper bound for c1 and c2 qualifiers. In most cases, this is simply the intersection of the collections. However, if a type system specifies more than one type qualifier, this needs to return the least restrictive type qualifiers. Examples: For NonNull, unify('Nullable', 'NonNull') ==> Nullable For IGJ, unify('Immutable', 'Mutable') ==> ReadOnly This method simply returns the intersection. Any subclasses may need to override this method to adhere to the specification.

Overrides:
unify in class AnnotatedTypeFactory
Parameters:
c1 - type qualifiers for the first type
c2 - tyep qualifiers for the second type
Returns:
the least restrictive qualifiers for both types