summaryrefslogtreecommitdiff
path: root/heat/TypeBundle.java
blob: ac00e71f8a44f6c53fb6c6ea9bfbb68d5dcf419f (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
51
52
53
54
55
56
57
58
59
60
package heat;
import st.TypeEnum;
import st.ClassInstance;

/**
 * A simple wrapper for TypeEnum,
 * meant to provide all helper methods
 * and structures for evaluating typing.
 */
class TypeBundle {

    private TypeEnum type;
    private ClassInstance instance;

    protected TypeBundle(TypeEnum type, ClassInstance instance) {
        this.type = type;
        this.instance = instance;
    }

    @Override public String toString() {
        String cls = (this.instance != null) ? String.format(" (%s)", this.instance) : "";
        return String.format("%s%s",
                             this.type,
                             cls);
    }

    @Override public boolean equals(Object other) {
        return (other instanceof TypeBundle) &&
            ((TypeBundle) other).type == this.type;
    }

    public boolean isClass() {
        return this.type == TypeEnum.classname;
    }

    public boolean isMethod() {
        return this.type == TypeEnum.method;
    }

    public boolean isArray() {
        return this.type == TypeEnum.intarray;
    }

    public boolean isBool() {
        return this.type == TypeEnum.bool;
    }

    public boolean isInt() {
        return this.type == TypeEnum.integer;
    }

    public TypeEnum getType() {
        return this.type;
    }

    public ClassInstance getInstance() {
        return this.instance;
    }

}