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.
Implementation detail: (*) cases are handled by a meta-annotation rather than by code in this class.


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  AnnotationMirror LAZYNONNULL
          Represents the Nullness Checker qualifiers
protected  AnnotationMirror NONNULL
          Represents the Nullness Checker qualifiers
protected  AnnotationMirror NULLABLE
          Represents the Nullness Checker qualifiers
protected  AnnotationMirror POLYNULL
          Represents the Nullness Checker qualifiers
protected  AnnotationMirror RAW
          Represents the Nullness Checker qualifiers
 
Fields inherited from class checkers.types.AnnotatedTypeFactory
annotations, atypes, elements, env, fromTreeCache, qualHierarchy, root, trees, types, visitorState
 
Constructor Summary
Constructor and Description
NullnessAnnotatedTypeFactory(NullnessSubchecker checker, CompilationUnitTree root)
          Creates a NullnessAnnotatedTypeFactory.
 
Method Summary
Modifier and Type Method and Description
protected  AnnotationMirror aliasedAnnotation(AnnotationMirror a)
          Aliased annotations.
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.AnnotatedExecutableType constructorFromUse(NewClassTree tree)
          Determines the AnnotatedTypeMirror.AnnotatedExecutableType of a constructor invocation.
 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, canHaveAnnotatedTypeParameters, createLRUCache, declarationFromElement, fromClass, fromElement, fromElement, fromElement, fromExpression, fromMember, fromNewClass, fromTypeTree, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedType, getAnnotatedTypeFromTypeTree, getBoxedType, getCurrentClassType, getCurrentMethodReceiver, getPath, getQualifierHierarchy, getReceiver, getSelfType, getUnboxedType, getVisitorState, isMostEnclosingThisDeref, isWithinConstructor, postAsMemberOf, unify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POLYNULL

protected final AnnotationMirror POLYNULL
Represents the Nullness Checker qualifiers


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


LAZYNONNULL

protected final AnnotationMirror LAZYNONNULL
Represents the Nullness Checker qualifiers

Constructor Detail

NullnessAnnotatedTypeFactory

public NullnessAnnotatedTypeFactory(NullnessSubchecker 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

constructorFromUse

public AnnotatedTypeMirror.AnnotatedExecutableType constructorFromUse(NewClassTree tree)
Description copied from class: AnnotatedTypeFactory
Determines the AnnotatedTypeMirror.AnnotatedExecutableType of a constructor invocation. Note that this is different than calling AnnotatedTypeFactory.getAnnotatedType(Tree) or AnnotatedTypeFactory.fromExpression(ExpressionTree) on the constructor invocation; those determine the type of the result of invoking the constructor, which is probably an AnnotatedTypeMirror.AnnotatedDeclaredType.

Overrides:
constructorFromUse in class AnnotatedTypeFactory
Parameters:
tree - a constructor invocation
Returns:
the annotated type of the invoked constructor (as an executable type)

aliasedAnnotation

protected AnnotationMirror aliasedAnnotation(AnnotationMirror a)
Aliased annotations.

Overrides:
aliasedAnnotation in class AnnotatedTypeFactory