@Override public void visitMethod(MethodTree tree) { scan(tree.modifiers()); scan(tree.typeParameters()); scan(tree.returnType()); // skip the simple name scan(tree.parameters()); scan(tree.defaultValue()); scan(tree.throwsClauses()); scan(tree.block()); } }
@Override public void visitMethod(MethodTree tree) { visitNode(tree, tree.simpleName(), tree.symbol().metadata()); super.visitMethod(tree); currentParents.pop(); }
@Override public void visitMethod(MethodTree tree) { if (tree.block() == null || tree.is(Tree.Kind.CONSTRUCTOR)) { // skip everything for abstract methods (from interfaces or abstract class) and constructors return; } tree.parameters().stream() .filter(p -> IS_ZIP_ENTRY.test(p.symbol().type())) .forEach(p -> context.reportIssue(this, p, ISSUE_MESSAGE)); super.visitMethod(tree); }
private static boolean isConstructorWithParameters(MethodTree methodTree) { return methodTree.is(Tree.Kind.CONSTRUCTOR) && !methodTree.parameters().isEmpty(); }
private static boolean isExcluded(MethodTree methodTree) { String name = methodTree.simpleName().name(); if ("equals".equals(name)) { return methodTree.parameters().size() == 1; } else if ("hashCode".equals(name)) { return methodTree.parameters().isEmpty(); } return false; }
@Override public void visitMethod(MethodTree tree) { //skip return type, and throw clauses : visited in second pass. scan(tree.modifiers()); completeMetadata((JavaSymbol.MethodJavaSymbol) tree.symbol(), tree.modifiers().annotations()); scan(tree.typeParameters()); // revisits the parameters to resolve their annotations. scan(tree.parameters()); scan(tree.defaultValue()); scan(tree.block()); }
@Override public boolean apply(MethodTree methodTree) { return methodTree.simpleName().name().startsWith(getStartName()) && methodTree.parameters().isEmpty() && !methodTree.returnType().symbolType().is("void"); } };
private boolean isSerializableMethod(MethodTree methodTree) { boolean result = false; // FIXME detect methods based on type of arg and throws, not arity. if (methodTree.modifiers().modifiers().contains(Modifier.PRIVATE) && methodTree.parameters().size() == 1) { result |= "writeObject".equals(methodTree.simpleName().name()) && methodTree.throwsClauses().size() == 1; result |= "readObject".equals(methodTree.simpleName().name()) && methodTree.throwsClauses().size() == 2; } return result; }
private static boolean isSetter(MethodTree methodTree) { TypeTree returnType = methodTree.returnType(); BlockTree block = methodTree.block(); boolean returnsVoid = returnType.is(Tree.Kind.PRIMITIVE_TYPE) && "void".equals(((PrimitiveTypeTree) returnType).keyword().text()); boolean hasAtLeastOneStatement = block == null || !block.body().isEmpty(); return methodTree.simpleName().name().startsWith("set") && methodTree.parameters().size() == 1 && returnsVoid && hasAtLeastOneStatement; } }
@Override public void visitNode(Tree tree) { MethodTree methodTree = (MethodTree) tree; if (hasSemantic() && isIteratorNextMethod(methodTree.symbol()) && methodTree.block() != null) { NextMethodBodyVisitor visitor = new NextMethodBodyVisitor(); tree.accept(visitor); if (!visitor.foundThrow) { reportIssue(methodTree.simpleName(), "Add a \"NoSuchElementException\" for iteration beyond the end of the collection."); } } }
private static boolean isCloneMethod(Tree tree) { if (!tree.is(Kind.METHOD)) { return false; } MethodTree methodTree = (MethodTree) tree; return "clone".equals(methodTree.simpleName().name()) && methodTree.parameters().isEmpty() && methodTree.block() != null; }
@Override public void visitMethod(MethodTree tree) { List<IdentifierTree> usages = tree.symbol().usages(); createSymbol(tree.simpleName(), usages); for (TypeParameterTree typeParameterTree : tree.typeParameters()) { createSymbol(typeParameterTree.identifier(), typeParameterTree); } super.visitMethod(tree); }
@Override public void visitNode(Tree tree) { MethodTree method = (MethodTree) tree; boolean isPublic = method.modifiers().contains(Modifier.PUBLIC); if (hasSemantic()) { isPublic = method.symbol().isPublic(); } if (!isPublic && hasTransactionalAnnotation(method)) { reportIssue(method.simpleName(), "Make this method \"public\" or remove the \"@Transactional\" annotation"); } }
@Override public void visitMethod(MethodTree tree) { super.visitMethod(tree); if (isPublic(tree.modifiers()) && Boolean.FALSE.equals(tree.isOverriding())) { checkIfAllowed(tree.returnType(), "The return type of this method "); for (VariableTree variableTree : tree.parameters()) { checkIfAllowed(variableTree.type(), "The type of the \"" + variableTree.simpleName() + "\" object "); } } }
private static boolean isDesignedForExtension(MethodTree tree) { if (tree.symbol().enclosingClass().isFinal()) { // methods of final class can not be overridden, because the class can not be extended return false; } ModifiersTree modifiers = tree.modifiers(); return ModifiersUtils.hasModifier(modifiers, Modifier.DEFAULT) || (!ModifiersUtils.hasModifier(modifiers, Modifier.PRIVATE) && isEmptyOrThrowStatement(tree.block())); }
@Override public void visitMethod(MethodTree tree) { TypeTree returnTypeTree = tree.returnType(); if (!isOverriding(tree) || returnTypeTree == null) { if (returnTypeTree != null) { reportIssueOnDeprecatedType(returnTypeTree, returnTypeTree.symbolType()); } scan(tree.parameters()); } scan(tree.block()); }
private static boolean isFinalize(MethodTree methodTree) { if ("finalize".equals(methodTree.simpleName().name())) { Tree returnType = methodTree.returnType(); if (returnType != null && returnType.is(Tree.Kind.PRIMITIVE_TYPE)) { return "void".equals(((PrimitiveTypeTree) returnType).keyword().text()); } } return false; } }
@Override public void visitMethod(MethodTree method) { if (!method.is(Tree.Kind.CONSTRUCTOR) && returnsOptional(method)) { // check that the method is not annotated with @Nullable checkNullableAnnotation(method.modifiers(), "Methods with an \"Optional\" return type should not be \"@Nullable\"."); // check that the method does not return "null" method.accept(new ReturnNullVisitor()); } super.visitMethod(method); }