51 lines
1.3 KiB
Java
51 lines
1.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.visitor.JavaVisitor;
|
|
import dev.peerat.parser.visitor.Visitor;
|
|
import dev.peerat.parser.visitor.VisitorBag;
|
|
|
|
public class TryOperation extends OperationBag{
|
|
|
|
private Variable resource;
|
|
|
|
public TryOperation(){
|
|
super();
|
|
}
|
|
|
|
public TryOperation(Variable resource){
|
|
this();
|
|
this.resource = resource;
|
|
}
|
|
|
|
public Variable getResource(){
|
|
return this.resource;
|
|
}
|
|
|
|
@Override
|
|
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
|
return resource != null ? finder.apply(resource) ? (E)resource : super.find(finder) : super.find(finder);
|
|
}
|
|
|
|
@Override
|
|
public <E extends JavaElement> void findAll(Function<JavaElement, Boolean> finder, List<E> list){
|
|
if(resource != null){
|
|
if(finder.apply(resource)) list.add((E) resource);
|
|
resource.findAll(finder, list);
|
|
}
|
|
super.findAll(finder, list);
|
|
}
|
|
|
|
@Override
|
|
public VisitorBag visit(Visitor<JavaElement> visitor) {
|
|
if(visitor.canVisit(getClass())) return visitor.visit(this);
|
|
VisitorBag bag = new VisitorBag();
|
|
if(this.resource != null) bag.merge(this.resource.visit(visitor));
|
|
bag.merge(super.visit(visitor));
|
|
return bag;
|
|
}
|
|
}
|