checkers.types.visitors
Class AnnotatedTypeScanner<R,P>

java.lang.Object
  extended by checkers.types.visitors.AnnotatedTypeScanner<R,P>
Type Parameters:
R - the return type of this visitor's methods. Use Void for visitors that do not need to return results.
P - the type of the additional parameter to this visitor's methods. Use Void for visitors that do not need an additional parameter.
All Implemented Interfaces:
AnnotatedTypeVisitor<R,P>
Direct Known Subclasses:
AnnotatedTypeComparer, AnnotatedTypeFactory.InheritedFromClassAnnotator, SimpleAnnotatedTypeScanner, TypeAnnotator

public class AnnotatedTypeScanner<R,P>
extends Object
implements AnnotatedTypeVisitor<R,P>

A TypeVisitor that visits all the child tree nodes. To visit types of a particular type, just override the corresponding visitXYZ method. Inside your method, call super.visitXYZ to visit descendant nodes. The default implementation of the visitXYZ methods will determine a result as follows: If the node being visited has no children, the result will be null. If the node being visited has one child, the result will be the result of calling scan on that child. The child may be a simple node or itself a list of nodes. If the node being visited has more than one child, the result will be determined by calling scan each child in turn, and then combining the result of each scan after the first with the cumulative result so far, as determined by the reduce(R, R) method. Each child may be either a simple node of a list of nodes. The default behavior of the reduce method is such that the result of the visitXYZ method will be the result of the last child scanned. Here is an example to count the parameter types number of nodes in a tree:

 class CountTypeVariable extends TreeScanner {

     @Override
     public Integer visitTypeVariable(ATypeVariable node, Void p) {
         return 1;
     }

     @Override
     public Integer reduce(Integer r1, Integer r2) {
         return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2);
     }
 }
 


Field Summary
Modifier and Type Field and Description
protected  Map<AnnotatedTypeMirror,R> visitedNodes
           
 
Constructor Summary
Constructor and Description
AnnotatedTypeScanner()
           
 
Method Summary
Modifier and Type Method and Description
protected  R reduce(R r1, R r2)
           
protected  R scan(AnnotatedTypeMirror type, P p)
          Processes an element by calling e.accept(this, p); this method may be overridden by subclasses.
protected  R scan(Iterable<? extends AnnotatedTypeMirror> types, P p)
          Processes an element by calling e.accept(this, p); this method may be overridden by subclasses.
 R scanAndReduce(AnnotatedTypeMirror type, P p, R r)
           
protected  R scanAndReduce(Iterable<? extends AnnotatedTypeMirror> types, P p, R r)
           
 R visit(AnnotatedTypeMirror t)
          A Convenience method equivalent to v.visit(t, null).
 R visit(AnnotatedTypeMirror type, P p)
          Visits a type.
 R visitArray(AnnotatedTypeMirror.AnnotatedArrayType type, P p)
          Visits an array type.
 R visitDeclared(AnnotatedTypeMirror.AnnotatedDeclaredType type, P p)
          Visits a declared type.
 R visitExecutable(AnnotatedTypeMirror.AnnotatedExecutableType type, P p)
          Visits an executable type.
 R visitNoType(AnnotatedTypeMirror.AnnotatedNoType type, P p)
          Visits NoType type.
 R visitNull(AnnotatedTypeMirror.AnnotatedNullType type, P p)
          Visits a null type.
 R visitPrimitive(AnnotatedTypeMirror.AnnotatedPrimitiveType type, P p)
          Visits a primitive type.
 R visitTypeVariable(AnnotatedTypeMirror.AnnotatedTypeVariable type, P p)
          Visits a type variable.
 R visitWildcard(AnnotatedTypeMirror.AnnotatedWildcardType type, P p)
          Visits a wildcard type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

visitedNodes

protected Map<AnnotatedTypeMirror,R> visitedNodes
Constructor Detail

AnnotatedTypeScanner

public AnnotatedTypeScanner()
Method Detail

visit

public final R visit(AnnotatedTypeMirror t)
Description copied from interface: AnnotatedTypeVisitor
A Convenience method equivalent to v.visit(t, null).

Specified by:
visit in interface AnnotatedTypeVisitor<R,P>
Parameters:
t - the type to visit
Returns:
a visitor-specified result

visit

public final R visit(AnnotatedTypeMirror type,
                     P p)
Description copied from interface: AnnotatedTypeVisitor
Visits a type.

Specified by:
visit in interface AnnotatedTypeVisitor<R,P>
Parameters:
type - the type to visit
p - a visitor-specified parameter
Returns:
a visitor-specified result

scan

protected R scan(AnnotatedTypeMirror type,
                 P p)
Processes an element by calling e.accept(this, p); this method may be overridden by subclasses.

Returns:
the result of visiting type

scan

protected R scan(Iterable<? extends AnnotatedTypeMirror> types,
                 P p)
Processes an element by calling e.accept(this, p); this method may be overridden by subclasses.

Parameters:
types -
p -
Returns:
a visitor-specified result

scanAndReduce

protected R scanAndReduce(Iterable<? extends AnnotatedTypeMirror> types,
                          P p,
                          R r)

scanAndReduce

public R scanAndReduce(AnnotatedTypeMirror type,
                       P p,
                       R r)

reduce

protected R reduce(R r1,
                   R r2)

visitDeclared

public R visitDeclared(AnnotatedTypeMirror.AnnotatedDeclaredType type,
                       P p)
Description copied from interface: AnnotatedTypeVisitor
Visits a declared type.

Specified by:
visitDeclared in interface AnnotatedTypeVisitor<R,P>
Parameters:
type - the type to visit
p - a visitor-specified parameter
Returns:
a visitor-specified result

visitArray

public R visitArray(AnnotatedTypeMirror.AnnotatedArrayType type,
                    P p)
Description copied from interface: AnnotatedTypeVisitor
Visits an array type.

Specified by:
visitArray in interface AnnotatedTypeVisitor<R,P>
Parameters:
type - the type to visit
p - a visitor-specified parameter
Returns:
a visitor-specified result

visitExecutable

public R visitExecutable(AnnotatedTypeMirror.AnnotatedExecutableType type,
                         P p)
Description copied from interface: AnnotatedTypeVisitor
Visits an executable type.

Specified by:
visitExecutable in interface AnnotatedTypeVisitor<R,P>
Parameters:
type - the type to visit
p - a visitor-specified parameter
Returns:
a visitor-specified result

visitTypeVariable

public R visitTypeVariable(AnnotatedTypeMirror.AnnotatedTypeVariable type,
                           P p)
Description copied from interface: AnnotatedTypeVisitor
Visits a type variable.

Specified by:
visitTypeVariable in interface AnnotatedTypeVisitor<R,P>
Parameters:
type - the type to visit
p - a visitor-specified parameter
Returns:
a visitor-specified result

visitNoType

public R visitNoType(AnnotatedTypeMirror.AnnotatedNoType type,
                     P p)
Description copied from interface: AnnotatedTypeVisitor
Visits NoType type.

Specified by:
visitNoType in interface AnnotatedTypeVisitor<R,P>
Parameters:
type - the type to visit
p - a visitor-specified parameter
Returns:
a visitor-specified result

visitNull

public R visitNull(AnnotatedTypeMirror.AnnotatedNullType type,
                   P p)
Description copied from interface: AnnotatedTypeVisitor
Visits a null type.

Specified by:
visitNull in interface AnnotatedTypeVisitor<R,P>
Parameters:
type - the type to visit
p - a visitor-specified parameter
Returns:
a visitor-specified result

visitPrimitive

public R visitPrimitive(AnnotatedTypeMirror.AnnotatedPrimitiveType type,
                        P p)
Description copied from interface: AnnotatedTypeVisitor
Visits a primitive type.

Specified by:
visitPrimitive in interface AnnotatedTypeVisitor<R,P>
Parameters:
type - the type to visit
p - a visitor-specified parameter
Returns:
a visitor-specified result

visitWildcard

public R visitWildcard(AnnotatedTypeMirror.AnnotatedWildcardType type,
                       P p)
Description copied from interface: AnnotatedTypeVisitor
Visits a wildcard type.

Specified by:
visitWildcard in interface AnnotatedTypeVisitor<R,P>
Parameters:
type - the type to visit
p - a visitor-specified parameter
Returns:
a visitor-specified result