public abstract class ExpressionTreeWalker extends Object
Implementors will define an algorithm resulting in some inner expressions of an EvaluableExpression (hereafter to be called the “root expression”) being visited and left in a certain order. The following hook types are offered:
at
: called when the traversal first reaches an expression.
after
: called when leaving an expression.
Every hook type is offered for every EvaluableExpression in
de.uka.ipd.sdq.beagle.core.evaluableexpressions
. Additionally, there is an
other
hook for each type. It is called for every expression type no hook was
defined for. If a hook is to be defined for an expression type but the other
hook is to be called for the expression anyway, the super
hook can be called.
Example:
class MyWalker extends ExpressionTreeWalker {
@Override
void atAddition(AdditionExpression expression) {
// some code
}
@Override
void atMultiplication(MultiplicationExpression expression) {
// some code
super.atMultiplication(expression);
// more code
}
@Override
void atOther(EvaluableExpression expression) {
// will be called for every expression but AdditionExpressions
}
}
MyWalker#atOther
will be called when first visiting any
EvaluableExpression, except when visiting an
AdditionExpression.
Furthermore, the class offers two general purpose hooks, atExpression(de.uka.ipd.sdq.beagle.core.evaluableexpressions.EvaluableExpression)
and
afterExpression(de.uka.ipd.sdq.beagle.core.evaluableexpressions.EvaluableExpression)
, that are always called for any expression. These will be
called before the expression’s specific hook (which implies that they will
also be called before the other
hook).
Constructor and Description |
---|
ExpressionTreeWalker() |
Modifier and Type | Method and Description |
---|---|
protected void |
afterAddition(AdditionExpression expression)
Called when leaving an
AdditionExpression . |
protected void |
afterComparison(ComparisonExpression expression)
Called when leaving a
ComparisonExpression . |
protected void |
afterConstant(ConstantExpression expression)
Called when leaving a
ConstantExpression . |
protected void |
afterDivision(DivisionExpression expression)
Called when leaving a
DivisionExpression . |
protected void |
afterExponentation(ExponentationExpression expression)
Called when leaving an
ExponentationExpression . |
protected void |
afterExponentialFunction(ExponentialFunctionExpression expression)
Called when leaving an
ExponentialFunctionExpression . |
protected void |
afterExpression(EvaluableExpression expression)
Called when leaving any
EvaluableExpression . |
protected void |
afterIfThenElse(IfThenElseExpression expression)
Called when leaving an
IfThenElseExpression . |
protected void |
afterLogarithm(LogarithmExpression expression)
Called when leaving a
LogarithmExpression . |
protected void |
afterMultiplication(MultiplicationExpression expression)
Called when leaving a
MultiplicationExpression . |
protected void |
afterNaturalLogarithm(NaturalLogarithmExpression expression)
Called when leaving a
NaturalLogarithmExpression . |
protected void |
afterOther(EvaluableExpression expression)
Called when leaving any
EvaluableExpression no hook was defined for. |
protected void |
afterSine(SineExpression expression)
Called when leaving a
SineExpression , after its inner expressions will be
visited. |
protected void |
afterSubtraction(SubtractionExpression expression)
Called when leaving a
SubtractionExpression . |
protected void |
afterVariable(EvaluableVariable expression)
Called when leaving an
EvaluableVariable . |
protected void |
atAddition(AdditionExpression expression)
Called when first visiting an
AdditionExpression . |
protected void |
atComparison(ComparisonExpression expression)
Called when first visiting a
ComparisonExpression . |
protected void |
atConstant(ConstantExpression expression)
Called when first visiting a
ConstantExpression . |
protected void |
atDivision(DivisionExpression expression)
Called when first visiting a
DivisionExpression . |
protected void |
atExponentation(ExponentationExpression expression)
Called when first visiting an
ExponentationExpression . |
protected void |
atExponentialFunction(ExponentialFunctionExpression expression)
Called when first visiting an
ExponentialFunctionExpression . |
protected void |
atExpression(EvaluableExpression expression)
Called when visiting any
EvaluableExpression . |
protected void |
atIfThenElse(IfThenElseExpression expression)
Called when first visiting an
IfThenElseExpression . |
protected void |
atLogarithm(LogarithmExpression expression)
Called when first visiting a
LogarithmExpression . |
protected void |
atMultiplication(MultiplicationExpression expression)
Called when first visiting a
MultiplicationExpression . |
protected void |
atNaturalLogarithm(NaturalLogarithmExpression expression)
Called when first visiting a
NaturalLogarithmExpression . |
protected void |
atOther(EvaluableExpression expression)
Called when first visiting any
EvaluableExpression no hook was defined for. |
protected void |
atSine(SineExpression expression)
Called when first visiting a
SineExpression . |
protected void |
atSubtraction(SubtractionExpression expression)
Called when first visiting a
SubtractionExpression . |
protected void |
atVariable(EvaluableVariable expression)
Called when first visiting an
EvaluableVariable . |
protected abstract int |
getTraversalDepth()
Queries how “deep” the currently visited expression is in the visited tree.
|
protected abstract int |
getVisitedCount()
Queries how many expressions have been visited during the momentary traversal.
|
protected abstract int getVisitedCount()
protected abstract int getTraversalDepth()
at
hooks have been called - how many after
hooks
have been called - 1. Will be 0
at the root expression and
-1
at the before and after a traversal.protected void atOther(EvaluableExpression expression)
EvaluableExpression
no hook was defined for.
See the class description for details.expression
- The momentarily visited expression.atExpression(EvaluableExpression)
protected void atExpression(EvaluableExpression expression)
EvaluableExpression
. Contrary to
atOther(EvaluableExpression)
, this hook will always be called, no matter
if an overridden specific hook exists for expression
.expression
- The momentarily visited expression.atOther(EvaluableExpression)
protected void atAddition(AdditionExpression expression)
AdditionExpression
.expression
- The momentary visited expression.protected void atMultiplication(MultiplicationExpression expression)
MultiplicationExpression
.expression
- The momentary visited expression.protected void atVariable(EvaluableVariable expression)
EvaluableVariable
.expression
- The momentary visited expression.protected void atComparison(ComparisonExpression expression)
ComparisonExpression
.expression
- The momentary visited expression.protected void atConstant(ConstantExpression expression)
ConstantExpression
.expression
- The momentary visited expression.protected void atDivision(DivisionExpression expression)
DivisionExpression
.expression
- The momentary visited expression.protected void atExponentation(ExponentationExpression expression)
ExponentationExpression
.expression
- The momentary visited expression.protected void atExponentialFunction(ExponentialFunctionExpression expression)
ExponentialFunctionExpression
.expression
- The momentary visited expression.protected void atIfThenElse(IfThenElseExpression expression)
IfThenElseExpression
.expression
- The momentary visited expression.protected void atLogarithm(LogarithmExpression expression)
LogarithmExpression
.expression
- The momentary visited expression.protected void atNaturalLogarithm(NaturalLogarithmExpression expression)
NaturalLogarithmExpression
.expression
- The momentary visited expression.protected void atSine(SineExpression expression)
SineExpression
.expression
- The momentary visited expression.protected void atSubtraction(SubtractionExpression expression)
SubtractionExpression
.expression
- The momentary visited expression.protected void afterOther(EvaluableExpression expression)
EvaluableExpression
no hook was defined for. See
the class description for details.expression
- The momentary visited expression.protected void afterExpression(EvaluableExpression expression)
EvaluableExpression
. Contrary to
afterOther(EvaluableExpression)
, this hook will always be called, no
matter if an overridden specific hook exists for expression
.expression
- The momentarily visited expression.afterOther(EvaluableExpression)
protected void afterAddition(AdditionExpression expression)
AdditionExpression
.expression
- The momentary visited expression.protected void afterMultiplication(MultiplicationExpression expression)
MultiplicationExpression
.expression
- The momentary visited expression.protected void afterVariable(EvaluableVariable expression)
EvaluableVariable
.expression
- The momentary visited expression.protected void afterComparison(ComparisonExpression expression)
ComparisonExpression
.expression
- The momentary visited expression.protected void afterConstant(ConstantExpression expression)
ConstantExpression
.expression
- The momentary visited expression.protected void afterDivision(DivisionExpression expression)
DivisionExpression
.expression
- The momentary visited expression.protected void afterExponentation(ExponentationExpression expression)
ExponentationExpression
.expression
- The momentary visited expression.protected void afterExponentialFunction(ExponentialFunctionExpression expression)
ExponentialFunctionExpression
.expression
- The momentary visited expression.protected void afterIfThenElse(IfThenElseExpression expression)
IfThenElseExpression
.expression
- The momentary visited expression.protected void afterLogarithm(LogarithmExpression expression)
LogarithmExpression
.expression
- The momentary visited expression.protected void afterNaturalLogarithm(NaturalLogarithmExpression expression)
NaturalLogarithmExpression
.expression
- The momentary visited expression.protected void afterSine(SineExpression expression)
SineExpression
, after its inner expressions will be
visited.expression
- The momentary visited expression.protected void afterSubtraction(SubtractionExpression expression)
SubtractionExpression
.expression
- The momentary visited expression.