diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Class.java b/src/be/jeffcheasey88/peeratcode/parser/java/Class.java index 176c7f8..bd167b6 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Class.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Class.java @@ -55,11 +55,15 @@ public class Class extends JavaElement implements AnnotableBuffer, ClassContaine @Override public E find(java.util.function.Function finder){ - for(Annotation annotation : this.annotations){ - if(finder.apply(annotation)) return (E) annotation; + if(annotations != null){ + for(Annotation annotation : this.annotations){ + if(finder.apply(annotation)) return (E) annotation; + } } - for(JavaElement element : this.elements){ - if(finder.apply(element)) return (E) element; + if(elements != null){ + for(JavaElement element : this.elements){ + if(finder.apply(element)) return (E) element; + } } return null; } diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Function.java b/src/be/jeffcheasey88/peeratcode/parser/java/Function.java index b170191..983939a 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Function.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Function.java @@ -60,15 +60,21 @@ public class Function extends JavaElement implements VariableContainer, Operatio } @Override - public E find(java.util.function.Function finder) { - for(Annotation annotation : this.annotations){ - if(finder.apply(annotation)) return (E) annotation; + public E find(java.util.function.Function finder){ + if(annotations != null){ + for(Annotation annotation : this.annotations){ + if(finder.apply(annotation)) return (E) annotation; + } } - for(Variable param : this.parameters){ - if(finder.apply(param)) return (E) param; + if(parameters != null){ + for(Variable param : this.parameters){ + if(finder.apply(param)) return (E) param; + } } - for(JavaElement content : this.elements){ - if(finder.apply(content)) return (E) content; + if(elements != null){ + for(JavaElement content : this.elements){ + if(finder.apply(content)) return (E) content; + } } return null; } diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java index 4099640..9d77ae5 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java @@ -733,7 +733,9 @@ public class JavaParser extends Parser { BiFunction function_builder = (parent, bag) -> { buildVariable(bag); Integer mod = bag.get("mod"); - Function function = new Function((((AnnotableBuffer)parent).getAnnotationBuffer()), mod == null ? 0 : mod, bag.get("generic"), bag.get("type"), bag.get("name"), bag.get("param"), bag.get("throws")); + List annotations = null; + if(parent instanceof AnnotableBuffer) annotations = (((AnnotableBuffer)parent).getAnnotationBuffer()); + Function function = new Function(annotations, mod == null ? 0 : mod, bag.get("generic"), bag.get("type"), bag.get("name"), bag.get("param"), bag.get("throws")); if(parent instanceof FunctionContainer) ((FunctionContainer)parent).addFunction(function); return function; }; @@ -1039,7 +1041,7 @@ public class JavaParser extends Parser { } public static void main(String[] args) throws Exception{ - File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\src\\dev\\peerat\\backend\\bonus\\extract\\RouteExtracter.java"); + File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\test\\dev\\peerat\\backend\\routes\\PlayerDetailsTests.java"); BufferedReader reader = new BufferedReader(new FileReader(file)); diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java b/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java index ccd062b..5d0f949 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java @@ -46,8 +46,10 @@ public class Variable extends JavaElement{ @Override public E find(Function finder){ - for(Annotation annotation : this.annotations){ - if(finder.apply(annotation)) return (E) annotation; + if(annotations != null){ + for(Annotation annotation : this.annotations){ + if(finder.apply(annotation)) return (E) annotation; + } } return value != null ? finder.apply(value) ? (E)value : null : null; } diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/operation/ForOperation.java b/src/be/jeffcheasey88/peeratcode/parser/java/operation/ForOperation.java index 5b08172..5707b8c 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/operation/ForOperation.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/operation/ForOperation.java @@ -44,11 +44,15 @@ public class ForOperation extends OperationBag{ @Override public E find(Function finder){ - for(Variable variable : this.init_vars){ - if(finder.apply(variable)) return (E)variable; + if(init_vars != null){ + for(Variable variable : this.init_vars){ + if(finder.apply(variable)) return (E)variable; + } } - for(Value value : this.init_values){ - if(finder.apply(value)) return (E)value; + if(init_values != null){ + for(Value value : this.init_values){ + if(finder.apply(value)) return (E)value; + } } if(finder.apply(condition)) return (E)condition; for(Value value : this.updates){ diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/operation/OperationBag.java b/src/be/jeffcheasey88/peeratcode/parser/java/operation/OperationBag.java index f6eb7a1..ddd197e 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/operation/OperationBag.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/operation/OperationBag.java @@ -30,8 +30,10 @@ public class OperationBag extends Operation implements VariableContainer, Operat @Override public E find(Function finder){ - for(JavaElement element : this.elements){ - if(finder.apply(element)) return (E)element; + if(elements != null){ + for(JavaElement element : this.elements){ + if(finder.apply(element)) return (E)element; + } } return null; } diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/operation/ReturnOperation.java b/src/be/jeffcheasey88/peeratcode/parser/java/operation/ReturnOperation.java index 76aac7f..7dff44f 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/operation/ReturnOperation.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/operation/ReturnOperation.java @@ -20,7 +20,7 @@ public class ReturnOperation extends Operation{ @Override public E find(Function finder) { - return finder.apply(value) ? (E)value : null; + return value != null ? finder.apply(value) ? (E)value : null : null; } } diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/operation/TryOperation.java b/src/be/jeffcheasey88/peeratcode/parser/java/operation/TryOperation.java index 6f37f0e..d11051a 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/operation/TryOperation.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/operation/TryOperation.java @@ -24,7 +24,6 @@ public class TryOperation extends OperationBag{ @Override public E find(Function finder){ - if(finder.apply(resource)) return (E)resource; - return super.find(finder); + return resource != null ? finder.apply(resource) ? (E)resource : super.find(finder) : super.find(finder); } }