org.glassfish.pfl.dynamic.codegen.impl
Class TreeWalker
java.lang.Object
org.glassfish.pfl.dynamic.codegen.impl.TreeWalker
- All Implemented Interfaces:
- Visitor
- Direct Known Subclasses:
- ASMByteCodeVisitor, ASMSetupVisitor, NopVisitor, SourceExpressionVisitor, SourceStatementVisitor
public abstract class TreeWalker
- extends Object
- implements Visitor
This is a general purpose utility that does a complete traversal
of a Node tree. A stack of Visitors is maintained. The current
Visitor on top of the stack is applied to each node.
Pre and post methods are provided for each type.
The default implementations of these methods delegate to the pre
and post methods of the superclass of the node type, so only the
required pre and post methods need be overridden.
This is used as follows:
TreeWalkerContext context = new TreeWalkerContext() ;
Visitor visitor = new SubclassOfTreeWalker( context, ... ) ;
context.push( visitor ) ;
node.accept( visitor ) ;
Note that this allows the temporary changing of the current visitor
while traversing the tree. The fact that the context support mark
and popMark operations makes it easy to process all of the children
of a node in any order: just call context.mark() in a preXXX method,
push appropriate visitors in the intermediate xXXBeforeYYY methods,
and then call context.popMark in the postXXX method.
Note that all preXXX methods return a boolean which indicates whether
or not this node should be traversed. If true is return, any
child nodes are traversed, and the postXXX method is called. If false
is returned, the visitXXX method completes.
If the preXXX method returns true, the postXXX method is always called.
If the preXXX method throws an exception or returns false, the
postXXX method is not called.
The more complex node types also include intermediate control methods
that can be overridden to affect the traversal.
- Author:
- Ken Cavanaugh
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
context
protected final TreeWalkerContext context
TreeWalker
public TreeWalker(TreeWalkerContext context)
preNode
public boolean preNode(Node arg)
postNode
public void postNode(Node arg)
visitNode
public void visitNode(Node arg)
- Specified by:
visitNode in interface Visitor
preFieldGenerator
public boolean preFieldGenerator(FieldGenerator arg)
postFieldGenerator
public void postFieldGenerator(FieldGenerator arg)
visitFieldGenerator
public final void visitFieldGenerator(FieldGenerator arg)
- Specified by:
visitFieldGenerator in interface Visitor
preClassGenerator
public boolean preClassGenerator(ClassGeneratorImpl arg)
classGeneratorBeforeFields
public boolean classGeneratorBeforeFields(ClassGeneratorImpl arg)
classGeneratorBeforeInitializer
public void classGeneratorBeforeInitializer(ClassGeneratorImpl arg)
classGeneratorBeforeMethod
public void classGeneratorBeforeMethod(ClassGeneratorImpl arg)
classGeneratorBeforeConstructor
public void classGeneratorBeforeConstructor(ClassGeneratorImpl arg)
postClassGenerator
public void postClassGenerator(ClassGeneratorImpl arg)
visitClassGenerator
public void visitClassGenerator(ClassGeneratorImpl arg)
- Specified by:
visitClassGenerator in interface Visitor
preMethodGenerator
public boolean preMethodGenerator(MethodGenerator arg)
methodGeneratorBeforeArguments
public boolean methodGeneratorBeforeArguments(MethodGenerator arg)
methodGeneratorAfterArguments
public void methodGeneratorAfterArguments(MethodGenerator arg)
postMethodGenerator
public void postMethodGenerator(MethodGenerator arg)
visitMethodGenerator
public void visitMethodGenerator(MethodGenerator arg)
- Specified by:
visitMethodGenerator in interface Visitor
preStatement
public boolean preStatement(Statement arg)
postStatement
public void postStatement(Statement arg)
visitStatement
public void visitStatement(Statement arg)
- Specified by:
visitStatement in interface Visitor
preThrowStatement
public boolean preThrowStatement(ThrowStatement arg)
postThrowStatement
public void postThrowStatement(ThrowStatement arg)
visitThrowStatement
public void visitThrowStatement(ThrowStatement arg)
- Specified by:
visitThrowStatement in interface Visitor
preAssignmentStatement
public boolean preAssignmentStatement(AssignmentStatement arg)
assignmentStatementBeforeLeftSide
public void assignmentStatementBeforeLeftSide(AssignmentStatement arg)
postAssignmentStatement
public void postAssignmentStatement(AssignmentStatement arg)
visitAssignmentStatement
public void visitAssignmentStatement(AssignmentStatement arg)
- Specified by:
visitAssignmentStatement in interface Visitor
preBlockStatement
public boolean preBlockStatement(BlockStatement arg)
blockStatementBeforeBodyStatement
public void blockStatementBeforeBodyStatement(BlockStatement arg,
Statement stmt)
postBlockStatement
public void postBlockStatement(BlockStatement arg)
visitBlockStatement
public void visitBlockStatement(BlockStatement arg)
- Specified by:
visitBlockStatement in interface Visitor
preCaseBranch
public boolean preCaseBranch(CaseBranch arg)
caseBranchBeforeBodyStatement
public void caseBranchBeforeBodyStatement(CaseBranch arg)
postCaseBranch
public void postCaseBranch(CaseBranch arg)
visitCaseBranch
public void visitCaseBranch(CaseBranch arg)
- Specified by:
visitCaseBranch in interface Visitor
preDefinitionStatement
public boolean preDefinitionStatement(DefinitionStatement arg)
definitionStatementBeforeExpr
public boolean definitionStatementBeforeExpr(DefinitionStatement arg)
postDefinitionStatement
public void postDefinitionStatement(DefinitionStatement arg)
visitDefinitionStatement
public void visitDefinitionStatement(DefinitionStatement arg)
- Specified by:
visitDefinitionStatement in interface Visitor
preIfStatement
public boolean preIfStatement(IfStatement arg)
ifStatementBeforeTruePart
public void ifStatementBeforeTruePart(IfStatement arg)
ifStatementBeforeFalsePart
public boolean ifStatementBeforeFalsePart(IfStatement arg)
postIfStatement
public void postIfStatement(IfStatement arg)
visitIfStatement
public void visitIfStatement(IfStatement arg)
- Specified by:
visitIfStatement in interface Visitor
preBreakStatement
public boolean preBreakStatement(BreakStatement arg)
postBreakStatement
public void postBreakStatement(BreakStatement arg)
visitBreakStatement
public void visitBreakStatement(BreakStatement arg)
- Specified by:
visitBreakStatement in interface Visitor
preReturnStatement
public boolean preReturnStatement(ReturnStatement arg)
postReturnStatement
public void postReturnStatement(ReturnStatement arg)
visitReturnStatement
public void visitReturnStatement(ReturnStatement arg)
- Specified by:
visitReturnStatement in interface Visitor
preSwitchStatement
public boolean preSwitchStatement(SwitchStatement arg)
switchStatementBeforeCaseBranches
public boolean switchStatementBeforeCaseBranches(SwitchStatement arg)
switchStatementBeforeDefault
public boolean switchStatementBeforeDefault(SwitchStatement arg)
postSwitchStatement
public void postSwitchStatement(SwitchStatement arg)
visitSwitchStatement
public void visitSwitchStatement(SwitchStatement arg)
- Specified by:
visitSwitchStatement in interface Visitor
preTryStatement
public boolean preTryStatement(TryStatement arg)
tryStatementBeforeBlock
public void tryStatementBeforeBlock(TryStatement arg,
Type type,
Variable var,
BlockStatement block)
tryStatementBeforeFinalPart
public boolean tryStatementBeforeFinalPart(TryStatement arg)
postTryStatement
public void postTryStatement(TryStatement arg)
visitTryStatement
public void visitTryStatement(TryStatement arg)
- Specified by:
visitTryStatement in interface Visitor
preWhileStatement
public boolean preWhileStatement(WhileStatement arg)
whileStatementBeforeBody
public void whileStatementBeforeBody(WhileStatement arg)
postWhileStatement
public void postWhileStatement(WhileStatement arg)
visitWhileStatement
public void visitWhileStatement(WhileStatement arg)
- Specified by:
visitWhileStatement in interface Visitor
preExpression
public boolean preExpression(ExpressionInternal arg)
postExpression
public void postExpression(ExpressionInternal arg)
visitExpression
public void visitExpression(ExpressionInternal arg)
- Specified by:
visitExpression in interface Visitor
preVariable
public boolean preVariable(Variable arg)
postVariable
public void postVariable(Variable arg)
visitVariable
public final void visitVariable(Variable arg)
- Specified by:
visitVariable in interface Visitor
preConstantExpression
public boolean preConstantExpression(ExpressionFactory.ConstantExpression arg)
postConstantExpression
public void postConstantExpression(ExpressionFactory.ConstantExpression arg)
visitConstantExpression
public void visitConstantExpression(ExpressionFactory.ConstantExpression arg)
- Specified by:
visitConstantExpression in interface Visitor
preVoidExpression
public boolean preVoidExpression(ExpressionFactory.VoidExpression arg)
postVoidExpression
public void postVoidExpression(ExpressionFactory.VoidExpression arg)
visitVoidExpression
public void visitVoidExpression(ExpressionFactory.VoidExpression arg)
- Specified by:
visitVoidExpression in interface Visitor
preThisExpression
public boolean preThisExpression(ExpressionFactory.ThisExpression arg)
postThisExpression
public void postThisExpression(ExpressionFactory.ThisExpression arg)
visitThisExpression
public void visitThisExpression(ExpressionFactory.ThisExpression arg)
- Specified by:
visitThisExpression in interface Visitor
preUnaryOperatorExpression
public boolean preUnaryOperatorExpression(ExpressionFactory.UnaryOperatorExpression arg)
postUnaryOperatorExpression
public void postUnaryOperatorExpression(ExpressionFactory.UnaryOperatorExpression arg)
visitUnaryOperatorExpression
public void visitUnaryOperatorExpression(ExpressionFactory.UnaryOperatorExpression arg)
- Specified by:
visitUnaryOperatorExpression in interface Visitor
preBinaryOperatorExpression
public boolean preBinaryOperatorExpression(ExpressionFactory.BinaryOperatorExpression arg)
binaryOperatorExpressionBeforeRight
public void binaryOperatorExpressionBeforeRight(ExpressionFactory.BinaryOperatorExpression arg)
postBinaryOperatorExpression
public void postBinaryOperatorExpression(ExpressionFactory.BinaryOperatorExpression arg)
visitBinaryOperatorExpression
public void visitBinaryOperatorExpression(ExpressionFactory.BinaryOperatorExpression arg)
- Specified by:
visitBinaryOperatorExpression in interface Visitor
preCastExpression
public boolean preCastExpression(ExpressionFactory.CastExpression arg)
postCastExpression
public void postCastExpression(ExpressionFactory.CastExpression arg)
visitCastExpression
public void visitCastExpression(ExpressionFactory.CastExpression arg)
- Specified by:
visitCastExpression in interface Visitor
preInstofExpression
public boolean preInstofExpression(ExpressionFactory.InstofExpression arg)
postInstofExpression
public void postInstofExpression(ExpressionFactory.InstofExpression arg)
visitInstofExpression
public void visitInstofExpression(ExpressionFactory.InstofExpression arg)
- Specified by:
visitInstofExpression in interface Visitor
preStaticCallExpression
public boolean preStaticCallExpression(ExpressionFactory.StaticCallExpression arg)
staticCallExpressionBeforeArg
public void staticCallExpressionBeforeArg(ExpressionFactory.StaticCallExpression arg)
postStaticCallExpression
public void postStaticCallExpression(ExpressionFactory.StaticCallExpression arg)
visitStaticCallExpression
public void visitStaticCallExpression(ExpressionFactory.StaticCallExpression arg)
- Specified by:
visitStaticCallExpression in interface Visitor
preNonStaticCallExpression
public boolean preNonStaticCallExpression(ExpressionFactory.NonStaticCallExpression arg)
nonStaticCallExpressionBeforeArg
public void nonStaticCallExpressionBeforeArg(ExpressionFactory.NonStaticCallExpression arg)
postNonStaticCallExpression
public void postNonStaticCallExpression(ExpressionFactory.NonStaticCallExpression arg)
visitNonStaticCallExpression
public void visitNonStaticCallExpression(ExpressionFactory.NonStaticCallExpression arg)
- Specified by:
visitNonStaticCallExpression in interface Visitor
preNewObjExpression
public boolean preNewObjExpression(ExpressionFactory.NewObjExpression arg)
newObjExpressionBeforeArg
public void newObjExpressionBeforeArg(ExpressionFactory.NewObjExpression arg)
postNewObjExpression
public void postNewObjExpression(ExpressionFactory.NewObjExpression arg)
visitNewObjExpression
public void visitNewObjExpression(ExpressionFactory.NewObjExpression arg)
- Specified by:
visitNewObjExpression in interface Visitor
preNewArrExpression
public boolean preNewArrExpression(ExpressionFactory.NewArrExpression arg)
newArrExpressionAfterSize
public void newArrExpressionAfterSize(ExpressionFactory.NewArrExpression arg)
newArrExpressionBeforeExpression
public void newArrExpressionBeforeExpression(ExpressionFactory.NewArrExpression arg)
newArrExpressionAfterExpression
public void newArrExpressionAfterExpression(ExpressionFactory.NewArrExpression arg)
postNewArrExpression
public void postNewArrExpression(ExpressionFactory.NewArrExpression arg)
visitNewArrExpression
public void visitNewArrExpression(ExpressionFactory.NewArrExpression arg)
- Specified by:
visitNewArrExpression in interface Visitor
preSuperCallExpression
public boolean preSuperCallExpression(ExpressionFactory.SuperCallExpression arg)
superCallExpressionBeforeArg
public void superCallExpressionBeforeArg(ExpressionFactory.SuperCallExpression arg)
postSuperCallExpression
public void postSuperCallExpression(ExpressionFactory.SuperCallExpression arg)
visitSuperCallExpression
public void visitSuperCallExpression(ExpressionFactory.SuperCallExpression arg)
- Specified by:
visitSuperCallExpression in interface Visitor
preSuperObjExpression
public boolean preSuperObjExpression(ExpressionFactory.SuperObjExpression arg)
superObjExpressionBeforeArg
public void superObjExpressionBeforeArg(ExpressionFactory.SuperObjExpression arg)
postSuperObjExpression
public void postSuperObjExpression(ExpressionFactory.SuperObjExpression arg)
visitSuperObjExpression
public void visitSuperObjExpression(ExpressionFactory.SuperObjExpression arg)
- Specified by:
visitSuperObjExpression in interface Visitor
preThisObjExpression
public boolean preThisObjExpression(ExpressionFactory.ThisObjExpression arg)
postThisObjExpression
public void postThisObjExpression(ExpressionFactory.ThisObjExpression arg)
thisObjExpressionBeforeArg
public void thisObjExpressionBeforeArg(ExpressionFactory.ThisObjExpression arg)
visitThisObjExpression
public void visitThisObjExpression(ExpressionFactory.ThisObjExpression arg)
- Specified by:
visitThisObjExpression in interface Visitor
preNonStaticFieldAccessExpression
public boolean preNonStaticFieldAccessExpression(ExpressionFactory.NonStaticFieldAccessExpression arg)
postNonStaticFieldAccessExpression
public void postNonStaticFieldAccessExpression(ExpressionFactory.NonStaticFieldAccessExpression arg)
visitNonStaticFieldAccessExpression
public void visitNonStaticFieldAccessExpression(ExpressionFactory.NonStaticFieldAccessExpression arg)
- Specified by:
visitNonStaticFieldAccessExpression in interface Visitor
preStaticFieldAccessExpression
public boolean preStaticFieldAccessExpression(ExpressionFactory.StaticFieldAccessExpression arg)
postStaticFieldAccessExpression
public void postStaticFieldAccessExpression(ExpressionFactory.StaticFieldAccessExpression arg)
visitStaticFieldAccessExpression
public void visitStaticFieldAccessExpression(ExpressionFactory.StaticFieldAccessExpression arg)
- Specified by:
visitStaticFieldAccessExpression in interface Visitor
preArrayIndexExpression
public boolean preArrayIndexExpression(ExpressionFactory.ArrayIndexExpression arg)
arrayIndexExpressionBeforeExpr
public void arrayIndexExpressionBeforeExpr(ExpressionFactory.ArrayIndexExpression arg)
postArrayIndexExpression
public void postArrayIndexExpression(ExpressionFactory.ArrayIndexExpression arg)
visitArrayIndexExpression
public void visitArrayIndexExpression(ExpressionFactory.ArrayIndexExpression arg)
- Specified by:
visitArrayIndexExpression in interface Visitor
preArrayLengthExpression
public boolean preArrayLengthExpression(ExpressionFactory.ArrayLengthExpression arg)
postArrayLengthExpression
public void postArrayLengthExpression(ExpressionFactory.ArrayLengthExpression arg)
visitArrayLengthExpression
public void visitArrayLengthExpression(ExpressionFactory.ArrayLengthExpression arg)
- Specified by:
visitArrayLengthExpression in interface Visitor
preIfExpression
public boolean preIfExpression(ExpressionFactory.IfExpression arg)
ifExpressionBeforeTruePart
public void ifExpressionBeforeTruePart(ExpressionFactory.IfExpression arg)
ifExpressionBeforeFalsePart
public boolean ifExpressionBeforeFalsePart(ExpressionFactory.IfExpression arg)
postIfExpression
public void postIfExpression(ExpressionFactory.IfExpression arg)
visitIfExpression
public void visitIfExpression(ExpressionFactory.IfExpression arg)
- Specified by:
visitIfExpression in interface Visitor
Copyright © 2013 Oracle. All Rights Reserved.