60 lines
1.5 KiB
Java
60 lines
1.5 KiB
Java
package be.jeffcheasey88.peeratcode.parser.java;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.function.Function;
|
|
|
|
import be.jeffcheasey88.peeratcode.parser.Token;
|
|
import be.jeffcheasey88.peeratcode.parser.java.Annotation.Annotable;
|
|
|
|
public class Variable extends JavaElement implements Annotable{
|
|
|
|
public static interface VariableContainer{
|
|
|
|
void addVariable(Variable variable);
|
|
|
|
}
|
|
|
|
private List<Annotation> annotations;
|
|
|
|
private int mod;
|
|
private Token type;
|
|
private Token name;
|
|
private boolean elips;
|
|
private Value value;
|
|
|
|
public Variable(int mod, Token type, Token name){
|
|
this.mod = mod;
|
|
this.type = type;
|
|
this.name = name;
|
|
this.annotations = new ArrayList<>();
|
|
}
|
|
|
|
public Variable(int mod, Token type, Token name, boolean elips){
|
|
this(mod, type, name);
|
|
this.elips = elips;
|
|
}
|
|
|
|
public Variable(int mod, Token type, Token name, boolean elips, Value value){
|
|
this(mod, type, name, elips);
|
|
this.value = value;
|
|
}
|
|
|
|
@Override
|
|
public String toString(){
|
|
return "Variable[mod="+mod+", type="+type+", name="+name+", elips="+elips+", value="+value+"]";
|
|
}
|
|
|
|
@Override
|
|
public void addAnnotation(Annotation annotation){
|
|
this.annotations.add(annotation);
|
|
}
|
|
|
|
@Override
|
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
|
for(Annotation annotation : this.annotations){
|
|
if(finder.apply(annotation)) return (E) annotation;
|
|
}
|
|
return value != null ? finder.apply(value) ? (E)value : null : null;
|
|
}
|
|
}
|