private static boolean hasNoExtension(ClassTree tree) { return tree.superInterfaces().isEmpty(); }
private static List<Type> getTypes(ListTree<TypeTree> superInterfaces) { List<Type> types = new ArrayList<>(superInterfaces.size()); for (TypeTree superInterface : superInterfaces) { types.add(superInterface.symbolType()); } return types; }
private static boolean isTryStatementResource(Tree tree) { final TryStatementTree tryStatement = getEnclosingTryStatement(tree); return tryStatement != null && tryStatement.resourceList().contains(tree); }
@Override public void visitNode(Tree tree) { ListTree<Tree> resources = ((TryStatementTree) tree).resourceList(); // need only (resources.size - 1) separators if (!resources.isEmpty() && resources.separators().size() == resources.size()) { reportIssue(Iterables.getLast(resources.separators()), "Remove this extraneous semicolon."); } }
private static boolean declaresResourceAsVariable(ListTree<Tree> resources) { return resources.stream().anyMatch(r -> r.is(Tree.Kind.VARIABLE)); }
@Override public void visitCatch(CatchTree tree) { super.visitCatch(tree); Tree typeTree = tree.parameter().type(); if (typeTree.is(Kind.UNION_TYPE)) { ((UnionTypeTree) typeTree).typeAlternatives().forEach(this::checkType); } else { checkType(typeTree); } }
private static Collection<Symbol> getUpdatedSymbols(ListTree<StatementTree> updates) { UpdateVisitor updateVisitor = new UpdateVisitor(); updates.accept(updateVisitor); return updateVisitor.symbols; }
@Override public void visitAnnotation(AnnotationTree annotationTree) { if (isArrayInitialized(annotationTree)) { NewArrayTree arrayTree = (NewArrayTree) annotationTree.arguments().get(0); if (isAllSameAnnotation(arrayTree.initializers()) && isAnnotationRepeatable(arrayTree.initializers().get(0))) { context.reportIssue( this, annotationTree.annotationType(), "Remove the '" + getAnnotationName(annotationTree) + "' wrapper from this annotation group" + context.getJavaVersion().java8CompatibilityMessage()); } } super.visitAnnotation(annotationTree); }
private static boolean declaresResourceAsVariable(ListTree<Tree> resources) { return resources.stream().anyMatch(r -> r.is(Tree.Kind.VARIABLE)); }
@Override public void visitNode(Tree tree) { ListTree<Tree> resources = ((TryStatementTree) tree).resourceList(); // need only (resources.size - 1) separators if (!resources.isEmpty() && resources.separators().size() == resources.size()) { reportIssue(Iterables.getLast(resources.separators()), "Remove this extraneous semicolon."); } }
@Override public void visitCatch(CatchTree tree) { super.visitCatch(tree); Tree typeTree = tree.parameter().type(); if (typeTree.is(Kind.UNION_TYPE)) { ((UnionTypeTree) typeTree).typeAlternatives().forEach(this::checkType); } else { checkType(typeTree); } }
private static Collection<Symbol> getUpdatedSymbols(ListTree<StatementTree> updates) { UpdateVisitor updateVisitor = new UpdateVisitor(); updates.accept(updateVisitor); return updateVisitor.symbols; }
@Override public void visitAnnotation(AnnotationTree annotationTree) { if (isArrayInitialized(annotationTree)) { NewArrayTree arrayTree = (NewArrayTree) annotationTree.arguments().get(0); if (isAllSameAnnotation(arrayTree.initializers()) && isAnnotationRepeatable(arrayTree.initializers().get(0))) { context.reportIssue( this, annotationTree.annotationType(), "Remove the '" + getAnnotationName(annotationTree) + "' wrapper from this annotation group" + context.getJavaVersion().java8CompatibilityMessage()); } } super.visitAnnotation(annotationTree); }
private static boolean hasNoExtension(ClassTree tree) { return tree.superInterfaces().isEmpty(); }
private static boolean isCloneable(ClassTree classTree) { return classTree.superInterfaces().stream().map(TypeTree::symbolType).anyMatch(t -> t.is("java.lang.Cloneable")); } }
private static List<Type> getTypes(ListTree<TypeTree> superInterfaces) { List<Type> types = new ArrayList<>(superInterfaces.size()); for (TypeTree superInterface : superInterfaces) { types.add(superInterface.symbolType()); } return types; }
private static boolean isTryStatementResource(VariableTree variable) { final TryStatementTree tryStatement = getEnclosingTryStatement(variable); return tryStatement != null && tryStatement.resources().contains(variable); }
private boolean withinStandardTryWithFinally() { return !withinTry.isEmpty() && withinTry.peek().resourceList().isEmpty() && withinTry.peek().finallyBlock() != null; }
private static Optional<Type> findInterruptingType(VariableTree parameter) { if (parameter.type().is(Tree.Kind.UNION_TYPE)) { return ((UnionTypeTree) parameter.type()).typeAlternatives().stream() .map(TypeTree::symbolType) .filter(INTERRUPTING_TYPE_PREDICATE) .findFirst(); } return Optional.of(parameter) .map(VariableTree::symbol) .map(Symbol::type) .filter(INTERRUPTING_TYPE_PREDICATE); }
@Override public void visitTryStatement(TryStatementTree tree) { statements++; statements -= tree.resourceList().size(); statements -= tree.catches().size(); super.visitTryStatement(tree); }