checkers.nullness
Class NullnessAnnotatedTypeFactory

java.lang.Object
  extended by checkers.types.AnnotatedTypeFactory
      extended by checkers.nullness.NullnessAnnotatedTypeFactory

public class NullnessAnnotatedTypeFactory
extends AnnotatedTypeFactory

Adds the NonNull annotation to a type that is:

  1. (*) all literals (except for null literal)
  2. (*) all primitive types
  3. (*) an array-creation expression (with new)
  4. (*) an object-creation expression (with new)
  5. (*) a package declaration
  6. in the scope of a DefaultQualifier annotation and matches its location criteria
  7. determined to be NonNull by flow-sensitive inference
  8. the class in a static member access (e.g., "System" in "System.out")
  9. an exception parameter
  10. the receiver type of a non-static (and non-constructor) method
Adds the Raw annotation to
  1. the receiver type of constructors.

Additionally, the type factory will add the Nullable annotation to a type if the input is

  1. (*) the null literal
  2. of type Void,
  3. may resolve the types of some NonNull fields as Nullable depending on the presence of a Raw annotation on a constructor or method receiver. Please review the Checker Framework for Raw semantics.
(*) cases handled with a meta-annotation


Field Summary
protected  AnnotationMirror NONNULL
          Represents the Nullness Checker qualifiers
protected  AnnotationMirror NULLABLE
          Represents the Nullness Checker qualifiers
protected  AnnotationMirror RAW
          Represents the Nullness Checker qualifiers
 
Fields inherited from class checkers.types.AnnotatedTypeFactory
annotations, atypes, elements, env, qualHierarchy, root, trees, types, visitorState
 
Constructor Summary
NullnessAnnotatedTypeFactory(NullnessChecker checker, CompilationUnitTree root)
          Creates a NullnessAnnotatedTypeFactory.
 
Method Summary
protected  void annotateImplicit(Element elt, 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.
 AnnotatedTypeMirror.AnnotatedDeclaredType getEnclosingType(TypeElement element, Tree tree)
           
protected  AnnotatedTypeMirror.AnnotatedDeclaredType getImplicitReceiverType(Tree tree)
           
 AnnotatedTypeMirror.AnnotatedExecutableType methodFromUse(MethodInvocationTree tree)
          Determines the type of the invoked method based on the passed method invocation tree.
protected  void postDirectSuperTypes(AnnotatedTypeMirror type, List<? extends AnnotatedTypeMirror> supertypes)
          A callback method for the AnnotatedTypeFactory subtypes to customize directSuperTypes().
 
Methods inherited from class checkers.types.AnnotatedTypeFactory
annotateInheritedFromClass, constructorFromUse, createLRUCache, declarationFromElement, fromClass, fromElement, fromElement, fromElement, fromExpression, fromMember, fromTypeTree, fromTypeTree, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFromTypeTree, getBoxedType, getCurrentClassType, getCurrentMethodReceiver, getPath, getQualifierHierarchy, getReceiver, getSelfType, getUnboxedType, getVisitorState, isMostEnclosingThisDeref, postAsMemberOf, unify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONNULL

protected final AnnotationMirror NONNULL
Represents the Nullness Checker qualifiers


RAW

protected final AnnotationMirror RAW
Represents the Nullness Checker qualifiers


NULLABLE

protected final AnnotationMirror NULLABLE
Represents the Nullness Checker qualifiers

Constructor Detail

NullnessAnnotatedTypeFactory

public NullnessAnnotatedTypeFactory(NullnessChecker checker,
                                    CompilationUnitTree root)
Creates a NullnessAnnotatedTypeFactory.

Method Detail

annotateImplicit

protected void annotateImplicit(Element elt,
                                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:
elt - an element
type - the type obtained from elt

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

getImplicitReceiverType

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

getEnclosingType

public final AnnotatedTypeMirror.AnnotatedDeclaredType getEnclosingType(TypeElement element,
                                                                        Tree tree)
Overrides:
getEnclosingType in class AnnotatedTypeFactory

postDirectSuperTypes

protected void postDirectSuperTypes(AnnotatedTypeMirror type,
                                    List<? extends AnnotatedTypeMirror> supertypes)
Description copied from class: AnnotatedTypeFactory
A callback method for the AnnotatedTypeFactory subtypes to customize directSuperTypes(). Overriding methods should merely change the annotations on the supertypes, without adding or removing new types The default provided implementation adds type annotations to supertypes. This allows the type and its supertypes to have the qualifiers, e.g. the supertypes of an Immutable type are also Immutable.

Overrides:
postDirectSuperTypes in class AnnotatedTypeFactory
Parameters:
type - the type whose supertypes are desired
supertypes - the supertypes as specified by the base AnnotatedTypeFactory

methodFromUse

public AnnotatedTypeMirror.AnnotatedExecutableType methodFromUse(MethodInvocationTree tree)
Description copied from class: AnnotatedTypeFactory
Determines the type of the invoked method based on the passed method invocation tree. The returned method type has all type variables resolved, whether based on receiver type, passed type parameters if any, and method invocation parameter. Subclasses may override this method to customize inference of types or qualifiers based on method invocation parameters. As an implementation detail, this method depends on AnnotatedTypes.asMemberOf(AnnotatedTypeMirror, Element), and customization based on receiver type should be in accordance to its specification.

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