aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-28 19:18:28 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-29 08:04:42 +0000
commitb7e0010d6e8e5413fcd66eae158111db509eb27b (patch)
tree35fafacd7819788b185f803a0c3797a2f54a1dca /src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java
parentd3e9fb5ce2a13bdb0ee39e9625494e8c5d2a9383 (diff)
Split ConcreteType up into specialised type implementations
Diffstat (limited to 'src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java')
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java b/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java
index 1661ee7..50ed24f 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java
@@ -4,24 +4,25 @@ import org.zwobble.couscous.ast.FieldDeclarationNode;
import org.zwobble.couscous.interpreter.InterpreterTypes;
import org.zwobble.couscous.interpreter.errors.NoSuchField;
import org.zwobble.couscous.interpreter.errors.UnboundField;
+import org.zwobble.couscous.interpreter.types.InterpreterType;
import java.util.HashMap;
import java.util.Map;
public class InterpreterFields {
- public static InterpreterFields forClass(ConcreteType type) {
+ public static InterpreterFields forClass(InterpreterType type) {
return new InterpreterFields(true, type);
}
- public static InterpreterFields forInstanceOf(ConcreteType type) {
+ public static InterpreterFields forInstanceOf(InterpreterType type) {
return new InterpreterFields(false, type);
}
private final boolean isStatic;
- private final ConcreteType type;
+ private final InterpreterType type;
private final Map<String, InterpreterValue> fields;
- private InterpreterFields(boolean isStatic, ConcreteType type) {
+ private InterpreterFields(boolean isStatic, InterpreterType type) {
this.isStatic = isStatic;
this.type = type;
this.fields = new HashMap<>();
@@ -43,7 +44,8 @@ public class InterpreterFields {
}
private FieldDeclarationNode getFieldDefinition(String fieldName) {
- return type.getField(isStatic, fieldName)
+ return type.getField(fieldName)
+ .filter(field -> field.isStatic() == isStatic)
.orElseThrow(() -> new NoSuchField(fieldName));
}
}