Fix nullpointer in ast finder
This commit is contained in:
parent
aab4cd5fd8
commit
90007dc0d2
8 changed files with 43 additions and 24 deletions
|
@ -55,12 +55,16 @@ public class Class extends JavaElement implements AnnotableBuffer, ClassContaine
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
if(finder.apply(annotation)) return (E) annotation;
|
||||
}
|
||||
}
|
||||
if(elements != null){
|
||||
for(JavaElement element : this.elements){
|
||||
if(finder.apply(element)) return (E) element;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,16 +60,22 @@ public class Function extends JavaElement implements VariableContainer, Operatio
|
|||
}
|
||||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder) {
|
||||
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> finder){
|
||||
if(annotations != null){
|
||||
for(Annotation annotation : this.annotations){
|
||||
if(finder.apply(annotation)) return (E) annotation;
|
||||
}
|
||||
}
|
||||
if(parameters != null){
|
||||
for(Variable param : this.parameters){
|
||||
if(finder.apply(param)) return (E) param;
|
||||
}
|
||||
}
|
||||
if(elements != null){
|
||||
for(JavaElement content : this.elements){
|
||||
if(finder.apply(content)) return (E) content;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -733,7 +733,9 @@ public class JavaParser extends Parser<JavaElement> {
|
|||
BiFunction<JavaElement, Bag, JavaElement> 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<Annotation> 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<JavaElement> {
|
|||
}
|
||||
|
||||
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));
|
||||
|
||||
|
|
|
@ -46,9 +46,11 @@ public class Variable extends JavaElement{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,12 +44,16 @@ public class ForOperation extends OperationBag{
|
|||
|
||||
@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;
|
||||
for(Value value : this.updates){
|
||||
if(finder.apply(value)) return (E)value;
|
||||
|
|
|
@ -30,9 +30,11 @@ public class OperationBag extends Operation implements VariableContainer, Operat
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder){
|
||||
if(elements != null){
|
||||
for(JavaElement element : this.elements){
|
||||
if(finder.apply(element)) return (E)element;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ public class ReturnOperation extends Operation{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> finder) {
|
||||
return finder.apply(value) ? (E)value : null;
|
||||
return value != null ? finder.apply(value) ? (E)value : null : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ public class TryOperation extends OperationBag{
|
|||
|
||||
@Override
|
||||
public <E extends JavaElement> E find(Function<JavaElement, Boolean> 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue