private VisitorState createVisitorState() { return VisitorState.createConfiguredForCompilation( state.context, description -> ok[0] = false, ImmutableMap.of(), state.errorProneOptions()); } }.scan(state.getPath(), null);
private static boolean requiresJavadoc(Tree tree, VisitorState state) { if (state.errorProneOptions().isTestOnlyTarget()) { return false; } Symbol symbol = getSymbol(tree); if (symbol instanceof MethodSymbol && !findSuperMethods((MethodSymbol) symbol, state.getTypes()).isEmpty()) { return false; } return symbol != null && (symbol.getModifiers().contains(Modifier.PUBLIC) || symbol.getModifiers().contains(Modifier.PROTECTED)); } }
private <M extends Suppressible, T extends Tree> VisitorState processMatchers( Iterable<M> matchers, T tree, TreeProcessor<M, T> processingFunction, VisitorState oldState) { ErrorProneOptions errorProneOptions = oldState.errorProneOptions(); for (M matcher : matchers) { SuppressedState suppressed = isSuppressed(matcher, errorProneOptions); // If the ErrorProneOptions say to visit suppressed code, we still visit it if (suppressed == SuppressedState.UNSUPPRESSED || errorProneOptions.isIgnoreSuppressionAnnotations()) { try { // We create a new VisitorState with the suppression info specific to this matcher. VisitorState stateWithSuppressionInformation = oldState.withPathAndSuppression(getCurrentPath(), suppressed); reportMatch( processingFunction.process(matcher, tree, stateWithSuppressionInformation), stateWithSuppressionInformation); } catch (Throwable t) { handleError(matcher, t); } } } // Return a VisitorState with our new path, but without mentioning the suppression of any // matcher. return oldState.withPath(getCurrentPath()); }
private VisitorState createVisitorState() { return new VisitorState( state.context, (Description description) -> { ok[0] = false; }, ImmutableMap.of(), state.errorProneOptions()); } }.scan(state.getPath(), null);
@Override public Void visitBinary(BinaryTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (BinaryTreeMatcher matcher : binaryMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchBinary(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitBinary(tree, state); }
@Override public Void visitDoWhileLoop(DoWhileLoopTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (DoWhileLoopTreeMatcher matcher : doWhileLoopMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchDoWhileLoop(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitDoWhileLoop(tree, state); }
@Override public Void visitEnhancedForLoop(EnhancedForLoopTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (EnhancedForLoopTreeMatcher matcher : enhancedForLoopMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchEnhancedForLoop(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitEnhancedForLoop(tree, state); }
@Override public Void visitImport(ImportTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (ImportTreeMatcher matcher : importMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchImport(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitImport(tree, state); }
@Override public Void visitNewArray(NewArrayTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (NewArrayTreeMatcher matcher : newArrayMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchNewArray(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitNewArray(tree, state); }
@Override public Void visitThrow(ThrowTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (ThrowTreeMatcher matcher : throwMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchThrow(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitThrow(tree, state); }
@Override public Void visitAssert(AssertTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (AssertTreeMatcher matcher : assertMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchAssert(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitAssert(tree, state); }
@Override public Void visitCase(CaseTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (CaseTreeMatcher matcher : caseMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchCase(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitCase(tree, state); }
@Override public Void visitForLoop(ForLoopTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (ForLoopTreeMatcher matcher : forLoopMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchForLoop(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitForLoop(tree, state); }
@Override public Void visitModifiers(ModifiersTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (ModifiersTreeMatcher matcher : modifiersMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchModifiers(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitModifiers(tree, state); }
@Override public Void visitParenthesized(ParenthesizedTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (ParenthesizedTreeMatcher matcher : parenthesizedMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchParenthesized(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitParenthesized(tree, state); }
@Override public Void visitPrimitiveType(PrimitiveTypeTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (PrimitiveTypeTreeMatcher matcher : primitiveTypeMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchPrimitiveType(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitPrimitiveType(tree, state); }
@Override public Void visitSwitch(SwitchTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (SwitchTreeMatcher matcher : switchMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchSwitch(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitSwitch(tree, state); }
@Override public Void visitSynchronized(SynchronizedTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (SynchronizedTreeMatcher matcher : synchronizedMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchSynchronized(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitSynchronized(tree, state); }
@Override public Void visitTypeParameter(TypeParameterTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (TypeParameterTreeMatcher matcher : typeParameterMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchTypeParameter(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitTypeParameter(tree, state); }
@Override public Void visitUnary(UnaryTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (UnaryTreeMatcher matcher : unaryMatchers) { if (!isSuppressed(matcher, state.errorProneOptions())) { try { reportMatch(matcher.matchUnary(tree, state), state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitUnary(tree, state); }