From 1cca01d385e68aefe2131319c53c4811101f15f7 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 10 Jan 2016 16:12:32 +0000 Subject: Handle both static and instance method calls in one node --- .../org/zwobble/couscous/ast/MethodCallNode.java | 36 ++++++++++++++-------- 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'src/main/java/org/zwobble/couscous/ast/MethodCallNode.java') diff --git a/src/main/java/org/zwobble/couscous/ast/MethodCallNode.java b/src/main/java/org/zwobble/couscous/ast/MethodCallNode.java index efeee93..3bae839 100644 --- a/src/main/java/org/zwobble/couscous/ast/MethodCallNode.java +++ b/src/main/java/org/zwobble/couscous/ast/MethodCallNode.java @@ -8,6 +8,7 @@ import java.util.Collections; import java.util.List; import java.util.function.Function; +import static org.zwobble.couscous.ast.InstanceReceiver.instanceReceiver; import static org.zwobble.couscous.util.ExtraLists.eagerMap; import static org.zwobble.couscous.util.ExtraLists.list; @@ -81,30 +82,41 @@ public class MethodCallNode implements ExpressionNode { } public static MethodCallNode methodCall( - ExpressionNode receiver, - String methodName, - List arguments, - TypeName type) { + ExpressionNode receiver, + String methodName, + List arguments, + TypeName type) + { + return methodCall(instanceReceiver(receiver), methodName, arguments, type); + } + + public static MethodCallNode methodCall( + Receiver receiver, + String methodName, + List arguments, + TypeName type) + { return new MethodCallNode(receiver, methodName, arguments, type); } - private final ExpressionNode receiver; + private final Receiver receiver; private final String methodName; private final List arguments; private final TypeName type; - public MethodCallNode( - ExpressionNode receiver, - String methodName, - List arguments, - TypeName type) { + private MethodCallNode( + Receiver receiver, + String methodName, + List arguments, + TypeName type) + { this.receiver = receiver; this.methodName = methodName; this.arguments = arguments; this.type = type; } - public ExpressionNode getReceiver() { + public Receiver getReceiver() { return receiver; } @@ -132,7 +144,7 @@ public class MethodCallNode implements ExpressionNode { @Override public ExpressionNode replaceExpressions(Function replace) { return new MethodCallNode( - replace.apply(receiver), + receiver.replaceExpressions(replace), methodName, eagerMap(arguments, replace::apply), type); -- cgit v1.2.3