diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-01-10 16:21:35 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-01-10 16:21:35 +0000 |
| commit | 72cd9d3ef576c3bb9037b1692781a1b46297e998 (patch) | |
| tree | e30f02fd8229052834f0194e221ca0fd42d43745 /src/main/java/org/zwobble/couscous/ast/MethodCallNode.java | |
| parent | d3399a0cff620d13364331cc66a09d9304f21bb0 (diff) | |
Move operation static methods into their own class
Diffstat (limited to 'src/main/java/org/zwobble/couscous/ast/MethodCallNode.java')
| -rw-r--r-- | src/main/java/org/zwobble/couscous/ast/MethodCallNode.java | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/src/main/java/org/zwobble/couscous/ast/MethodCallNode.java b/src/main/java/org/zwobble/couscous/ast/MethodCallNode.java index 3bae839..b385eec 100644 --- a/src/main/java/org/zwobble/couscous/ast/MethodCallNode.java +++ b/src/main/java/org/zwobble/couscous/ast/MethodCallNode.java @@ -1,86 +1,14 @@ package org.zwobble.couscous.ast; import org.zwobble.couscous.ast.visitors.ExpressionNodeMapper; -import org.zwobble.couscous.values.BooleanValue; -import org.zwobble.couscous.values.IntegerValue; -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; public class MethodCallNode implements ExpressionNode { - public static ExpressionNode not(ExpressionNode value) { - if (value.getType().equals(BooleanValue.REF)) { - return methodCall(value, "negate", Collections.emptyList(), BooleanValue.REF); - } else { - throw new IllegalArgumentException("Can only negate booleans"); - } - } - - public static ExpressionNode booleanAnd(ExpressionNode left, ExpressionNode right) { - return booleanOperation(Operator.BOOLEAN_AND.getMethodName(), left, right); - } - - public static ExpressionNode booleanOr(ExpressionNode left, ExpressionNode right) { - return booleanOperation(Operator.BOOLEAN_OR.getMethodName(), left, right); - } - - public static ExpressionNode integerAdd(ExpressionNode left, ExpressionNode right) { - return integerOperation(Operator.ADD.getMethodName(), left, right); - } - - public static ExpressionNode integerSubtract(ExpressionNode left, ExpressionNode right) { - return integerOperation(Operator.SUBTRACT.getMethodName(), left, right); - } - - public static ExpressionNode integerMultiply(ExpressionNode left, ExpressionNode right) { - return integerOperation(Operator.MULTIPLY.getMethodName(), left, right); - } - - public static ExpressionNode integerDivide(ExpressionNode left, ExpressionNode right) { - return integerOperation(Operator.DIVIDE.getMethodName(), left, right); - } - - public static ExpressionNode integerMod(ExpressionNode left, ExpressionNode right) { - return integerOperation(Operator.MOD.getMethodName(), left, right); - } - - public static MethodCallNode integerOperation(String methodName, ExpressionNode left, ExpressionNode right) { - return methodCall(left, methodName, list(right), IntegerValue.REF); - } - - public static ExpressionNode equal(ExpressionNode left, ExpressionNode right) { - return booleanOperation(Operator.EQUALS.getMethodName(), left, right); - } - - public static ExpressionNode notEqual(ExpressionNode left, ExpressionNode right) { - return booleanOperation(Operator.NOT_EQUALS.getMethodName(), left, right); - } - - public static ExpressionNode greaterThan(ExpressionNode left, ExpressionNode right) { - return booleanOperation(Operator.GREATER_THAN.getMethodName(), left, right); - } - - public static ExpressionNode greaterThanOrEqual(ExpressionNode left, ExpressionNode right) { - return booleanOperation(Operator.GREATER_THAN_OR_EQUAL.getMethodName(), left, right); - } - - public static ExpressionNode lessThan(ExpressionNode left, ExpressionNode right) { - return booleanOperation(Operator.LESS_THAN.getMethodName(), left, right); - } - - public static ExpressionNode lessThanOrEqual(ExpressionNode left, ExpressionNode right) { - return booleanOperation(Operator.LESS_THAN_OR_EQUAL.getMethodName(), left, right); - } - - private static ExpressionNode booleanOperation(String methodName, ExpressionNode left, ExpressionNode right) { - return methodCall(left, methodName, list(right), BooleanValue.REF); - } - public static MethodCallNode methodCall( ExpressionNode receiver, String methodName, |
