public abstract class AbstractTreeScanner
extends com.sun.tools.javac.tree.TreeScanner
| Modifier and Type | Field and Description |
|---|---|
protected com.sun.tools.javac.tree.JCTree.JCCompilationUnit |
compilationUnit
Holds the compilation being currently scanned.
|
protected JSweetContext |
context
The transpiler context.
|
protected com.sun.tools.javac.util.DiagnosticSource |
diagnosticSource
The javac diagnostic source object (useful to get line information for
instance).
|
protected Stack<com.sun.tools.javac.tree.JCTree> |
stack
The scanning stack.
|
protected Map<String,com.sun.tools.javac.tree.JCTree.JCImport> |
staticImports
A map holding static import statements.
|
| Constructor and Description |
|---|
AbstractTreeScanner(TranspilationHandler logHandler,
JSweetContext context,
com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit)
Creates a new scanner.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
dumpStackTrace()
Pretty prints the current scanning trace.
|
protected void |
enter(com.sun.tools.javac.tree.JCTree tree)
Enters a tree element (to be scanned for printing).
|
protected void |
exit()
Exits a tree element (to be scanned for printing).
|
com.sun.tools.javac.tree.JCTree.JCCompilationUnit |
getCompilationUnit()
Gets the currently scanned compilation unit.
|
JSweetContext |
getContext()
Gets the transpiler context.
|
com.sun.tools.javac.tree.JCTree |
getCurrent()
Returns the currently visited node in the printer's scanning stack.
|
com.sun.tools.javac.tree.JCTree |
getFirstParent(Class<?>... types)
Gets the first tree in the scanning stack that matched one of the given
tree types.
|
protected String[] |
getGetSource(com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit)
Gets the Java source code for the given compilation unit.
|
com.sun.tools.javac.tree.JCTree |
getParent()
Returns the immediate parent in the printer's scanning stack.
|
<T extends com.sun.tools.javac.tree.JCTree> |
getParent(Class<T> type)
Gets the first parent in the scanning stack matching the given type.
|
<T extends com.sun.tools.javac.tree.JCTree> |
getParent(Class<T> type,
com.sun.tools.javac.tree.JCTree from)
Gets the first parent matching the given type, looking up from the given
tree in the scanning stack.
|
ExtendedElement |
getParentElement()
Gets the parent element in the printer's scanning stack.
|
<T extends Element> |
getParentElement(Class<T> type)
Gets the parent element matching the given type within the scanning
stack.
|
com.sun.tools.javac.tree.JCTree |
getParentOfParent()
Returns the parent of the immediate parent in the printer's scanning
stack.
|
Stack<com.sun.tools.javac.tree.JCTree> |
getStack()
Returns the printer's scanning stack.
|
Map<String,com.sun.tools.javac.tree.JCTree.JCImport> |
getStaticImports()
Gets the map of static imports in the current compilation unit.
|
protected void |
onRollbacked(com.sun.tools.javac.tree.JCTree target)
A global handler to be called when a rollback operation terminates.
|
void |
report(com.sun.tools.javac.tree.JCTree tree,
JSweetProblem problem,
Object... params)
Report a JSweet problem on the given program element (tree).
|
void |
report(com.sun.tools.javac.tree.JCTree tree,
com.sun.tools.javac.util.Name name,
JSweetProblem problem,
Object... params)
Report a JSweet problem on the given named program element (tree).
|
protected void |
rollback(com.sun.tools.javac.tree.JCTree target,
Consumer<com.sun.tools.javac.tree.JCTree> onRollbacked)
Rollbacks (undo) the current printing transaction up to the target.
|
void |
scan(ExtendedElement element)
Generically scan an extended element.
|
void |
scan(com.sun.tools.javac.tree.JCTree tree)
Scans a program tree.
|
protected void |
setCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit)
Sets the compilation unit to be scanned.
|
scan, visitAnnotatedType, visitAnnotation, visitApply, visitAssert, visitAssign, visitAssignop, visitBinary, visitBlock, visitBreak, visitCase, visitCatch, visitClassDef, visitConditional, visitContinue, visitDoLoop, visitErroneous, visitExec, visitForeachLoop, visitForLoop, visitIdent, visitIf, visitImport, visitIndexed, visitLabelled, visitLambda, visitLetExpr, visitLiteral, visitMethodDef, visitModifiers, visitNewArray, visitNewClass, visitParens, visitReference, visitReturn, visitSelect, visitSkip, visitSwitch, visitSynchronized, visitThrow, visitTopLevel, visitTree, visitTry, visitTypeApply, visitTypeArray, visitTypeBoundKind, visitTypeCast, visitTypeIdent, visitTypeIntersection, visitTypeParameter, visitTypeTest, visitTypeUnion, visitUnary, visitVarDef, visitWhileLoop, visitWildcardprotected Stack<com.sun.tools.javac.tree.JCTree> stack
protected Map<String,com.sun.tools.javac.tree.JCTree.JCImport> staticImports
protected com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit
protected JSweetContext context
protected com.sun.tools.javac.util.DiagnosticSource diagnosticSource
public AbstractTreeScanner(TranspilationHandler logHandler, JSweetContext context, com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit)
logHandler - the handler for reporting messagescontext - the JSweet transpilation contextcompilationUnit - the compilation to be scannedpublic void report(com.sun.tools.javac.tree.JCTree tree,
JSweetProblem problem,
Object... params)
tree - the program element causing the problemproblem - the problem to be reportedparams - problem argumentspublic void report(com.sun.tools.javac.tree.JCTree tree,
com.sun.tools.javac.util.Name name,
JSweetProblem problem,
Object... params)
tree - the program element causing the problemname - the name of that program elementproblem - the problem to be reportedparams - problem argumentspublic Map<String,com.sun.tools.javac.tree.JCTree.JCImport> getStaticImports()
getCompilationUnit()public com.sun.tools.javac.tree.JCTree.JCCompilationUnit getCompilationUnit()
public JSweetContext getContext()
protected String[] getGetSource(com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit)
protected final void setCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit)
public void scan(ExtendedElement element)
public void scan(com.sun.tools.javac.tree.JCTree tree)
scan in class com.sun.tools.javac.tree.TreeScannerprotected void dumpStackTrace()
This is useful for reporting internal errors and give information about what happened to the user.
protected void onRollbacked(com.sun.tools.javac.tree.JCTree target)
target - the rollback's targetrollback(JCTree, Consumer)protected void rollback(com.sun.tools.javac.tree.JCTree target,
Consumer<com.sun.tools.javac.tree.JCTree> onRollbacked)
target - the element up to which the printing should be undoneonRollbacked - the callback to be invoked once the rollback is finished (see
also onRollbacked(JCTree)protected void enter(com.sun.tools.javac.tree.JCTree tree)
exit()protected void exit()
enter(JCTree)public Stack<com.sun.tools.javac.tree.JCTree> getStack()
public com.sun.tools.javac.tree.JCTree getCurrent()
public com.sun.tools.javac.tree.JCTree getParent()
public com.sun.tools.javac.tree.JCTree getParentOfParent()
getStack()public ExtendedElement getParentElement()
getStack()public <T extends com.sun.tools.javac.tree.JCTree> T getParent(Class<T> type)
type - the type to search forgetStack()public <T extends Element> T getParentElement(Class<T> type)
type - the element type being search forgetStack()public com.sun.tools.javac.tree.JCTree getFirstParent(Class<?>... types)
types - the tree types to be checkedgetStack()public <T extends com.sun.tools.javac.tree.JCTree> T getParent(Class<T> type, com.sun.tools.javac.tree.JCTree from)
type - the type to search forfrom - the tree to start the search fromgetStack()