001package org.clafer.ast;
002
003import org.clafer.common.Check;
004
005/**
006 * All the Clafers of a type. For example, A and B are the globals in the
007 * expression {@code some A => some B}.
008 *
009 * @author jimmy
010 */
011public class AstGlobal implements AstSetExpr {
012
013    private final AstClafer type;
014
015    AstGlobal(AstClafer type) {
016        this.type = Check.notNull(type);
017    }
018
019    /**
020     * The type of this expression.
021     *
022     * @return the type of this expression
023     */
024    public AstClafer getType() {
025        return type;
026    }
027
028    /**
029     * {@inheritDoc}
030     */
031    @Override
032    public <A, B> B accept(AstExprVisitor<A, B> visitor, A a) {
033        return visitor.visit(this, a);
034    }
035
036    @Override
037    public boolean equals(Object obj) {
038        if (obj instanceof AstGlobal) {
039            AstGlobal other = (AstGlobal) obj;
040            return type.equals(other.getType());
041        }
042        return false;
043    }
044
045    @Override
046    public int hashCode() {
047        return type.hashCode() + 91;
048    }
049
050    /**
051     * {@inheritDoc}
052     */
053    @Override
054    public String toString() {
055        return type.getName();
056    }
057}