checkers.oigj
Class ImmutabilityAnnotatedTypeFactory

java.lang.Object
  extended by checkers.types.AnnotatedTypeFactory
      extended by checkers.types.BasicAnnotatedTypeFactory<ImmutabilitySubchecker>
          extended by checkers.oigj.ImmutabilityAnnotatedTypeFactory

public class ImmutabilityAnnotatedTypeFactory
extends BasicAnnotatedTypeFactory<ImmutabilitySubchecker>

Adds implicit and default OIGJ annotations, only if the user does not annotate the type explicitly. The default annotations are designed to minimize the number of Immutable or ReadOnly appearing in the source code.

Implicit Annotations for literals:
Immutable - any primitive literal (e.g. integer, long, boolean, etc.)
OIGJMutabilityBottom - a null literal

However, due to the default setting being similar to the implicit annotations, there is no significant distinction between the two in implementation.

Default Annotations:

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
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)
  3. supertype of a wildcard/type parameter in a class/method declaration
It will add OIGJMutabilityBottom, a special bottom annotation to a type if the input can be assigned to anything, like the following cases:
  1. (*)the input is a null literal
  2. (*)the input is an unannotated new array tree
  3. the input is an unannotated new class tree invoking a constructor of ReadOnly or AssignsFields receiver type
  4. the input is the class or interface declaration
It will add the Mutable annotation to a type if
  1. any remaining unqualified types (i.e. Mutable is the default)
Implementation detail: (*) cases are handled with a meta annotation rather than in this class.

Furthermore, it resolves I annotation to the proper annotation, according to its specification (described in I javadoc).


Nested Class Summary
Modifier and Type Class and Description
 
Nested classes/interfaces inherited from class checkers.types.AnnotatedTypeFactory
AnnotatedTypeFactory.InheritedFromClassAnnotator
 
Field Summary
Modifier and Type Field and Description
protected static String IMMUTABILITY_KEY
          the I annotation value key
 
Fields inherited from class checkers.types.BasicAnnotatedTypeFactory
defaults, flow, FLOW_BY_DEFAULT, poly, treeAnnotator, typeAnnotator, useFlow
 
Fields inherited from class checkers.types.AnnotatedTypeFactory
annotations, atypes, elements, env, fromTreeCache, qualHierarchy, root, trees, types, uid, visitorState
 
Constructor Summary
Constructor and Description
ImmutabilityAnnotatedTypeFactory(ImmutabilitySubchecker checker, CompilationUnitTree root)
          Constructor for IGJAnnotatedTypeFactory object.
 
Method Summary
Modifier and Type Method and Description
protected  Set<AnnotationMirror> createFlowQualifiers(ImmutabilitySubchecker checker)
          Returns the set of annotations to be inferred in flow analysis
protected  TreeAnnotator createTreeAnnotator(ImmutabilitySubchecker checker)
          Returns a TreeAnnotator that adds annotations to a type based on the contents of a tree.
protected  TypeAnnotator createTypeAnnotator(ImmutabilitySubchecker checker)
          Returns a TypeAnnotator that adds annotations to a type based on the content of the type itself.
protected  AnnotatedTypeMirror.AnnotatedDeclaredType getImplicitReceiverType(Tree tree)
           
 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
 
Methods inherited from class checkers.types.BasicAnnotatedTypeFactory
annotateImplicit, annotateImplicit, createFlow
 
Methods inherited from class checkers.types.AnnotatedTypeFactory
aliasedAnnotation, annotateInheritedFromClass, canHaveAnnotatedTypeParameters, constructorFromUse, createLRUCache, declarationFromElement, fromClass, fromElement, fromElement, fromElement, fromExpression, fromMember, fromNewClass, fromTypeTree, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFromTypeTree, getBoxedType, getCurrentClassType, getCurrentMethodReceiver, getEnclosingType, getPath, getQualifierHierarchy, getReceiver, getUnboxedType, getVisitorState, isMostEnclosingThisDeref, isWithinConstructor, toString, unify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IMMUTABILITY_KEY

protected static final String IMMUTABILITY_KEY
the I annotation value key

See Also:
Constant Field Values
Constructor Detail

ImmutabilityAnnotatedTypeFactory

public ImmutabilityAnnotatedTypeFactory(ImmutabilitySubchecker 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

createFlowQualifiers

protected Set<AnnotationMirror> createFlowQualifiers(ImmutabilitySubchecker checker)
Description copied from class: BasicAnnotatedTypeFactory
Returns the set of annotations to be inferred in flow analysis

Overrides:
createFlowQualifiers in class BasicAnnotatedTypeFactory<ImmutabilitySubchecker>

createTreeAnnotator

protected TreeAnnotator createTreeAnnotator(ImmutabilitySubchecker checker)
Description copied from class: BasicAnnotatedTypeFactory
Returns a TreeAnnotator that adds annotations to a type based on the contents of a tree. Subclasses may override this method to specify more appriopriate TreeAnnotator

Overrides:
createTreeAnnotator in class BasicAnnotatedTypeFactory<ImmutabilitySubchecker>
Returns:
a tree annotator

createTypeAnnotator

protected TypeAnnotator createTypeAnnotator(ImmutabilitySubchecker checker)
Description copied from class: BasicAnnotatedTypeFactory
Returns a TypeAnnotator that adds annotations to a type based on the content of the type itself.

Overrides:
createTypeAnnotator in class BasicAnnotatedTypeFactory<ImmutabilitySubchecker>
Returns:
a type annotator

getImplicitReceiverType

protected AnnotatedTypeMirror.AnnotatedDeclaredType getImplicitReceiverType(Tree tree)
Overrides:
getImplicitReceiverType in class AnnotatedTypeFactory

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

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 BasicAnnotatedTypeFactory<ImmutabilitySubchecker>
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

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 BasicAnnotatedTypeFactory<ImmutabilitySubchecker>
Parameters:
tree - the method invocation tree
Returns:
the method type being invoked with tree