package accrue.analysis.preciseExceptions;

import polyglot.types.Type;

public class ThrowableType {
    private final boolean isExactType;
    private final Type type;

    public ThrowableType(Type t, boolean isExactType) {
        this.isExactType = isExactType;
        this.type = t;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (isExactType ? 1231 : 1237);
        result = prime * result + ((type == null) ? 0 : type.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (!(obj instanceof ThrowableType)) return false;
        ThrowableType other = (ThrowableType) obj;
        if (isExactType != other.isExactType) return false;
        if (type == null) {
            if (other.type != null) return false;
        }
        else if (!type.equals(other.type)) return false;
        return true;
    }

    @Override
    public String toString() {
        return (isExactType ? "exactly-" : "subtypesof-") + type.toString();
    }

    public boolean isExactType() {
        return isExactType;
    }

    public Type type() {
        return type;
    }

}
