aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/interpreter/values/ArrayInterpreterValue.java
blob: 3a1de5896d9bc11d509b75c9010f86fe65217ae7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package org.zwobble.couscous.interpreter.values;

import org.zwobble.couscous.interpreter.errors.NoSuchField;
import org.zwobble.couscous.interpreter.types.InterpreterType;
import org.zwobble.couscous.interpreter.types.IntrinsicInterpreterType;
import org.zwobble.couscous.types.Type;
import org.zwobble.couscous.types.Types;
import org.zwobble.couscous.values.PrimitiveValue;

import java.util.List;
import java.util.Optional;

public class ArrayInterpreterValue implements InterpreterValue {
    private final Type elementType;
    private final List<InterpreterValue> elements;

    public ArrayInterpreterValue(Type elementType, List<InterpreterValue> elements) {
        this.elementType = elementType;
        this.elements = elements;
    }

    public Type getElementType() {
        return elementType;
    }

    public List<InterpreterValue> getElements() {
        return elements;
    }

    @Override
    public InterpreterType getType() {
        return IntrinsicInterpreterType.builder(ArrayInterpreterValue.class, Types.array(elementType))
            .build();
    }

    @Override
    public Optional<PrimitiveValue> toPrimitiveValue() {
        return Optional.empty();
    }

    @Override
    public InterpreterValue getField(String fieldName) {
        throw new NoSuchField(fieldName);
    }

    @Override
    public void setField(String fieldName, InterpreterValue value) {
        throw new NoSuchField(fieldName);
    }
}