forked from JavaTX/JavaCompilerCore
66 lines
1.7 KiB
Java
66 lines
1.7 KiB
Java
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<GenericTypeVar>{
|
|
|
|
private Token offsetOfLastElement;
|
|
private List<GenericTypeVar> gtvs = new ArrayList<>();
|
|
|
|
@SuppressWarnings("unchecked")
|
|
public GenericDeclarationList(Iterable<? extends GenericTypeVar> values, Token endOffset) {
|
|
super(endOffset);
|
|
gtvs = isListOfGenericTypeVar(values) ? (List<GenericTypeVar>)values : Lists.newArrayList(values);
|
|
this.offsetOfLastElement = endOffset;
|
|
}
|
|
|
|
public GenericDeclarationList(ArrayList<GenericTypeVar> values, Token endOffset) {
|
|
super(endOffset);
|
|
gtvs = values;
|
|
this.offsetOfLastElement = endOffset; }
|
|
|
|
private boolean isListOfGenericTypeVar(Iterable<? extends GenericTypeVar> values) {
|
|
return values instanceof List && ((List<?>)values).size() > 0 && ((List<?>)values).get(0) instanceof GenericTypeVar;
|
|
}
|
|
|
|
@Override
|
|
public Iterator<GenericTypeVar> 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);
|
|
}
|
|
}
|