122 lines
3 KiB
Java
122 lines
3 KiB
Java
package dev.peerat.parser.java.operation;
|
|
|
|
import java.util.List;
|
|
import java.util.function.Function;
|
|
|
|
import dev.peerat.parser.java.JavaElement;
|
|
import dev.peerat.parser.java.Variable;
|
|
import dev.peerat.parser.java.value.Value;
|
|
import dev.peerat.parser.java.visitor.JavaVisitor;
|
|
import dev.peerat.parser.visitor.bag.ListVisitorBag;
|
|
import dev.peerat.parser.visitor.bag.VisitorBag;
|
|
|
|
public class ForOperation extends OperationBag{
|
|
|
|
private List<Variable> init_vars;
|
|
private List<Value> init_values;
|
|
|
|
private Value condition;
|
|
|
|
private List<Value> updates;
|
|
|
|
public ForOperation(List<Variable> init_vars, List<Value> init_values, Value condition, List<Value> updates){
|
|
super();
|
|
|
|
this.init_vars = init_vars;
|
|
this.init_values = init_values;
|
|
|
|
this.condition = condition;
|
|
this.updates = updates;
|
|
}
|
|
|
|
public List<Variable> initVars(){
|
|
return this.init_vars;
|
|
}
|
|
|
|
public List<Value> initValues(){
|
|
return this.init_values;
|
|
}
|
|
|
|
public Value getCondition(){
|
|
return this.condition;
|
|
}
|
|
|
|
public List<Value> getUpdates(){
|
|
return this.updates;
|
|
}
|
|
|
|
@Override
|
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
|
if(init_vars != null){
|
|
for(Variable variable : this.init_vars){
|
|
if(finder.apply(variable)) return (E)variable;
|
|
}
|
|
}
|
|
if(init_values != null){
|
|
for(Value value : this.init_values){
|
|
if(finder.apply(value)) return (E)value;
|
|
}
|
|
}
|
|
if(finder.apply(condition)) return (E)condition;
|
|
if(this.updates != null){
|
|
for(Value value : this.updates){
|
|
if(finder.apply(value)) return (E)value;
|
|
}
|
|
}
|
|
return super.find(finder);
|
|
}
|
|
|
|
@Override
|
|
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
|
if(init_vars != null){
|
|
for(Variable variable : this.init_vars){
|
|
if(finder.apply(variable)) list.add((E)variable);
|
|
variable.findAll(finder, list);
|
|
}
|
|
}
|
|
if(init_values != null){
|
|
for(Value value : this.init_values){
|
|
if(finder.apply(value)) list.add((E)value);
|
|
value.findAll(finder, list);
|
|
}
|
|
}
|
|
if(finder.apply(condition)) list.add((E)condition);
|
|
if(this.updates != null){
|
|
for(Value value : this.updates){
|
|
if(finder.apply(value)) list.add((E)value);
|
|
value.findAll(finder, list);
|
|
}
|
|
}
|
|
super.findAll(finder, list);
|
|
}
|
|
|
|
@Override
|
|
public void build(Builder builder) throws Exception {
|
|
|
|
}
|
|
|
|
@Override
|
|
public VisitorBag visit(JavaVisitor<?> visitor) {
|
|
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
|
VisitorBag bag = new ListVisitorBag();
|
|
if(init_vars != null)
|
|
for(Variable variable : this.init_vars){
|
|
bag.compute(variable.visit(visitor).toList().toArray());
|
|
}
|
|
|
|
if(init_values != null)
|
|
for(Value value : this.init_values){
|
|
bag.compute(value.visit(visitor).toList().toArray());
|
|
}
|
|
|
|
bag.compute(condition.visit(visitor).toList().toArray());
|
|
|
|
if(this.updates != null)
|
|
for(Value value : this.updates){
|
|
bag.compute(value.visit(visitor).toList().toArray());
|
|
}
|
|
|
|
bag.compute(super.visit(visitor).toList().toArray());
|
|
return bag;
|
|
}
|
|
}
|