diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/operations/OperationFactory.java b/src/be/jeffcheasey88/peeratcode/parser/java/operations/OperationFactory.java index 68fe1ae..e73d056 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/operations/OperationFactory.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/operations/OperationFactory.java @@ -40,6 +40,8 @@ public class OperationFactory{ this.patterns.put(Pattern.compile("^\\s*continue\\s*;"), ContinueOperation.class); this.patterns.put(Pattern.compile("^\\s*break\\s*;"), BreakOperation.class); + this.patterns.put(Pattern.compile("^\\s*throw\\s+[^;]+"), ThrowOperation.class); + this.patterns.put(Pattern.compile("^\\s*[^\\^\\s]+\\^GENERIC_PARENTHESIS\\d+;"), MethodCallOperation.class); this.patterns.put(Pattern.compile("^\\s*[^\\s]+\\s+[^\\s]+\\s*=\\s*[^;]+;"), Variable.class); @@ -60,7 +62,7 @@ public class OperationFactory{ * continue OK * break OK * try catch finally - * throw + * throw OK * else OK * synchronized OK * instance of diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/operations/ThrowOperation.java b/src/be/jeffcheasey88/peeratcode/parser/java/operations/ThrowOperation.java new file mode 100644 index 0000000..2ed5183 --- /dev/null +++ b/src/be/jeffcheasey88/peeratcode/parser/java/operations/ThrowOperation.java @@ -0,0 +1,50 @@ +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 buffer, int tab) throws Exception{ + super.build(buffer, tab); + buffer.append((s) -> s+="throw "+toChange+";"); + buffer.add(""); + } + + + @Override + public E find(java.util.function.Function search, java.util.function.Function, Boolean> deep, List trace){ + return search.apply(this) ? (E)this : null; + } + + @Override + public E find(BiFunction, Boolean> search, List trace){ + trace.add(this); + return search.apply(this, trace) || trace.remove(trace.size()-1) == null ? (E)this : null; + } + +}