diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-10-25 19:18:09 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-10-25 19:34:44 +0000 |
| commit | 368f2dd010defaf5f4b6deb70f45285cee8f244d (patch) | |
| tree | 55494f85341f23dd1e588fa070ef863ef7cfdef5 /src/main/java/org/zwobble/couscous/interpreter | |
| parent | 060ae04a695df6abac7445df3c5394b59da40f41 (diff) | |
Remove lombok
Diffstat (limited to 'src/main/java/org/zwobble/couscous/interpreter')
25 files changed, 776 insertions, 444 deletions
diff --git a/src/main/java/org/zwobble/couscous/interpreter/ConditionMustBeBoolean.java b/src/main/java/org/zwobble/couscous/interpreter/ConditionMustBeBoolean.java index 7f2e901..b9cf32a 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/ConditionMustBeBoolean.java +++ b/src/main/java/org/zwobble/couscous/interpreter/ConditionMustBeBoolean.java @@ -2,13 +2,45 @@ package org.zwobble.couscous.interpreter; import org.zwobble.couscous.interpreter.values.InterpreterValue; -import lombok.EqualsAndHashCode; -import lombok.Value; - -@Value -@EqualsAndHashCode(callSuper=false) -public class ConditionMustBeBoolean extends InterpreterException { +public final class ConditionMustBeBoolean extends InterpreterException { private static final long serialVersionUID = 1L; + private final InterpreterValue actual; + + public ConditionMustBeBoolean(final InterpreterValue actual) { + this.actual = actual; + } + + public InterpreterValue getActual() { + return this.actual; + } + + @java.lang.Override + public java.lang.String toString() { + return "ConditionMustBeBoolean(actual=" + this.getActual() + ")"; + } + + @java.lang.Override + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof ConditionMustBeBoolean)) return false; + final ConditionMustBeBoolean other = (ConditionMustBeBoolean)o; + if (!other.canEqual((java.lang.Object)this)) return false; + final java.lang.Object this$actual = this.getActual(); + final java.lang.Object other$actual = other.getActual(); + if (this$actual == null ? other$actual != null : !this$actual.equals(other$actual)) return false; + return true; + } + + protected boolean canEqual(final java.lang.Object other) { + return other instanceof ConditionMustBeBoolean; + } - InterpreterValue actual; -} + @java.lang.Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $actual = this.getActual(); + result = result * PRIME + ($actual == null ? 43 : $actual.hashCode()); + return result; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/Environment.java b/src/main/java/org/zwobble/couscous/interpreter/Environment.java index 675cfda..b1d59e2 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/Environment.java +++ b/src/main/java/org/zwobble/couscous/interpreter/Environment.java @@ -2,33 +2,22 @@ package org.zwobble.couscous.interpreter; import java.util.Map; import java.util.Optional; - import org.zwobble.couscous.ast.TypeName; import org.zwobble.couscous.ast.VariableDeclaration; import org.zwobble.couscous.ast.VariableNode; import org.zwobble.couscous.interpreter.values.ConcreteType; import org.zwobble.couscous.interpreter.values.InterpreterValue; - import static java.util.stream.Collectors.toMap; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import lombok.val; - public class Environment { private final Project project; private final Optional<InterpreterValue> thisValue; private final Map<String, VariableEntry> stackFrame; - - public Environment( - Project project, - Optional<InterpreterValue> thisValue, - Map<VariableDeclaration, Optional<InterpreterValue>> stackFrame) { + + public Environment(Project project, Optional<InterpreterValue> thisValue, Map<VariableDeclaration, Optional<InterpreterValue>> stackFrame) { this.project = project; this.thisValue = thisValue; - this.stackFrame = stackFrame.entrySet() - .stream() + this.stackFrame = stackFrame.entrySet().stream() .collect(toMap( entry -> entry.getKey().getId(), entry -> VariableEntry.of(entry.getKey().getType(), entry.getValue()))); @@ -37,47 +26,65 @@ public class Environment { public Optional<InterpreterValue> getThis() { return thisValue; } - + public InterpreterValue get(String variableId) { checkVariableIsInScope(variableId); - val entry = stackFrame.get(variableId); + final org.zwobble.couscous.interpreter.Environment.VariableEntry entry = stackFrame.get(variableId); return entry.getValue().orElseThrow(() -> new UnboundVariable(variableId)); } - + public void put(String variableId, InterpreterValue value) { checkVariableIsInScope(variableId); checkVariableType(variableId, value); stackFrame.get(variableId).setValue(Optional.of(value)); } - + public void put(VariableNode variable, InterpreterValue value) { put(variable.getDeclaration().getId(), value); } - + public ConcreteType findClass(TypeName className) { return project.findClass(className); } - + public Environment withStackFrame(Optional<InterpreterValue> thisValue, Map<VariableDeclaration, Optional<InterpreterValue>> stackFrame) { return new Environment(project, thisValue, stackFrame); } - + private void checkVariableIsInScope(String variableId) { if (!stackFrame.containsKey(variableId)) { throw new VariableNotInScope(variableId); } } - + private void checkVariableType(String variableId, InterpreterValue value) { - val variableType = stackFrame.get(variableId).getType(); + TypeName variableType = stackFrame.get(variableId).getType(); InterpreterTypes.checkIsInstance(variableType, value); } - @AllArgsConstructor(staticName="of") - @Getter - @Setter private static class VariableEntry { private final TypeName type; private Optional<InterpreterValue> value; + + private VariableEntry(final TypeName type, final Optional<InterpreterValue> value) { + this.type = type; + this.value = value; + } + + public static VariableEntry of(final TypeName type, final Optional<InterpreterValue> value) { + return new VariableEntry(type, value); + } + + public TypeName getType() { + return this.type; + } + + public Optional<InterpreterValue> getValue() { + return this.value; + } + + public void setValue(final Optional<InterpreterValue> value) { + this.value = value; + } } -} +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/Evaluator.java b/src/main/java/org/zwobble/couscous/interpreter/Evaluator.java index 1bc1ab8..2122f01 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/Evaluator.java +++ b/src/main/java/org/zwobble/couscous/interpreter/Evaluator.java @@ -2,7 +2,6 @@ package org.zwobble.couscous.interpreter; import java.util.List; import java.util.stream.Collectors; - import org.zwobble.couscous.ast.AssignmentNode; import org.zwobble.couscous.ast.ConstructorCallNode; import org.zwobble.couscous.ast.ExpressionNode; @@ -16,18 +15,17 @@ import org.zwobble.couscous.ast.VariableReferenceNode; import org.zwobble.couscous.ast.visitors.AssignableExpressionNodeVisitor; import org.zwobble.couscous.ast.visitors.ExpressionNodeMapper; import org.zwobble.couscous.interpreter.values.BooleanInterpreterValue; +import org.zwobble.couscous.interpreter.values.ConcreteType; import org.zwobble.couscous.interpreter.values.InterpreterValue; import org.zwobble.couscous.interpreter.values.InterpreterValues; -import lombok.val; - public class Evaluator implements ExpressionNodeMapper<InterpreterValue> { public static InterpreterValue eval(Environment environment, ExpressionNode expression) { return new Evaluator(environment).eval(expression); } private final Environment environment; - + private Evaluator(Environment environment) { this.environment = environment; } @@ -35,29 +33,29 @@ public class Evaluator implements ExpressionNodeMapper<InterpreterValue> { public InterpreterValue eval(ExpressionNode expression) { return expression.accept(this); } - + @Override public InterpreterValue visit(LiteralNode literal) { return InterpreterValues.value(literal.getValue()); } - + @Override public InterpreterValue visit(VariableReferenceNode variableReference) { return environment.get(variableReference.getReferentId()); } - + @Override public InterpreterValue visit(ThisReferenceNode reference) { return environment.getThis().get(); } - + @Override public InterpreterValue visit(AssignmentNode assignment) { - val value = eval(assignment.getValue()); - assignment.getTarget().accept(new AssignableExpressionNodeVisitor() { + InterpreterValue value = eval(assignment.getValue()); + assignment.getTarget().accept(new AssignableExpressionNodeVisitor(){ @Override public void visit(FieldAccessNode fieldAccess) { - val left = eval(fieldAccess.getLeft()); + InterpreterValue left = eval(fieldAccess.getLeft()); left.setField(fieldAccess.getFieldName(), value); } @@ -68,51 +66,48 @@ public class Evaluator implements ExpressionNodeMapper<InterpreterValue> { }); return value; } - + @Override public InterpreterValue visit(TernaryConditionalNode ternaryConditional) { - val condition = eval(ternaryConditional.getCondition()); + InterpreterValue condition = eval(ternaryConditional.getCondition()); if (!(condition instanceof BooleanInterpreterValue)) { throw new ConditionMustBeBoolean(condition); } - val branch = ((BooleanInterpreterValue)condition).getValue() - ? ternaryConditional.getIfTrue() - : ternaryConditional.getIfFalse(); + final org.zwobble.couscous.ast.ExpressionNode branch = ((BooleanInterpreterValue)condition).getValue() ? ternaryConditional.getIfTrue() : ternaryConditional.getIfFalse(); return eval(branch); } - + @Override public InterpreterValue visit(MethodCallNode methodCall) { - val receiver = eval(methodCall.getReceiver()); - val type = receiver.getType(); - val arguments = evalArguments(methodCall.getArguments()); + InterpreterValue receiver = eval(methodCall.getReceiver()); + ConcreteType type = receiver.getType(); + List<InterpreterValue> arguments = evalArguments(methodCall.getArguments()); return type.callMethod(environment, receiver, methodCall.getMethodName(), arguments); } - + @Override public InterpreterValue visit(StaticMethodCallNode staticMethodCall) { - val clazz = environment.findClass(staticMethodCall.getClassName()); - val arguments = evalArguments(staticMethodCall.getArguments()); + ConcreteType clazz = environment.findClass(staticMethodCall.getClassName()); + List<InterpreterValue> arguments = evalArguments(staticMethodCall.getArguments()); return clazz.callStaticMethod(environment, staticMethodCall.getMethodName(), arguments); } - + @Override public InterpreterValue visit(ConstructorCallNode call) { - val clazz = environment.findClass(call.getType()); - val arguments = evalArguments(call.getArguments()); + ConcreteType clazz = environment.findClass(call.getType()); + List<InterpreterValue> arguments = evalArguments(call.getArguments()); return clazz.callConstructor(environment, arguments); } - + @Override public InterpreterValue visit(FieldAccessNode fieldAccess) { - val left = eval(fieldAccess.getLeft()); + InterpreterValue left = eval(fieldAccess.getLeft()); return left.getField(fieldAccess.getFieldName()); } - + private List<InterpreterValue> evalArguments(List<ExpressionNode> arguments) { - return arguments - .stream() + return arguments.stream() .map(argument -> eval(argument)) .collect(Collectors.toList()); } -} +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/Executor.java b/src/main/java/org/zwobble/couscous/interpreter/Executor.java index 5c26244..e47106d 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/Executor.java +++ b/src/main/java/org/zwobble/couscous/interpreter/Executor.java @@ -3,7 +3,6 @@ package org.zwobble.couscous.interpreter; import java.util.List; import java.util.Optional; import java.util.stream.Stream; - import org.zwobble.couscous.ast.CallableNode; import org.zwobble.couscous.ast.ExpressionStatementNode; import org.zwobble.couscous.ast.LocalVariableDeclarationNode; @@ -13,72 +12,55 @@ import org.zwobble.couscous.ast.VariableNode; import org.zwobble.couscous.ast.visitors.StatementNodeMapper; import org.zwobble.couscous.interpreter.values.InterpreterValue; import org.zwobble.couscous.interpreter.values.UnitInterpreterValue; - import static org.zwobble.couscous.interpreter.Evaluator.eval; -import lombok.val; - public class Executor implements StatementNodeMapper<Optional<InterpreterValue>> { - public static InterpreterValue callMethod( - Environment environment, - CallableNode method, - Optional<InterpreterValue> thisValue, - PositionalArguments arguments) { - - val innerEnvironment = buildEnvironment(environment, method, thisValue, arguments); - - for (val statement : method.getBody()) { - val result = exec(innerEnvironment, statement); + + public static InterpreterValue callMethod(Environment environment, CallableNode method, Optional<InterpreterValue> thisValue, PositionalArguments arguments) { + final org.zwobble.couscous.interpreter.Environment innerEnvironment = buildEnvironment(environment, method, thisValue, arguments); + for (final org.zwobble.couscous.ast.StatementNode statement : method.getBody()) { + final java.util.Optional<org.zwobble.couscous.interpreter.values.InterpreterValue> result = exec(innerEnvironment, statement); if (result.isPresent()) { return result.get(); } } return UnitInterpreterValue.UNIT; } - - private static Environment buildEnvironment( - final Environment environment, - final CallableNode method, - Optional<InterpreterValue> thisValue, - PositionalArguments arguments) { - - val stackFrame = new StackFrameBuilder(); + + private static Environment buildEnvironment(final Environment environment, final CallableNode method, Optional<InterpreterValue> thisValue, PositionalArguments arguments) { + final org.zwobble.couscous.interpreter.StackFrameBuilder stackFrame = new StackFrameBuilder(); for (int index = 0; index < method.getArguments().size(); index++) { stackFrame.declare(method.getArguments().get(index), arguments.get(index)); } - - findDeclarations(method.getBody()).forEach(declaration -> - stackFrame.declare(declaration)); - + findDeclarations(method.getBody()).forEach(declaration -> stackFrame.declare(declaration)); return environment.withStackFrame(thisValue, stackFrame.build()); } private static Stream<VariableNode> findDeclarations(List<StatementNode> body) { - return body.stream() - .flatMap(statement -> statement.accept(new StatementNodeMapper<Stream<VariableNode>>() { - @Override - public Stream<VariableNode> visit(ReturnNode returnNode) { - return Stream.empty(); - } - - @Override - public Stream<VariableNode> visit(ExpressionStatementNode expressionStatement) { - return Stream.empty(); - } - - @Override - public Stream<VariableNode> visit(LocalVariableDeclarationNode localVariableDeclaration) { - return Stream.of(localVariableDeclaration); - } - })); + return body.stream().flatMap(statement -> statement.accept(new StatementNodeMapper<Stream<VariableNode>>(){ + + @Override + public Stream<VariableNode> visit(ReturnNode returnNode) { + return Stream.empty(); + } + + @Override + public Stream<VariableNode> visit(ExpressionStatementNode expressionStatement) { + return Stream.empty(); + } + + @Override + public Stream<VariableNode> visit(LocalVariableDeclarationNode localVariableDeclaration) { + return Stream.of(localVariableDeclaration); + } + })); } - + public static Optional<InterpreterValue> exec(Environment environment, StatementNode statement) { return statement.accept(new Executor(environment)); } - private final Environment environment; - + private Executor(Environment environment) { this.environment = environment; } @@ -87,17 +69,17 @@ public class Executor implements StatementNodeMapper<Optional<InterpreterValue>> public Optional<InterpreterValue> visit(ReturnNode returnNode) { return Optional.of(eval(environment, returnNode.getValue())); } - + @Override public Optional<InterpreterValue> visit(ExpressionStatementNode expressionStatement) { eval(environment, expressionStatement.getExpression()); return Optional.empty(); } - + @Override public Optional<InterpreterValue> visit(LocalVariableDeclarationNode localVariableDeclaration) { - val value = eval(environment, localVariableDeclaration.getInitialValue()); + final org.zwobble.couscous.interpreter.values.InterpreterValue value = eval(environment, localVariableDeclaration.getInitialValue()); environment.put(localVariableDeclaration, value); return Optional.empty(); } -} +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/Interpreter.java b/src/main/java/org/zwobble/couscous/interpreter/Interpreter.java index 0506a59..e5f6482 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/Interpreter.java +++ b/src/main/java/org/zwobble/couscous/interpreter/Interpreter.java @@ -3,32 +3,30 @@ package org.zwobble.couscous.interpreter; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; - import org.zwobble.couscous.ast.TypeName; import org.zwobble.couscous.ast.ExpressionNode; import org.zwobble.couscous.interpreter.values.InterpreterValue; - import com.google.common.collect.ImmutableMap; - import static org.zwobble.couscous.ast.LiteralNode.literal; import static org.zwobble.couscous.ast.StaticMethodCallNode.staticMethodCall; import static org.zwobble.couscous.interpreter.Evaluator.eval; -import lombok.val; - public class Interpreter { private Project project; - + public Interpreter(Project project) { this.project = project; } public InterpreterValue run(TypeName className, String methodName, List<InterpreterValue> arguments) { - val argumentExpressions = arguments - .stream() - .<ExpressionNode>map(argument -> literal(argument.toPrimitiveValue().get())) + List<ExpressionNode> argumentExpressions = arguments.stream() + .map(argument -> literal(argument.toPrimitiveValue().get())) .collect(Collectors.toList()); - return eval(new Environment(project, Optional.empty(), ImmutableMap.of()), + return eval( + new Environment( + project, + Optional.empty(), + ImmutableMap.of()), staticMethodCall(className, methodName, argumentExpressions)); } -} +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/JavaProject.java b/src/main/java/org/zwobble/couscous/interpreter/JavaProject.java index fd01053..e6b6df1 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/JavaProject.java +++ b/src/main/java/org/zwobble/couscous/interpreter/JavaProject.java @@ -8,8 +8,6 @@ import org.zwobble.couscous.interpreter.values.ConcreteType; import com.google.common.collect.Iterables; -import lombok.val; - public class JavaProject { public static MapBackedProject.Builder builder() { return MapBackedProject.builder() @@ -17,7 +15,7 @@ public class JavaProject { } public static Project of(List<ClassNode> classNodes) { - val concreteTypes = Iterables.transform(classNodes, ConcreteType::fromNode); + Iterable<ConcreteType> concreteTypes = Iterables.transform(classNodes, ConcreteType::fromNode); return builder() .addClasses(concreteTypes) .build(); diff --git a/src/main/java/org/zwobble/couscous/interpreter/MapBackedProject.java b/src/main/java/org/zwobble/couscous/interpreter/MapBackedProject.java index 7206b1a..7f16b8f 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/MapBackedProject.java +++ b/src/main/java/org/zwobble/couscous/interpreter/MapBackedProject.java @@ -1,15 +1,12 @@ package org.zwobble.couscous.interpreter; import java.util.Map; - import org.zwobble.couscous.ast.TypeName; import org.zwobble.couscous.interpreter.values.ConcreteType; - import com.google.common.collect.ImmutableMap; -import lombok.val; - public class MapBackedProject implements Project { + public static Builder builder() { return new Builder(); } @@ -27,7 +24,7 @@ public class MapBackedProject implements Project { } public Builder addClasses(Iterable<ConcreteType> classes) { - for (val clazz : classes) { + for (ConcreteType clazz : classes) { addClass(clazz); } return this; @@ -37,9 +34,8 @@ public class MapBackedProject implements Project { return new MapBackedProject(classes.build()); } } - private Map<TypeName, ConcreteType> classes; - + public MapBackedProject(Map<TypeName, ConcreteType> classes) { this.classes = classes; } @@ -47,10 +43,9 @@ public class MapBackedProject implements Project { @Override public ConcreteType findClass(TypeName name) { if (classes.containsKey(name)) { - return classes.get(name); + return classes.get(name); } else { throw new IllegalArgumentException("Cannot find class: " + name); } - } -} +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/NoSuchField.java b/src/main/java/org/zwobble/couscous/interpreter/NoSuchField.java index 31feaab..03b714f 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/NoSuchField.java +++ b/src/main/java/org/zwobble/couscous/interpreter/NoSuchField.java @@ -1,12 +1,43 @@ package org.zwobble.couscous.interpreter; -import lombok.EqualsAndHashCode; -import lombok.Value; - -@Value -@EqualsAndHashCode(callSuper=false) -public class NoSuchField extends InterpreterException { +public final class NoSuchField extends InterpreterException { private static final long serialVersionUID = 1L; + private final String fieldName; + + public NoSuchField(final String fieldName) { + this.fieldName = fieldName; + } + + public String getFieldName() { + return this.fieldName; + } + + public java.lang.String toString() { + return "NoSuchField(fieldName=" + this.getFieldName() + ")"; + } + + @java.lang.Override + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof NoSuchField)) return false; + final NoSuchField other = (NoSuchField)o; + if (!other.canEqual((java.lang.Object)this)) return false; + final java.lang.Object this$fieldName = this.getFieldName(); + final java.lang.Object other$fieldName = other.getFieldName(); + if (this$fieldName == null ? other$fieldName != null : !this$fieldName.equals(other$fieldName)) return false; + return true; + } + + protected boolean canEqual(final java.lang.Object other) { + return other instanceof NoSuchField; + } - String fieldName; -} + @java.lang.Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $fieldName = this.getFieldName(); + result = result * PRIME + ($fieldName == null ? 43 : $fieldName.hashCode()); + return result; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/NoSuchMethod.java b/src/main/java/org/zwobble/couscous/interpreter/NoSuchMethod.java index e69c978..ddddd71 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/NoSuchMethod.java +++ b/src/main/java/org/zwobble/couscous/interpreter/NoSuchMethod.java @@ -1,12 +1,44 @@ package org.zwobble.couscous.interpreter; -import lombok.EqualsAndHashCode; -import lombok.Value; - -@Value -@EqualsAndHashCode(callSuper=false) -public class NoSuchMethod extends InterpreterException { +public final class NoSuchMethod extends InterpreterException { private static final long serialVersionUID = 1L; + private final String methodName; + + public NoSuchMethod(final String methodName) { + this.methodName = methodName; + } + + public String getMethodName() { + return this.methodName; + } + + @java.lang.Override + public java.lang.String toString() { + return "NoSuchMethod(methodName=" + this.getMethodName() + ")"; + } + + @java.lang.Override + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof NoSuchMethod)) return false; + final NoSuchMethod other = (NoSuchMethod)o; + if (!other.canEqual((java.lang.Object)this)) return false; + final java.lang.Object this$methodName = this.getMethodName(); + final java.lang.Object other$methodName = other.getMethodName(); + if (this$methodName == null ? other$methodName != null : !this$methodName.equals(other$methodName)) return false; + return true; + } + + protected boolean canEqual(final java.lang.Object other) { + return other instanceof NoSuchMethod; + } - String methodName; -} + @java.lang.Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $methodName = this.getMethodName(); + result = result * PRIME + ($methodName == null ? 43 : $methodName.hashCode()); + return result; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/UnboundField.java b/src/main/java/org/zwobble/couscous/interpreter/UnboundField.java index 2efca06..1d21071 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/UnboundField.java +++ b/src/main/java/org/zwobble/couscous/interpreter/UnboundField.java @@ -1,12 +1,44 @@ package org.zwobble.couscous.interpreter; -import lombok.EqualsAndHashCode; -import lombok.Value; - -@Value -@EqualsAndHashCode(callSuper=false) -public class UnboundField extends InterpreterException { +public final class UnboundField extends InterpreterException { private static final long serialVersionUID = 1L; + private final String fieldName; + + public UnboundField(final String fieldName) { + this.fieldName = fieldName; + } + + public String getFieldName() { + return this.fieldName; + } + + @java.lang.Override + public java.lang.String toString() { + return "UnboundField(fieldName=" + this.getFieldName() + ")"; + } + + @java.lang.Override + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof UnboundField)) return false; + final UnboundField other = (UnboundField)o; + if (!other.canEqual((java.lang.Object)this)) return false; + final java.lang.Object this$fieldName = this.getFieldName(); + final java.lang.Object other$fieldName = other.getFieldName(); + if (this$fieldName == null ? other$fieldName != null : !this$fieldName.equals(other$fieldName)) return false; + return true; + } + + protected boolean canEqual(final java.lang.Object other) { + return other instanceof UnboundField; + } - String fieldName; -} + @java.lang.Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $fieldName = this.getFieldName(); + result = result * PRIME + ($fieldName == null ? 43 : $fieldName.hashCode()); + return result; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/UnboundVariable.java b/src/main/java/org/zwobble/couscous/interpreter/UnboundVariable.java index 684a3b9..e0131f0 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/UnboundVariable.java +++ b/src/main/java/org/zwobble/couscous/interpreter/UnboundVariable.java @@ -1,12 +1,44 @@ package org.zwobble.couscous.interpreter; -import lombok.EqualsAndHashCode; -import lombok.Value; - -@Value -@EqualsAndHashCode(callSuper=false) -public class UnboundVariable extends InterpreterException { +public final class UnboundVariable extends InterpreterException { private static final long serialVersionUID = 1L; + private final String variableId; + + public UnboundVariable(final String variableId) { + this.variableId = variableId; + } + + public String getVariableId() { + return this.variableId; + } + + @java.lang.Override + public java.lang.String toString() { + return "UnboundVariable(variableId=" + this.getVariableId() + ")"; + } + + @java.lang.Override + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof UnboundVariable)) return false; + final UnboundVariable other = (UnboundVariable)o; + if (!other.canEqual((java.lang.Object)this)) return false; + final java.lang.Object this$variableId = this.getVariableId(); + final java.lang.Object other$variableId = other.getVariableId(); + if (this$variableId == null ? other$variableId != null : !this$variableId.equals(other$variableId)) return false; + return true; + } + + protected boolean canEqual(final java.lang.Object other) { + return other instanceof UnboundVariable; + } - String variableId; -} + @java.lang.Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $variableId = this.getVariableId(); + result = result * PRIME + ($variableId == null ? 43 : $variableId.hashCode()); + return result; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/UnexpectedValueType.java b/src/main/java/org/zwobble/couscous/interpreter/UnexpectedValueType.java index 827b9e9..2b40728 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/UnexpectedValueType.java +++ b/src/main/java/org/zwobble/couscous/interpreter/UnexpectedValueType.java @@ -2,14 +2,56 @@ package org.zwobble.couscous.interpreter; import org.zwobble.couscous.ast.TypeName; -import lombok.EqualsAndHashCode; -import lombok.Value; - -@Value -@EqualsAndHashCode(callSuper=false) -public class UnexpectedValueType extends InterpreterException { +public final class UnexpectedValueType extends InterpreterException { private static final long serialVersionUID = 1L; + private final TypeName expected; + private final TypeName actual; + + public UnexpectedValueType(final TypeName expected, final TypeName actual) { + this.expected = expected; + this.actual = actual; + } + + public TypeName getExpected() { + return this.expected; + } + + public TypeName getActual() { + return this.actual; + } + + @java.lang.Override + public java.lang.String toString() { + return "UnexpectedValueType(expected=" + this.getExpected() + ", actual=" + this.getActual() + ")"; + } + + @java.lang.Override + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof UnexpectedValueType)) return false; + final UnexpectedValueType other = (UnexpectedValueType)o; + if (!other.canEqual((java.lang.Object)this)) return false; + final java.lang.Object this$expected = this.getExpected(); + final java.lang.Object other$expected = other.getExpected(); + if (this$expected == null ? other$expected != null : !this$expected.equals(other$expected)) return false; + final java.lang.Object this$actual = this.getActual(); + final java.lang.Object other$actual = other.getActual(); + if (this$actual == null ? other$actual != null : !this$actual.equals(other$actual)) return false; + return true; + } + + protected boolean canEqual(final java.lang.Object other) { + return other instanceof UnexpectedValueType; + } - TypeName expected; - TypeName actual; -} + @java.lang.Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $expected = this.getExpected(); + result = result * PRIME + ($expected == null ? 43 : $expected.hashCode()); + final java.lang.Object $actual = this.getActual(); + result = result * PRIME + ($actual == null ? 43 : $actual.hashCode()); + return result; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/VariableNotInScope.java b/src/main/java/org/zwobble/couscous/interpreter/VariableNotInScope.java index 17ab6af..54b66bd 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/VariableNotInScope.java +++ b/src/main/java/org/zwobble/couscous/interpreter/VariableNotInScope.java @@ -1,12 +1,44 @@ package org.zwobble.couscous.interpreter; -import lombok.EqualsAndHashCode; -import lombok.Value; - -@Value -@EqualsAndHashCode(callSuper=false) -public class VariableNotInScope extends InterpreterException { +public final class VariableNotInScope extends InterpreterException { private static final long serialVersionUID = 1L; + private final String variableId; + + public VariableNotInScope(final String variableId) { + this.variableId = variableId; + } + + public String getVariableId() { + return this.variableId; + } + + @java.lang.Override + public java.lang.String toString() { + return "VariableNotInScope(variableId=" + this.getVariableId() + ")"; + } + + @java.lang.Override + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof VariableNotInScope)) return false; + final VariableNotInScope other = (VariableNotInScope)o; + if (!other.canEqual((java.lang.Object)this)) return false; + final java.lang.Object this$variableId = this.getVariableId(); + final java.lang.Object other$variableId = other.getVariableId(); + if (this$variableId == null ? other$variableId != null : !this$variableId.equals(other$variableId)) return false; + return true; + } + + protected boolean canEqual(final java.lang.Object other) { + return other instanceof VariableNotInScope; + } - String variableId; -} + @java.lang.Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $variableId = this.getVariableId(); + result = result * PRIME + ($variableId == null ? 43 : $variableId.hashCode()); + return result; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/WrongNumberOfArguments.java b/src/main/java/org/zwobble/couscous/interpreter/WrongNumberOfArguments.java index 06d8079..800aabb 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/WrongNumberOfArguments.java +++ b/src/main/java/org/zwobble/couscous/interpreter/WrongNumberOfArguments.java @@ -1,13 +1,49 @@ package org.zwobble.couscous.interpreter; -import lombok.EqualsAndHashCode; -import lombok.Value; - -@Value -@EqualsAndHashCode(callSuper=false) -public class WrongNumberOfArguments extends InterpreterException { +public final class WrongNumberOfArguments extends InterpreterException { private static final long serialVersionUID = 1L; + private final int expected; + private final int actual; + + public WrongNumberOfArguments(final int expected, final int actual) { + this.expected = expected; + this.actual = actual; + } + + public int getExpected() { + return this.expected; + } + + public int getActual() { + return this.actual; + } + + @java.lang.Override + public java.lang.String toString() { + return "WrongNumberOfArguments(expected=" + this.getExpected() + ", actual=" + this.getActual() + ")"; + } + + @java.lang.Override + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof WrongNumberOfArguments)) return false; + final WrongNumberOfArguments other = (WrongNumberOfArguments)o; + if (!other.canEqual((java.lang.Object)this)) return false; + if (this.getExpected() != other.getExpected()) return false; + if (this.getActual() != other.getActual()) return false; + return true; + } + + protected boolean canEqual(final java.lang.Object other) { + return other instanceof WrongNumberOfArguments; + } - int expected; - int actual; -} + @java.lang.Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + result = result * PRIME + this.getExpected(); + result = result * PRIME + this.getActual(); + return result; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/BooleanInterpreterValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/BooleanInterpreterValue.java index 7bb108c..8245f87 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/values/BooleanInterpreterValue.java +++ b/src/main/java/org/zwobble/couscous/interpreter/values/BooleanInterpreterValue.java @@ -1,44 +1,61 @@ package org.zwobble.couscous.interpreter.values; import java.util.Optional; - import org.zwobble.couscous.interpreter.NoSuchField; import org.zwobble.couscous.values.PrimitiveValue; import org.zwobble.couscous.values.PrimitiveValues; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.Value; - -@Value -public class BooleanInterpreterValue implements InterpreterValue { - private static final ConcreteType TYPE = ConcreteType.builder(BooleanInterpreterValue.class, "Boolean") - .build(); +public final class BooleanInterpreterValue implements InterpreterValue { + private static final ConcreteType TYPE = ConcreteType.builder(BooleanInterpreterValue.class, "Boolean").build(); + private final boolean value; - @Getter(value = AccessLevel.NONE) - boolean value; - public boolean getValue() { return value; } - + @Override public ConcreteType getType() { return TYPE; } - + @Override public Optional<PrimitiveValue> toPrimitiveValue() { return Optional.of(PrimitiveValues.value(value)); } - + @Override public InterpreterValue getField(String fieldName) { throw new NoSuchField(fieldName); } - + @Override public void setField(String fieldName, InterpreterValue value) { throw new NoSuchField(fieldName); } -} + + public BooleanInterpreterValue(final boolean value) { + this.value = value; + } + + @java.lang.Override + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof BooleanInterpreterValue)) return false; + final BooleanInterpreterValue other = (BooleanInterpreterValue)o; + if (this.getValue() != other.getValue()) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + result = result * PRIME + (this.getValue() ? 79 : 97); + return result; + } + + @java.lang.Override + public java.lang.String toString() { + return "BooleanInterpreterValue(value=" + this.getValue() + ")"; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/BoxedIntegerInterpreterValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/BoxedIntegerInterpreterValue.java index a6ba5e1..458eca7 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/values/BoxedIntegerInterpreterValue.java +++ b/src/main/java/org/zwobble/couscous/interpreter/values/BoxedIntegerInterpreterValue.java @@ -4,13 +4,11 @@ import org.zwobble.couscous.values.StringValue; import static java.util.Arrays.asList; -import lombok.val; - public class BoxedIntegerInterpreterValue { public static final ConcreteType TYPE = ConcreteType.classBuilder("java.lang.Integer") .staticMethod("parseInt", asList(StringValue.REF), (environment, arguments) -> { - val value = (StringInterpreterValue)arguments.get(0); + StringInterpreterValue value = (StringInterpreterValue)arguments.get(0); return new IntegerInterpreterValue(Integer.parseInt(value.getValue())); }) diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/ConcreteType.java b/src/main/java/org/zwobble/couscous/interpreter/values/ConcreteType.java index 2c64031..a61ec27 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/values/ConcreteType.java +++ b/src/main/java/org/zwobble/couscous/interpreter/values/ConcreteType.java @@ -5,7 +5,6 @@ import java.util.Map; import java.util.Optional; import java.util.function.BiFunction; import java.util.stream.Collectors; - import org.zwobble.couscous.ast.ClassNode; import org.zwobble.couscous.ast.FormalArgumentNode; import org.zwobble.couscous.ast.TypeName; @@ -16,32 +15,27 @@ import org.zwobble.couscous.interpreter.NoSuchMethod; import org.zwobble.couscous.interpreter.PositionalArguments; import org.zwobble.couscous.interpreter.WrongNumberOfArguments; import org.zwobble.couscous.util.Casts; - import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; - import static java.util.stream.Collectors.toMap; -import lombok.val; - public class ConcreteType { + public static <T> ConcreteType.Builder<T> builder(Class<T> interpreterValueType, TypeName reference) { return new Builder<>(interpreterValueType, reference); } - + public static <T> ConcreteType.Builder<T> builder(Class<T> interpreterValueType, String name) { return builder(interpreterValueType, TypeName.of(name)); } - + public static ConcreteType.Builder<ObjectInterpreterValue> classBuilder(String name) { return builder(ObjectInterpreterValue.class, name); } public static class Builder<T> { - private final ImmutableMap.Builder<String, MethodValue> methods = - ImmutableMap.builder(); - private final ImmutableMap.Builder<String, StaticMethodValue> staticMethods = - ImmutableMap.builder(); + private final ImmutableMap.Builder<String, MethodValue> methods = ImmutableMap.builder(); + private final ImmutableMap.Builder<String, StaticMethodValue> staticMethods = ImmutableMap.builder(); private final Class<T> interpreterValueType; private final TypeName name; @@ -50,112 +44,51 @@ public class ConcreteType { this.name = name; } - public Builder<T> method( - String name, - List<TypeName> argumentsTypes, - BiFunction<Environment, MethodCallArguments<T>, InterpreterValue> method) { + public Builder<T> method(String name, List<TypeName> argumentsTypes, BiFunction<Environment, MethodCallArguments<T>, InterpreterValue> method) { methods.put(name, new MethodValue(argumentsTypes, (environment, arguments) -> { - return Casts.tryCast(interpreterValueType, arguments.getReceiver()) - .map(typedReceiver -> - method.apply(environment, MethodCallArguments.of(typedReceiver, arguments.getPositionalArguments()))) - .orElseThrow(() -> new RuntimeException("receiver is of wrong type")); + return Casts.tryCast(interpreterValueType, arguments.getReceiver()).map(typedReceiver -> method.apply(environment, MethodCallArguments.of(typedReceiver, arguments.getPositionalArguments()))).orElseThrow(() -> new RuntimeException("receiver is of wrong type")); })); return this; } - public Builder<T> staticMethod( - String name, - List<TypeName> argumentsTypes, - BiFunction<Environment, PositionalArguments, InterpreterValue> method) { + public Builder<T> staticMethod(String name, List<TypeName> argumentsTypes, BiFunction<Environment, PositionalArguments, InterpreterValue> method) { staticMethods.put(name, new StaticMethodValue(argumentsTypes, method)); return this; } public ConcreteType build() { - return new ConcreteType( - name, - ImmutableMap.of(), - new MethodValue( - ImmutableList.of(), - (environment, arguments) -> InterpreterValues.UNIT), - methods.build(), - staticMethods.build()); + return new ConcreteType(name, ImmutableMap.of(), new MethodValue(ImmutableList.of(), (environment, arguments) -> InterpreterValues.UNIT), methods.build(), staticMethods.build()); } } public static ConcreteType fromNode(ClassNode classNode) { - val fields = classNode.getFields().stream() - .collect(toMap( - field -> field.getName(), - field -> new FieldValue(field.getName(), field.getType()))); - - val constructor = new MethodValue( - getArgumentTypes(classNode.getConstructor().getArguments()), - (environment, arguments) -> Executor.callMethod( - environment, - classNode.getConstructor(), - Optional.of(arguments.getReceiver()), - arguments.getPositionalArguments())); - - val methods = classNode.getMethods().stream() - .filter(method -> !method.isStatic()) - .collect(toMap( - method -> method.getName(), - method -> { - val argumentTypes = getArgumentTypes(method.getArguments()); - - return new MethodValue(argumentTypes, (environment, arguments) -> { - return Executor.callMethod( - environment, - method, - Optional.of(arguments.getReceiver()), - arguments.getPositionalArguments()); - }); - })); - - val staticMethods = classNode.getMethods() - .stream() - .filter(method -> method.isStatic()) - .collect(toMap( - method -> method.getName(), - method -> { - val argumentTypes = getArgumentTypes(method.getArguments()); - - return new StaticMethodValue(argumentTypes, (environment, arguments) -> { - return Executor.callMethod( - environment, - method, - Optional.empty(), - arguments); - }); - })); - return new ConcreteType( - classNode.getName(), - fields, - constructor, - methods, - staticMethods); + final java.util.Map<String, FieldValue> fields = classNode.getFields().stream().collect(toMap(field -> field.getName(), field -> new FieldValue(field.getName(), field.getType()))); + final org.zwobble.couscous.interpreter.values.MethodValue constructor = new MethodValue(getArgumentTypes(classNode.getConstructor().getArguments()), (environment, arguments) -> Executor.callMethod(environment, classNode.getConstructor(), Optional.of(arguments.getReceiver()), arguments.getPositionalArguments())); + final java.util.Map<String, MethodValue> methods = classNode.getMethods().stream().filter(method -> !method.isStatic()).collect(toMap(method -> method.getName(), method -> { + List<TypeName> argumentTypes = getArgumentTypes(method.getArguments()); + return new MethodValue(argumentTypes, (environment, arguments) -> { + return Executor.callMethod(environment, method, Optional.of(arguments.getReceiver()), arguments.getPositionalArguments()); + }); + })); + final java.util.Map<String, StaticMethodValue> staticMethods = classNode.getMethods().stream().filter(method -> method.isStatic()).collect(toMap(method -> method.getName(), method -> { + List<TypeName> argumentTypes = getArgumentTypes(method.getArguments()); + return new StaticMethodValue(argumentTypes, (environment, arguments) -> { + return Executor.callMethod(environment, method, Optional.empty(), arguments); + }); + })); + return new ConcreteType(classNode.getName(), fields, constructor, methods, staticMethods); } private static List<TypeName> getArgumentTypes(List<FormalArgumentNode> arguments) { - return arguments - .stream() - .map(arg -> arg.getType()) - .collect(Collectors.toList()); + return arguments.stream().map(arg -> arg.getType()).collect(Collectors.toList()); } - private final TypeName name; private final Map<String, FieldValue> fields; private final MethodValue constructor; private final Map<String, MethodValue> methods; private final Map<String, StaticMethodValue> staticMethods; - - public ConcreteType( - TypeName name, - Map<String, FieldValue> fields, - MethodValue constructor, - Map<String, MethodValue> methods, - Map<String, StaticMethodValue> staticMethods) { + + public ConcreteType(TypeName name, Map<String, FieldValue> fields, MethodValue constructor, Map<String, MethodValue> methods, Map<String, StaticMethodValue> staticMethods) { this.name = name; this.fields = fields; this.constructor = constructor; @@ -170,27 +103,21 @@ public class ConcreteType { public Optional<FieldValue> getField(String fieldName) { return Optional.ofNullable(fields.get(fieldName)); } - + public InterpreterValue callMethod(Environment environment, InterpreterValue receiver, String methodName, List<InterpreterValue> arguments) { - val method = findMethod(methods, methodName, arguments); - return method.apply( - environment, - MethodCallArguments.of(receiver, new PositionalArguments(arguments))); + final org.zwobble.couscous.interpreter.values.MethodValue method = findMethod(methods, methodName, arguments); + return method.apply(environment, MethodCallArguments.of(receiver, new PositionalArguments(arguments))); } - + public InterpreterValue callStaticMethod(Environment environment, String methodName, List<InterpreterValue> arguments) { - val method = findMethod(staticMethods, methodName, arguments); + final org.zwobble.couscous.interpreter.values.StaticMethodValue method = findMethod(staticMethods, methodName, arguments); return method.apply(environment, new PositionalArguments(arguments)); } - - public InterpreterValue callConstructor( - Environment environment, - List<InterpreterValue> arguments) { - val object = new ObjectInterpreterValue(this); + + public InterpreterValue callConstructor(Environment environment, List<InterpreterValue> arguments) { + final org.zwobble.couscous.interpreter.values.ObjectInterpreterValue object = new ObjectInterpreterValue(this); checkMethodArguments(constructor, arguments); - constructor.apply( - environment, - MethodCallArguments.of(object, new PositionalArguments(arguments))); + constructor.apply(environment, MethodCallArguments.of(object, new PositionalArguments(arguments))); return object; } @@ -198,20 +125,17 @@ public class ConcreteType { if (!methods.containsKey(methodName)) { throw new NoSuchMethod(methodName); } - val method = methods.get(methodName); + final T method = methods.get(methodName); checkMethodArguments(method, arguments); return method; } - - private static void checkMethodArguments( - final Callable method, - List<InterpreterValue> arguments) { + + private static void checkMethodArguments(final Callable method, List<InterpreterValue> arguments) { if (method.getArgumentTypes().size() != arguments.size()) { throw new WrongNumberOfArguments(method.getArgumentTypes().size(), arguments.size()); } - for (int index = 0; index < arguments.size(); index++) { - val formalArgumentType = method.getArgumentTypes().get(index); + final org.zwobble.couscous.ast.TypeName formalArgumentType = method.getArgumentTypes().get(index); InterpreterTypes.checkIsInstance(formalArgumentType, arguments.get(index)); } } @@ -220,4 +144,4 @@ public class ConcreteType { public String toString() { return "ConcreteType<" + name + ">"; } -} +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/FieldValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/FieldValue.java index d778144..4ee1c95 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/values/FieldValue.java +++ b/src/main/java/org/zwobble/couscous/interpreter/values/FieldValue.java @@ -2,10 +2,50 @@ package org.zwobble.couscous.interpreter.values; import org.zwobble.couscous.ast.TypeName; -import lombok.Value; +public final class FieldValue { + private final String name; + private final TypeName type; -@Value -public class FieldValue { - String name; - TypeName type; -} + public FieldValue(final String name, final TypeName type) { + this.name = name; + this.type = type; + } + + public String getName() { + return this.name; + } + + public TypeName getType() { + return this.type; + } + + @java.lang.Override + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof FieldValue)) return false; + final FieldValue other = (FieldValue)o; + final java.lang.Object this$name = this.getName(); + final java.lang.Object other$name = other.getName(); + if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false; + final java.lang.Object this$type = this.getType(); + final java.lang.Object other$type = other.getType(); + if (this$type == null ? other$type != null : !this$type.equals(other$type)) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $name = this.getName(); + result = result * PRIME + ($name == null ? 43 : $name.hashCode()); + final java.lang.Object $type = this.getType(); + result = result * PRIME + ($type == null ? 43 : $type.hashCode()); + return result; + } + + @java.lang.Override + public java.lang.String toString() { + return "FieldValue(name=" + this.getName() + ", type=" + this.getType() + ")"; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/IntegerInterpreterValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/IntegerInterpreterValue.java index 95b05aa..bd214cb 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/values/IntegerInterpreterValue.java +++ b/src/main/java/org/zwobble/couscous/interpreter/values/IntegerInterpreterValue.java @@ -1,48 +1,67 @@ package org.zwobble.couscous.interpreter.values; import java.util.Optional; - import org.zwobble.couscous.interpreter.NoSuchField; import org.zwobble.couscous.values.IntegerValue; import org.zwobble.couscous.values.PrimitiveValue; import org.zwobble.couscous.values.PrimitiveValues; import org.zwobble.couscous.values.StringValue; - import static java.util.Arrays.asList; -import lombok.Value; -import lombok.val; - -@Value -public class IntegerInterpreterValue implements InterpreterValue { - public static final ConcreteType TYPE = ConcreteType.builder(IntegerInterpreterValue.class, IntegerValue.REF) - .staticMethod("parseInt", asList(StringValue.REF), - (environment, arguments) -> { - val value = (StringInterpreterValue)arguments.get(0); - return new IntegerInterpreterValue(Integer.parseInt(value.getValue())); - }) - - .build(); - - int value; - +public final class IntegerInterpreterValue implements InterpreterValue { + public static final ConcreteType TYPE = ConcreteType.builder(IntegerInterpreterValue.class, IntegerValue.REF).staticMethod("parseInt", asList(StringValue.REF), (environment, arguments) -> { + StringInterpreterValue value = (StringInterpreterValue)arguments.get(0); + return new IntegerInterpreterValue(Integer.parseInt(value.getValue())); + }).build(); + private final int value; + @Override public ConcreteType getType() { return TYPE; } - + @Override public Optional<PrimitiveValue> toPrimitiveValue() { return Optional.of(PrimitiveValues.value(value)); } - + @Override public InterpreterValue getField(String fieldName) { throw new NoSuchField(fieldName); } - + @Override public void setField(String fieldName, InterpreterValue value) { throw new NoSuchField(fieldName); } -} + + public IntegerInterpreterValue(final int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } + + @java.lang.Override + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof IntegerInterpreterValue)) return false; + final IntegerInterpreterValue other = (IntegerInterpreterValue)o; + if (this.getValue() != other.getValue()) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + result = result * PRIME + this.getValue(); + return result; + } + + @java.lang.Override + public java.lang.String toString() { + return "IntegerInterpreterValue(value=" + this.getValue() + ")"; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/MethodCallArguments.java b/src/main/java/org/zwobble/couscous/interpreter/values/MethodCallArguments.java index 9f3e937..23af57f 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/values/MethodCallArguments.java +++ b/src/main/java/org/zwobble/couscous/interpreter/values/MethodCallArguments.java @@ -2,11 +2,6 @@ package org.zwobble.couscous.interpreter.values; import org.zwobble.couscous.interpreter.PositionalArguments; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@AllArgsConstructor(staticName="of") -@Getter public class MethodCallArguments<T> { private final T receiver; private final PositionalArguments positionalArguments; @@ -14,4 +9,21 @@ public class MethodCallArguments<T> { public InterpreterValue get(int index) { return positionalArguments.get(index); } -} + + private MethodCallArguments(final T receiver, final PositionalArguments positionalArguments) { + this.receiver = receiver; + this.positionalArguments = positionalArguments; + } + + public static <T> MethodCallArguments<T> of(final T receiver, final PositionalArguments positionalArguments) { + return new MethodCallArguments<T>(receiver, positionalArguments); + } + + public T getReceiver() { + return this.receiver; + } + + public PositionalArguments getPositionalArguments() { + return this.positionalArguments; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/MethodValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/MethodValue.java index b5068fc..81964fb 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/values/MethodValue.java +++ b/src/main/java/org/zwobble/couscous/interpreter/values/MethodValue.java @@ -2,21 +2,53 @@ package org.zwobble.couscous.interpreter.values; import java.util.List; import java.util.function.BiFunction; - import org.zwobble.couscous.ast.TypeName; import org.zwobble.couscous.interpreter.Environment; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.Value; - -@Value -public class MethodValue implements Callable { - List<TypeName> argumentTypes; - @Getter(value=AccessLevel.NONE) - BiFunction<Environment, MethodCallArguments<InterpreterValue>, InterpreterValue> apply; +public final class MethodValue implements Callable { + private final List<TypeName> argumentTypes; + private final BiFunction<Environment, MethodCallArguments<InterpreterValue>, InterpreterValue> apply; public InterpreterValue apply(Environment environment, MethodCallArguments<InterpreterValue> arguments) { return apply.apply(environment, arguments); } -} + + public MethodValue(final List<TypeName> argumentTypes, final BiFunction<Environment, MethodCallArguments<InterpreterValue>, InterpreterValue> apply) { + this.argumentTypes = argumentTypes; + this.apply = apply; + } + + public List<TypeName> getArgumentTypes() { + return this.argumentTypes; + } + + @java.lang.Override + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof MethodValue)) return false; + final MethodValue other = (MethodValue)o; + final java.lang.Object this$argumentTypes = this.getArgumentTypes(); + final java.lang.Object other$argumentTypes = other.getArgumentTypes(); + if (this$argumentTypes == null ? other$argumentTypes != null : !this$argumentTypes.equals(other$argumentTypes)) return false; + final java.lang.Object this$apply = this.apply; + final java.lang.Object other$apply = other.apply; + if (this$apply == null ? other$apply != null : !this$apply.equals(other$apply)) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $argumentTypes = this.getArgumentTypes(); + result = result * PRIME + ($argumentTypes == null ? 43 : $argumentTypes.hashCode()); + final java.lang.Object $apply = this.apply; + result = result * PRIME + ($apply == null ? 43 : $apply.hashCode()); + return result; + } + + @java.lang.Override + public java.lang.String toString() { + return "MethodValue(argumentTypes=" + this.getArgumentTypes() + ", apply=" + this.apply + ")"; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/ObjectInterpreterValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/ObjectInterpreterValue.java index b248398..bebd5f7 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/values/ObjectInterpreterValue.java +++ b/src/main/java/org/zwobble/couscous/interpreter/values/ObjectInterpreterValue.java @@ -3,18 +3,15 @@ package org.zwobble.couscous.interpreter.values; import java.util.HashMap; import java.util.Map; import java.util.Optional; - import org.zwobble.couscous.interpreter.InterpreterTypes; import org.zwobble.couscous.interpreter.NoSuchField; import org.zwobble.couscous.interpreter.UnboundField; import org.zwobble.couscous.values.PrimitiveValue; -import lombok.val; - public class ObjectInterpreterValue implements InterpreterValue { private final ConcreteType type; private final Map<String, InterpreterValue> fields; - + public ObjectInterpreterValue(ConcreteType type) { this.type = type; this.fields = new HashMap<>(); @@ -24,26 +21,27 @@ public class ObjectInterpreterValue implements InterpreterValue { public ConcreteType getType() { return type; } - + @Override public Optional<PrimitiveValue> toPrimitiveValue() { return Optional.empty(); } - + @Override public InterpreterValue getField(String fieldName) { type.getField(fieldName).orElseThrow(() -> new NoSuchField(fieldName)); if (fields.containsKey(fieldName)) { - return fields.get(fieldName); + return fields.get(fieldName); } else { throw new UnboundField(fieldName); } } - + @Override public void setField(String fieldName, InterpreterValue value) { - val field = type.getField(fieldName).orElseThrow(() -> new NoSuchField(fieldName)); + FieldValue field = type.getField(fieldName) + .orElseThrow(() -> new NoSuchField(fieldName)); InterpreterTypes.checkIsInstance(field.getType(), value); - fields.put(fieldName, value); + fields.put(fieldName, value); } -} +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/StaticMethodValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/StaticMethodValue.java index 37f3c56..302582c 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/values/StaticMethodValue.java +++ b/src/main/java/org/zwobble/couscous/interpreter/values/StaticMethodValue.java @@ -2,23 +2,54 @@ package org.zwobble.couscous.interpreter.values; import java.util.List; import java.util.function.BiFunction; - import org.zwobble.couscous.ast.TypeName; import org.zwobble.couscous.interpreter.PositionalArguments; import org.zwobble.couscous.interpreter.Environment; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.Value; - -@Value -public class StaticMethodValue implements Callable { - List<TypeName> argumentTypes; - @Getter(value=AccessLevel.NONE) - BiFunction<Environment, PositionalArguments, InterpreterValue> apply; +public final class StaticMethodValue implements Callable { + private final List<TypeName> argumentTypes; + private final BiFunction<Environment, PositionalArguments, InterpreterValue> apply; public InterpreterValue apply(Environment environment, PositionalArguments arguments) { return apply.apply(environment, arguments); } - -} + + public StaticMethodValue(final List<TypeName> argumentTypes, final BiFunction<Environment, PositionalArguments, InterpreterValue> apply) { + this.argumentTypes = argumentTypes; + this.apply = apply; + } + + public List<TypeName> getArgumentTypes() { + return this.argumentTypes; + } + + @java.lang.Override + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof StaticMethodValue)) return false; + final StaticMethodValue other = (StaticMethodValue)o; + final java.lang.Object this$argumentTypes = this.getArgumentTypes(); + final java.lang.Object other$argumentTypes = other.getArgumentTypes(); + if (this$argumentTypes == null ? other$argumentTypes != null : !this$argumentTypes.equals(other$argumentTypes)) return false; + final java.lang.Object this$apply = this.apply; + final java.lang.Object other$apply = other.apply; + if (this$apply == null ? other$apply != null : !this$apply.equals(other$apply)) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $argumentTypes = this.getArgumentTypes(); + result = result * PRIME + ($argumentTypes == null ? 43 : $argumentTypes.hashCode()); + final java.lang.Object $apply = this.apply; + result = result * PRIME + ($apply == null ? 43 : $apply.hashCode()); + return result; + } + + @java.lang.Override + public java.lang.String toString() { + return "StaticMethodValue(argumentTypes=" + this.getArgumentTypes() + ", apply=" + this.apply + ")"; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/StringInterpreterValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/StringInterpreterValue.java index 15bde43..42ee713 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/values/StringInterpreterValue.java +++ b/src/main/java/org/zwobble/couscous/interpreter/values/StringInterpreterValue.java @@ -1,53 +1,71 @@ package org.zwobble.couscous.interpreter.values; import java.util.Optional; - import org.zwobble.couscous.interpreter.NoSuchField; import org.zwobble.couscous.values.IntegerValue; import org.zwobble.couscous.values.PrimitiveValue; import org.zwobble.couscous.values.PrimitiveValues; import org.zwobble.couscous.values.StringValue; - import static java.util.Arrays.asList; -import lombok.Value; -import lombok.val; - -@Value -public class StringInterpreterValue implements InterpreterValue { - public static final ConcreteType TYPE = ConcreteType.builder(StringInterpreterValue.class, StringValue.REF) - .method("length", asList(), - (environment, arguments) -> - new IntegerInterpreterValue(arguments.getReceiver().value.length())) - - .method("substring", asList(IntegerValue.REF, IntegerValue.REF), - (environment, arguments) -> { - val startIndex = (IntegerInterpreterValue)arguments.get(0); - val endIndex = (IntegerInterpreterValue)arguments.get(1); - return new StringInterpreterValue(arguments.getReceiver().value.substring(startIndex.getValue(), endIndex.getValue())); - }) - - .build(); - - String value; - +public final class StringInterpreterValue implements InterpreterValue { + public static final ConcreteType TYPE = ConcreteType.builder(StringInterpreterValue.class, StringValue.REF).method("length", asList(), (environment, arguments) -> new IntegerInterpreterValue(arguments.getReceiver().value.length())).method("substring", asList(IntegerValue.REF, IntegerValue.REF), (environment, arguments) -> { + IntegerInterpreterValue startIndex = (IntegerInterpreterValue)arguments.get(0); + IntegerInterpreterValue endIndex = (IntegerInterpreterValue)arguments.get(1); + return new StringInterpreterValue(arguments.getReceiver().value.substring(startIndex.getValue(), endIndex.getValue())); + }).build(); + private final String value; + @Override public ConcreteType getType() { return TYPE; } - + @Override public Optional<PrimitiveValue> toPrimitiveValue() { return Optional.of(PrimitiveValues.value(value)); } - + @Override public InterpreterValue getField(String fieldName) { throw new NoSuchField(fieldName); } - + @Override public void setField(String fieldName, InterpreterValue value) { throw new NoSuchField(fieldName); } -} + + public StringInterpreterValue(final String value) { + this.value = value; + } + + public String getValue() { + return this.value; + } + + @java.lang.Override + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof StringInterpreterValue)) return false; + final StringInterpreterValue other = (StringInterpreterValue)o; + final java.lang.Object this$value = this.getValue(); + final java.lang.Object other$value = other.getValue(); + if (this$value == null ? other$value != null : !this$value.equals(other$value)) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $value = this.getValue(); + result = result * PRIME + ($value == null ? 43 : $value.hashCode()); + return result; + } + + @java.lang.Override + public java.lang.String toString() { + return "StringInterpreterValue(value=" + this.getValue() + ")"; + } +}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/UnitInterpreterValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/UnitInterpreterValue.java index 1c184a4..2d4ef9c 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/values/UnitInterpreterValue.java +++ b/src/main/java/org/zwobble/couscous/interpreter/values/UnitInterpreterValue.java @@ -1,40 +1,39 @@ package org.zwobble.couscous.interpreter.values; import java.util.Optional; - import org.zwobble.couscous.interpreter.NoSuchField; import org.zwobble.couscous.values.PrimitiveValue; import org.zwobble.couscous.values.PrimitiveValues; -import lombok.ToString; - -@ToString public class UnitInterpreterValue implements InterpreterValue { - private static final ConcreteType TYPE = ConcreteType.builder(UnitInterpreterValue.class, "Unit") - .build(); - - public static final UnitInterpreterValue UNIT = new UnitInterpreterValue(); + private static final ConcreteType TYPE = ConcreteType.builder(UnitInterpreterValue.class, "Unit").build(); + public static final UnitInterpreterValue UNIT = new UnitInterpreterValue(); private UnitInterpreterValue() { } - + @Override public ConcreteType getType() { return TYPE; } - + @Override public Optional<PrimitiveValue> toPrimitiveValue() { return Optional.of(PrimitiveValues.UNIT); } - + @Override public InterpreterValue getField(String fieldName) { throw new NoSuchField(fieldName); } - + @Override public void setField(String fieldName, InterpreterValue value) { throw new NoSuchField(fieldName); } -} + + @java.lang.Override + public java.lang.String toString() { + return "UnitInterpreterValue()"; + } +}
\ No newline at end of file |
