diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-12-06 11:20:51 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-12-06 11:20:51 +0000 |
| commit | 51e8ff721cc7079212119ba44fcc4bf0f9818d1e (patch) | |
| tree | 5075238f12957b80ac0b9a3adff5d547002e99b9 /src/main/java/org/zwobble/couscous/ast/IfStatementNode.java | |
| parent | 9ecc34a6884473feda3882c1339b29ac1a8c6557 (diff) | |
Replace captured variable references in method bodies
Diffstat (limited to 'src/main/java/org/zwobble/couscous/ast/IfStatementNode.java')
| -rw-r--r-- | src/main/java/org/zwobble/couscous/ast/IfStatementNode.java | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/couscous/ast/IfStatementNode.java b/src/main/java/org/zwobble/couscous/ast/IfStatementNode.java index ae3e29b..cb5eee8 100644 --- a/src/main/java/org/zwobble/couscous/ast/IfStatementNode.java +++ b/src/main/java/org/zwobble/couscous/ast/IfStatementNode.java @@ -1,9 +1,12 @@ package org.zwobble.couscous.ast; import java.util.List; +import java.util.function.Function; import org.zwobble.couscous.ast.visitors.StatementNodeMapper; +import static org.zwobble.couscous.util.ExtraLists.eagerMap; + public class IfStatementNode implements StatementNode { public static IfStatementNode ifStatement( ExpressionNode condition, @@ -43,6 +46,14 @@ public class IfStatementNode implements StatementNode { } @Override + public StatementNode replaceExpressions(Function<ExpressionNode, ExpressionNode> replace) { + return new IfStatementNode( + replace.apply(condition), + eagerMap(trueBranch, statement -> statement.replaceExpressions(replace)), + eagerMap(falseBranch, statement -> statement.replaceExpressions(replace))); + } + + @Override public String toString() { return "IfStatementNode(condition=" + condition + ", trueBranch=" + trueBranch + ", falseBranch=" + falseBranch + ")"; |
