Class TypeASTMapper<N>
- Type Parameters:
N- common supertype of the AST nodes
TypeASTMapper traverses a client-maintained abstract syntax tree representing a type in
parallel with an ATypeElement from the annotation scene library, indicating corresponding
pairs of AST nodes and AElements to the client so the client can process them in some
fashion.
To use TypeASTMapper, write a subclass for your particular AST. Implement getElementType(N), numTypeArguments(N), and getTypeArgument(N, int) so that the mapper
knows how to traverse your AST; implement map(N, org.checkerframework.afu.scenelib.el.ATypeElement) to perform whatever processing you desire
on each AST node and its corresponding AElement. Then, pass the root of your AST and the
corresponding ATypeElement from your annotation scene to traverse(N, org.checkerframework.afu.scenelib.el.ATypeElement).
TypeASTMapper itself saves no state, but subclasses may save state if they wish.
ATypeElement objects that will be traversed
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract NgetElementType(N n) Ifnrepresents an array type,getElementType(N)returns the node for the element type of the array; otherwise it returnsnull.protected abstract NgetTypeArgument(N n, int index) Returns the node corresponding to the type argument ofn(which must be a parameterized type) at the given index.protected abstract voidmap(N n, ATypeElement e) Signals to the client thatncorresponds toe.protected abstract intIfnrepresents a parameterized type,numTypeArguments(N)returns the number of type arguments; otherwise it returns 0.voidtraverse(N tastRoot, ATypeElement aslRoot) Traverses the type AST rooted attastRoot, callingmap(N, org.checkerframework.afu.scenelib.el.ATypeElement)with each AST node and the correspondingAElementfromaslRoot.
-
Constructor Details
-
TypeASTMapper
protected TypeASTMapper()Constructs aTypeASTMapper. ATypeASTMapperstores no state.
-
-
Method Details
-
traverse
Traverses the type AST rooted attastRoot, callingmap(N, org.checkerframework.afu.scenelib.el.ATypeElement)with each AST node and the correspondingAElementfromaslRoot.If a node of the AST has no corresponding inner type in
aslRoot, an inner typeAElementis vivified to hold any annotations thatmap(N, org.checkerframework.afu.scenelib.el.ATypeElement)might wish to store in it. Thus, a call totraverse(N, org.checkerframework.afu.scenelib.el.ATypeElement)may write toaslRooteven ifmap(N, org.checkerframework.afu.scenelib.el.ATypeElement)does not write to itsAElementargument. You may wish to pruneaslRootafter traversal. -
getElementType
Ifnrepresents an array type,getElementType(N)returns the node for the element type of the array; otherwise it returnsnull. -
numTypeArguments
Ifnrepresents a parameterized type,numTypeArguments(N)returns the number of type arguments; otherwise it returns 0. -
getTypeArgument
Returns the node corresponding to the type argument ofn(which must be a parameterized type) at the given index. The caller must ensure that0 <= index <.numTypeArguments(N)(n) -
map
Signals to the client thatncorresponds toe. The client may, for example, set flags innbased on the annotations ine.. ThetlAnnotationsHereTypeASTMappercallsmap(N, org.checkerframework.afu.scenelib.el.ATypeElement)onnbefore it callsmap(N, org.checkerframework.afu.scenelib.el.ATypeElement)on sub-nodes ofnbut not necessarily before it explores the structure ofn's subtree.
-