50 lines
1.5 KiB
Java
50 lines
1.5 KiB
Java
package be.jeffcheasey88.peeratcode.parser.java.operations;
|
|
|
|
import java.util.List;
|
|
import java.util.function.BiFunction;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
import be.jeffcheasey88.peeratcode.parser.java.ArrayBuffer;
|
|
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool;
|
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
|
|
|
public class ThrowOperation extends JavaElement{
|
|
|
|
private static Pattern PATTERN = Pattern.compile("^(\\s*throw\\s+([^;]+);)");
|
|
|
|
private String toChange;
|
|
|
|
public ThrowOperation(){}
|
|
|
|
@Override
|
|
public int parse(String content, CleanerPool global, CleanerPool local) throws Exception {
|
|
Matcher matcher = PATTERN.matcher(content);
|
|
matcher.lookingAt();
|
|
|
|
//To update for native obj
|
|
this.toChange = matcher.group(2);
|
|
|
|
return matcher.group(1).length();
|
|
}
|
|
|
|
@Override
|
|
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{
|
|
super.build(buffer, tab);
|
|
buffer.append((s) -> s+="throw "+toChange+";");
|
|
buffer.add("");
|
|
}
|
|
|
|
|
|
@Override
|
|
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> search, java.util.function.Function<List<JavaElement>, Boolean> deep, List<JavaElement> trace){
|
|
return search.apply(this) ? (E)this : null;
|
|
}
|
|
|
|
@Override
|
|
public <E extends JavaElement> E find(BiFunction<JavaElement, List<JavaElement>, Boolean> search, List<JavaElement> trace){
|
|
trace.add(this);
|
|
return search.apply(this, trace) || trace.remove(trace.size()-1) == null ? (E)this : null;
|
|
}
|
|
|
|
}
|