package st; import java.util.ArrayList; public abstract class AbstractInstance { protected String name; // the literal name of the declaration protected TypeEnum type; // the type of the declaration protected ArrayList scope; // the scope where the instance is valid protected ClassInstance cls; // the surrounding class public AbstractInstance(String name, TypeEnum type) { this.type = type; this.name = name; this.scope = new ArrayList<>(); } public String toString() { return this.name; } public boolean equals(AbstractInstance other) { return this.name == other.getName() && this.type == this.type; } public int hashCode() { return this.name.hashCode(); } public void setScope(AbstractInstance ins) { /** * If the scope is a MethodInstance, add the single method. * If the scope is a ClassInstance, add the classes' methods, * and the class itself. */ // FIXME add third pass to properly add all scope information if (ins instanceof MethodInstance) this.scope.add(ins); else if (ins instanceof ClassInstance) { for (MethodInstance mtd : ((ClassInstance) ins).getMethods()) this.scope.add(mtd); } } public void addClassInstance(ClassInstance cls) { this.cls = cls; } public String getName() { return this.name; } public TypeEnum getType() { return this.type; } public ArrayList getScope() { return this.scope; } public ClassInstance getClassInstance() { return this.cls; } }