summaryrefslogtreecommitdiff
path: root/st/TokenKey.java
blob: 54086c58fa2654d526c67bee825b84ccd3662017 (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
package st;

/**
 * This class is a data structure used to distinguish tokens in
 * a given program. Tokens are considered unique if their "beginLine"
 * and name are different.
 */
public class TokenKey {

    private String name;
    private AbstractInstance cls; // null for classes
    private AbstractInstance mtd; // null for classes, methods

    public TokenKey(String name, AbstractInstance cls, AbstractInstance mtd) {
        this.name = name;
        this.cls = cls;
        this.mtd = mtd;
    }

    @Override public String toString() {
        return String.format("%s (%s,%s)",
                             this.name,
                             this.mtd,
                             this.cls);
    }


    @Override public boolean equals(Object other) {
        boolean ret = false;
        TokenKey o;
        if (other instanceof TokenKey &&
            (o = (TokenKey) other).name == this.name &&
            o.cls == this.cls &&
            o.mtd == this.mtd) {
            ret = true;
        }
        return ret;
    }

    @Override public int hashCode() {
        return this.name.hashCode();
    }

    public String getName() {
        return this.name;
    }

}