package de.dhbwstuttgart.syntaxtree; import org.antlr.v4.runtime.Token; import com.google.common.collect.Lists; import de.dhbwstuttgart.parser.NullToken; import java.util.*; /** * Stellt eine Deklarations-Liste von Generischen Variablen dar. * Kann vor Methoden und Klassen auftauchen. (<....>) * @author janulrich * */ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable{ private Token offsetOfLastElement; private List gtvs = new ArrayList<>(); @SuppressWarnings("unchecked") public GenericDeclarationList(Iterable values, Token endOffset) { super(endOffset); gtvs = isListOfGenericTypeVar(values) ? (List)values : Lists.newArrayList(values); this.offsetOfLastElement = endOffset; } public GenericDeclarationList(ArrayList values, Token endOffset) { super(endOffset); gtvs = values; this.offsetOfLastElement = endOffset; } private boolean isListOfGenericTypeVar(Iterable values) { return values instanceof List && ((List)values).size() > 0 && ((List)values).get(0) instanceof GenericTypeVar; } @Override public Iterator iterator() { return gtvs.iterator(); } @Override public void accept(ASTVisitor visitor) { visitor.visit(this); } public String toString() { return this.gtvs.toString(); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; GenericDeclarationList that = (GenericDeclarationList) o; return gtvs.equals(that.gtvs); } @Override public int hashCode() { return Objects.hash(gtvs); } }