001package gudusoft.gsqlparser.dlineage.symbol;
002
003import gudusoft.gsqlparser.dlineage.dynamicsql.RoutineIdentity;
004
005/**
006 * The scope of one overload's variable pool (identity-first pools, {@code Option.identityFirstVariablePools}): the
007 * routine's frozen scope and its declaration identity. Two same-named overloads share the scope and differ in the
008 * identity, so their formals and locals never meet.
009 */
010public final class IdentityScope {
011
012    private final Object scope;
013    private final RoutineIdentity identity;
014
015    private IdentityScope(Object scope, RoutineIdentity identity) {
016        this.scope = scope;
017        this.identity = identity;
018    }
019
020    /** The pool scope of a routine, or null when it has no declaration identity. */
021    public static IdentityScope of(Object scope, RoutineIdentity identity) {
022        return identity == null ? null : new IdentityScope(scope, identity);
023    }
024
025    /** The routine's frozen scope, the overload-blind scope this pool refines. */
026    public Object getScope() {
027        return scope;
028    }
029
030    @Override
031    public boolean equals(Object o) {
032        if (this == o) {
033            return true;
034        }
035        if (!(o instanceof IdentityScope)) {
036            return false;
037        }
038        IdentityScope other = (IdentityScope) o;
039        return (scope == null ? other.scope == null : scope.equals(other.scope)) && identity.equals(other.identity);
040    }
041
042    @Override
043    public int hashCode() {
044        return (scope == null ? 0 : scope.hashCode()) * 31 + identity.hashCode();
045    }
046
047    @Override
048    public String toString() {
049        return "{" + scope + "#" + identity.signatureKey() + "}";
050    }
051}