private void checkIfNativeMethod(MethodTree method) { if (ModifiersUtils.hasModifier(method.modifiers(), Modifier.NATIVE)) { hasNativeMethod = true; } }
@Override public void visitMethod(MethodTree tree) { if(ModifiersUtils.hasModifier(tree.modifiers(), Modifier.DEFAULT)) { //Ignore default methods to avoid catch-22 with S1214 return; } super.visitMethod(tree); }
private void handleMethodTree(MethodTree tree) { ModifiersTree modifiers = tree.modifiers(); checkAnnotations(modifiers, ANNOTATIONS); checkAnnotations(modifiers, JSR_250_ANNOTATIONS); }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree methodTree = (MethodTree) tree; List<AnnotationTree> annotations = methodTree.modifiers().annotations(); annotations.stream().filter(SpringEndpointsCheck::isSpringWebHandler).forEach(annotationTree -> reportIssue(methodTree.simpleName(), MESSAGE)); }
private void checkMethod(MethodTree method, Symbol.TypeSymbol classSymbol) { Optional<AnnotationTree> requestMappingAnnotation = findRequestMappingAnnotation(method.modifiers()); Optional<AssignmentExpressionTree> requestMethod = requestMappingAnnotation .flatMap(SpringRequestMappingMethodCheck::findRequestMethod); if (requestMethod.isPresent()) { requestMethod .filter(SpringRequestMappingMethodCheck::hasMoreThanOneValue) .ifPresent(assignment -> reportIssue(assignment.expression(), "Consider narrowing this list of methods to one.")); } else if (requestMappingAnnotation.isPresent() && !inheritRequestMethod(classSymbol)) { reportIssue(requestMappingAnnotation.get().annotationType(), "Add a \"method\" parameter to this \"@RequestMapping\" annotation."); } }
private static Tree toReportTree(Tree member) { Stream<AnnotationTree> stream = Stream.empty(); if (member.is(Kind.VARIABLE)) { stream = ((VariableTree) member).modifiers().annotations().stream(); } else if (member.is(Kind.METHOD)) { stream = ((MethodTree) member).modifiers().annotations().stream(); } return stream .filter(a -> a.annotationType().symbolType().is("org.springframework.beans.factory.annotation.Autowired")) .findFirst() .orElseThrow(() -> new IllegalStateException("Mapping a tree to something unexpected")); }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } if (tree.is(METHOD, CONSTRUCTOR)) { MethodTree methodTree = (MethodTree) tree; int initialCounter = findModifier(methodTree.modifiers(), SYNCHRONIZED).map(m -> 1).orElse(0); synchronizedStack.push(new Counter(initialCounter)); findWaitInvocation(methodTree); } }
@Override public void visitMethod(MethodTree methodTree) { if (ModifiersUtils.hasModifier(methodTree.modifiers(), Modifier.ABSTRACT)) { return; } containsAssertThatWithoutAssertAll.push(false); super.visitMethod(methodTree); if (Boolean.TRUE.equals(containsAssertThatWithoutAssertAll.pop())) { context.reportIssue(this, methodTree.block().closeBraceToken(), "Add a call to 'assertAll' after all 'assertThat'."); } }
private static boolean hasOverrideAnnotation(MethodTree method) { for (AnnotationTree annotationTree : method.modifiers().annotations()) { Tree annotationType = annotationTree.annotationType(); if (annotationType.is(Tree.Kind.IDENTIFIER) && "Override".equals(((IdentifierTree) annotationType).name())) { return true; } } return false; }
@Override public void visitMethod(MethodTree tree) { findModifier(tree.modifiers(), SYNCHRONIZED) .ifPresent(s -> synchronizedKeywords.add(s.keyword())); super.visitMethod(tree); }
@Override public void visitNode(Tree tree) { if (tree.is(Tree.Kind.METHOD_INVOCATION)) { super.visitNode(tree); } else if (tree.is(Tree.Kind.METHOD)) { withinSynchronizedBlock.push(ModifiersUtils.hasModifier(((MethodTree) tree).modifiers(), Modifier.SYNCHRONIZED)); } else if (tree.is(Tree.Kind.SYNCHRONIZED_STATEMENT)) { withinSynchronizedBlock.push(true); } }
@Override public void visitMethod(MethodTree tree) { handleSuppressWarning(tree.modifiers().annotations(), tree); super.visitMethod(tree); }
private static ModifiersTree getModifierTrees(Tree tree) { ModifiersTree modifiersTree = null; if (tree.is(CLASS_KINDS)) { modifiersTree = ((ClassTree) tree).modifiers(); } else if (tree.is(METHOD_KINDS)) { modifiersTree = ((MethodTree) tree).modifiers(); } else if (tree.is(Kind.VARIABLE)) { modifiersTree = ((VariableTree) tree).modifiers(); } return modifiersTree; }
private static boolean isAllowingNull(MethodTree methodTree) { for (AnnotationTree annotation : methodTree.modifiers().annotations()) { Type type = annotation.annotationType().symbolType(); if (type.is("javax.annotation.Nullable") || type.is("javax.annotation.CheckForNull")) { return true; } } return false; } }
private static boolean isPublicApi(ClassTree classTree, MethodTree methodTree) { Preconditions.checkNotNull(classTree); if (isPublicInterface(classTree)) { return !hasOverrideAnnotation(methodTree); } else if (isEmptyDefaultConstructor(methodTree) || hasOverrideAnnotation(methodTree) || classTree.is(Tree.Kind.INTERFACE, Tree.Kind.ANNOTATION_TYPE) || constructorOfNonPublicClass(methodTree, classTree)) { return false; } return hasPublic(methodTree.modifiers()); }
@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 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); }
@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 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) { scan(tree.modifiers()); scan(tree.typeParameters()); scan(tree.returnType()); scan(tree.simpleName()); scan(tree.parameters()); scan(tree.defaultValue()); scan(tree.throwsClauses()); scan(tree.block()); }