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

import misc.*;

/**
 * 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 TypeEnum type;
    private AbstractInstance cls; // null for classes
    private AbstractInstance mtd; // null for classes, methods

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

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


    @Override public boolean equals(Object other) {
        boolean ret = false;
        TokenKey o;
        // if (other instanceof TokenKey) {
        //     o = (TokenKey) other;
        //     MinimalLogger.info(String.format("Comparing %s and %s",
        //                                   this.toString(),
        //                                   other.toString()));
        //     if ((o.cls == null && this.cls == null) ||
        //         (o.cls != null && o.cls.equals(this.cls))) {
        //         MinimalLogger.info("Classes are equal!");
        //         if ((o.mtd == null && this.mtd == null) ||
        //             (o.mtd != null && o.mtd.equals(this.mtd))) {
        //             MinimalLogger.info("Methods are equal!");
        //             if (o.name.equals(this.name)) { ret = true; }
        //         } else { MinimalLogger.info("Methods not equal."); }
        //     } else { MinimalLogger.info("Classes not equal."); }
        // }
        if (other instanceof TokenKey &&
            (o = (TokenKey) other).name.equals(this.name) &&
            ((o.type == null && this.type == null) ||
             (o.type != null && o.type.equals(this.type))) &&
            ((o.cls == null && this.cls == null) ||
             (o.cls != null && o.cls.equals(this.cls))) &&
            ((o.mtd == null && this.mtd == null) ||
             (o.mtd != null && o.mtd.equals(this.mtd))))
            ret = true;
        return ret;
    }

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

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

}