From 51e8ff721cc7079212119ba44fcc4bf0f9818d1e Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 6 Dec 2015 11:20:51 +0000 Subject: Replace captured variable references in method bodies --- src/main/java/org/zwobble/couscous/ast/IfStatementNode.java | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/main/java/org/zwobble/couscous/ast/IfStatementNode.java') 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, @@ -42,6 +45,14 @@ public class IfStatementNode implements StatementNode { return visitor.visit(this); } + @Override + public StatementNode replaceExpressions(Function 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=" -- cgit v1.2.3