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; } }