@Override public void visitAllOwnMethodInvocations( ExecutableElement method, OwnMethodInvocationVisitor visitor) { trees.getTree(method).accept(OWN_METHOD_INVOCATIONS_VISITOR, (tree, methodName) -> { visitor.visitInvocation(methodName, (kind, msg) -> { CompilationUnitTree compilationUnit = trees.getPath(method).getCompilationUnit(); trees.printMessage(kind, msg, tree, compilationUnit); }); }); }
private boolean isStartExpression(Element element, Tree statement) { if(statement.toString().startsWith("super(") || statement.toString().startsWith("this(")) { return false; } Set<String> methods = element.getKind() == CONSTRUCTOR ? getMethods(element.getEnclosingElement().asType()) : getMethods(((ExecutableElement) element).getReturnType()); if(!methods.isEmpty() || isAnnotatedStartMethod(element)) { trees.printMessage(ERROR, message(methods), statement, getCurrentPath().getCompilationUnit()); return true; } return false; }
private Void visitExpression(ExpressionTree tree, Tree statement) { if(tree.accept(new SimpleTreeVisitor<Boolean, Void>(false) { @Override public Boolean visitMethodInvocation(MethodInvocationTree methodInvocationTree, Void aVoid) { return isEndMethod(element(tree)); } }, null)) { return null; } Set<String> endMethods = new HashSet<>(getMethods(tree)); tree.accept(this, statement); if (!endMethods.isEmpty()) { trees.printMessage(ERROR, message(endMethods), statement, getCurrentPath().getCompilationUnit()); } return null; }
private Void visitExpression(ExpressionTree tree, Tree statement) { if(tree.getKind() == ASSIGNMENT) { return tree.accept(this, null); } else { Set<String> endMethods = new HashSet<>(getMethods(tree)); tree.accept(this, endMethods); if (!endMethods.isEmpty()) { trees.printMessage(ERROR, message(endMethods), statement, getCurrentPath().getCompilationUnit()); } return null; } }
@Override public void visitAllOwnMethodInvocations( ExecutableElement method, OwnMethodInvocationVisitor visitor) { trees.getTree(method).accept(OWN_METHOD_INVOCATIONS_VISITOR, (tree, methodName) -> { visitor.visitInvocation(methodName, (kind, msg) -> { CompilationUnitTree compilationUnit = trees.getPath(method).getCompilationUnit(); trees.printMessage(kind, msg, tree, compilationUnit); }); }); }
@Override public void finished(TaskEvent taskEvent) { if(taskEvent.getKind() == ANALYZE) try { scan(taskEvent.getCompilationUnit(), null); } catch (RuntimeException runtimeException) { trees.printMessage(WARNING, "Unable to finish @End method check: " + runtimeException, taskEvent.getCompilationUnit(), taskEvent.getCompilationUnit()); } }
@Override public void finished(TaskEvent taskEvent) { if(taskEvent.getKind() == ANALYZE) try { scan(taskEvent.getCompilationUnit(), null); } catch (RuntimeException runtimeException) { trees.printMessage(WARNING, "Unable to finish @End method check: " + runtimeException, taskEvent.getCompilationUnit(), getCurrentPath().getCompilationUnit()); } }
@Override public Void visitMemberReference(MemberReferenceTree tree, Set<String> endMethods) { ExpressionTree expression = tree.getQualifierExpression(); if(isVoidLambda(tree)) { Set<String> methods = new HashSet<>(getMethods(expression)); expression.accept(this, methods); if(element(tree).accept(new ExecutableElementTest<>(this::isMethodReferenceEndMethodMissing), methods)) { trees.printMessage(ERROR, message(methods), tree, getCurrentPath().getCompilationUnit()); } return null; } else { return expression.accept(this, null); } }