Skip to content

Commit

Permalink
Add comments explaining why we avoid some superclass methods in Scope…
Browse files Browse the repository at this point in the history
…TrackingClassCodeExpressionTransformer
  • Loading branch information
dwnusbaum committed Mar 20, 2023
1 parent 6c8ab91 commit b3af9f7
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def h() {
// When using Java-style for loops, the 3 expressions are a ClosureListExpression and ForStatement.getVariable is a dummy value that we need to ignore.
declareVariable(forLoop.getVariable());
}
// Avoid super.visitForLoop because it transforms the collection expression but then recurses on the entire
// ForStatement, causing the collection expression to be visited a second time.
forLoop.setCollectionExpression(transform(forLoop.getCollectionExpression()));
forLoop.getLoopBlock().visit(this);
}
Expand Down Expand Up @@ -138,6 +140,8 @@ public void visitSwitch(SwitchStatement statement) {

@Override
public void visitSynchronizedStatement(SynchronizedStatement sync) {
// Avoid super.visitSynchronizedStatement because it transforms the expression but then recurses on the entire
// SynchronizedStatement, causing the expression to be visited a second time.
sync.setExpression(transform(sync.getExpression()));
try (StackVariableSet scope = new StackVariableSet(this)) {
sync.getCode().visit(this);
Expand All @@ -161,6 +165,8 @@ public void visitCatchStatement(CatchStatement statement) {

@Override
public void visitWhileLoop(WhileStatement loop) {
// Avoid super.visitWhileLoop because it transforms the boolean expression but then recurses on the entire
// WhileStatement, causing the boolean expression to be visited a second time.
loop.setBooleanExpression((BooleanExpression) transform(loop.getBooleanExpression()));
try (StackVariableSet scope = new StackVariableSet(this)) {
loop.getLoopBlock().visit(this);
Expand Down

0 comments on commit b3af9f7

Please sign in to comment.