summaryrefslogtreecommitdiff
path: root/st/TypeInstance.java
blob: e43c5b35831a5659801a0bfd264eec7f7aba7200 (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
61
62
63
64
65
66
67
68
69
70
71
72
package st;

public class TypeInstance extends AbstractInstance {

    protected ClassInstance par_cls;                        // the surrounding class
    protected MethodInstance par_mtd;                       // the surrounding method
    protected ClassInstance cls;                            // the class instance


    public TypeInstance(String name, TypeEnum type, MethodInstance par_mtd, ClassInstance par_cls) {
        super(name, type);
        this.par_cls = par_cls;
        this.par_mtd = par_mtd;
    }

    @Override public boolean equals(Object other) {
        TypeInstance o;
        return (other instanceof TypeInstance &&
                ((o = (TypeInstance) other).getName() == this.getName() &&
                 o.getParentClass() == this.getParentClass() &&
                 o.getParentMethod() == this.getParentMethod()));
    }

    public int getSize() {
        return (this.cls != null) ?
            cls.getSize() : 4;
    }

    public boolean sameType(TypeInstance other) {
        /**
         * Given a TypeInstance object other,
         * returns true if other object
         * is the same type as this one.
         *
         * We can say two types are equal, as
         * long as they are not equal on a
         * type error!
         */

        return this.type != TypeEnum.ERROR &&
            this.type == other.getType();
    }

    public boolean hasChecked() {
        return type != TypeEnum.ERROR;
    }

    public void addClassInstance(ClassInstance cls) {
        this.cls = cls;
    }

    public ClassInstance getClassInstance() {
        return this.cls;
    }

    public void addParentClass(ClassInstance par_cls) {
        this.par_cls = par_cls;
    }

    public ClassInstance getParentClass() {
        return this.par_cls;
    }

    public void addParentMethod(MethodInstance par_mtd) {
        this.par_mtd = par_mtd;
    }

    public MethodInstance getParentMethod() {
        return this.par_mtd;
    }

}