private static boolean isSpringInjectionAnnotated(SymbolMetadata metadata) { return metadata.isAnnotatedWith("org.springframework.beans.factory.annotation.Autowired") || metadata.isAnnotatedWith("javax.inject.Inject") || metadata.isAnnotatedWith("javax.annotation.Resource"); } }
private static boolean isSpringInjectionAnnotated(SymbolMetadata metadata) { return metadata.isAnnotatedWith("org.springframework.beans.factory.annotation.Autowired") || metadata.isAnnotatedWith("javax.inject.Inject") || metadata.isAnnotatedWith("javax.annotation.Resource") || metadata.isAnnotatedWith("org.springframework.beans.factory.annotation.Value"); }
private static boolean isSpringComponent(SymbolMetadata clazzMeta) { return clazzMeta.isAnnotatedWith("org.springframework.stereotype.Controller") || clazzMeta.isAnnotatedWith("org.springframework.stereotype.Service") || clazzMeta.isAnnotatedWith("org.springframework.stereotype.Repository"); }
private static boolean isSpringInjectionAnnotated(SymbolMetadata metadata) { return metadata.isAnnotatedWith("org.springframework.beans.factory.annotation.Autowired") || metadata.isAnnotatedWith("javax.inject.Inject") || metadata.isAnnotatedWith("javax.annotation.Resource") || metadata.isAnnotatedWith("org.springframework.beans.factory.annotation.Value"); }
private static boolean isSpringComponent(SymbolMetadata clazzMeta) { return clazzMeta.isAnnotatedWith("org.springframework.stereotype.Controller") || clazzMeta.isAnnotatedWith("org.springframework.stereotype.Service") || clazzMeta.isAnnotatedWith("org.springframework.stereotype.Repository"); }
private static boolean isSpringComponent(SymbolMetadata clazzMeta) { return clazzMeta.isAnnotatedWith("org.springframework.stereotype.Controller") || clazzMeta.isAnnotatedWith("org.springframework.stereotype.Service") || clazzMeta.isAnnotatedWith("org.springframework.stereotype.Repository"); } }
private static Optional<String> findNullableAnnotation(MethodTree methodTree) { SymbolMetadata methodMetadata = methodTree.symbol().metadata(); if (methodMetadata.isAnnotatedWith("javax.annotation.CheckForNull")) { return Optional.of("@CheckForNull"); } else if (methodMetadata.isAnnotatedWith("javax.annotation.Nullable")) { return Optional.of("@Nullable"); } return Optional.empty(); }
private AbstractValue checkNullity(Symbol symbol) { if (symbol.metadata().isAnnotatedWith("javax.annotation.Nonnull")) { return AbstractValue.NOTNULL; } else if (symbol.metadata().isAnnotatedWith("javax.annotation.CheckForNull")) { return AbstractValue.NULL; } return AbstractValue.UNKNOWN; }
private static boolean isTestMethod(MethodTree methodTree) { SymbolMetadata metadata = methodTree.symbol().metadata(); return metadata.isAnnotatedWith("org.junit.Test") || metadata.isAnnotatedWith("org.testng.annotations.Test"); } }
private static boolean nonNullVsNull(Symbol sym1, Symbol sym2) { return sym1.metadata().isAnnotatedWith(JAVAX_ANNOTATION_NONNULL) && (sym2.metadata().isAnnotatedWith(JAVAX_ANNOTATION_NULLABLE) || sym2.metadata().isAnnotatedWith(JAVAX_ANNOTATION_CHECK_FOR_NULL)); }
private static boolean isAnnotatedWithCheckForNull(MethodTree methodTree) { SymbolMetadata methodMetadata = methodTree.symbol().metadata(); return methodMetadata.isAnnotatedWith("javax.annotation.CheckForNull") || methodMetadata.isAnnotatedWith("javax.annotation.Nullable"); }
private static boolean hasTestMethod(List<Tree> members) { return members.stream() .filter(member -> member.is(Tree.Kind.METHOD)) .map(tree -> ((MethodTree) tree).symbol().metadata()) .anyMatch(metadata -> metadata.isAnnotatedWith("org.junit.Test") || metadata.isAnnotatedWith("org.testng.annotations.Test")); }
private static void collectAutowiredFields(Tree tree, Map<Symbol, VariableTree> autowiredFields) { if (!tree.is(Tree.Kind.VARIABLE)) { return; } VariableTree variable = (VariableTree) tree; Symbol variableSymbol = variable.symbol(); if (AUTOWIRED_ANNOTATIONS.stream().anyMatch(a -> variableSymbol.metadata().isAnnotatedWith(a))) { autowiredFields.put(variableSymbol, variable); } }
private static boolean usesAnnotation(ClassTree classTree, List<String> annotations) { SymbolMetadata metadata = classTree.symbol().metadata(); for (String annotation : annotations) { if (metadata.isAnnotatedWith(annotation)) { return true; } } return false; }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } if (tree.is(Tree.Kind.METHOD)) { ((MethodTree) tree).parameters().stream() .filter(v -> v.symbol().metadata().isAnnotatedWith("org.springframework.web.bind.annotation.CookieValue")) .forEach(v -> reportIssue(v.modifiers(), MESSAGE)); } else { super.visitNode(tree); } }
private static boolean isTransientSerializableOrInjected(VariableTree member) { if (ModifiersUtils.hasModifier(member.modifiers(), Modifier.TRANSIENT) || (isSerializable(member.type()) && !isSubtypeOfCollectionApi(member.type().symbolType()))) { return true; } SymbolMetadata metadata = member.symbol().metadata(); return metadata.isAnnotatedWith("javax.inject.Inject") || metadata.isAnnotatedWith("javax.ejb.EJB"); }
private static boolean isSpringWebHandler(AnnotationTree annotationTree) { Type annotationType = annotationTree.annotationType().symbolType(); return annotationType.is(REQUEST_MAPPING_ANNOTATION) || annotationType.symbol().metadata().isAnnotatedWith(REQUEST_MAPPING_ANNOTATION); } }
@Override public void visitNode(Tree tree) { ClassTree clazzTree = (ClassTree) tree; SymbolMetadata clazzMeta = clazzTree.symbol().metadata(); if (isSpringComponent(clazzMeta) && clazzMeta.isAnnotatedWith(SCOPE_ANNOTATION_FQN) && !isScopeSingleton(clazzMeta)) { checkScopeAnnotation(clazzTree); } }
private static boolean isUnitTest(MethodTree methodTree) { Symbol.MethodSymbol symbol = methodTree.symbol(); while (symbol != null) { if (symbol.metadata().isAnnotatedWith("org.junit.Test")) { return true; } symbol = symbol.overriddenSymbol(); } Symbol.TypeSymbol enclosingClass = methodTree.symbol().enclosingClass(); return enclosingClass != null && enclosingClass.type().isSubtypeOf("junit.framework.TestCase") && methodTree.simpleName().name().startsWith("test"); }
private static boolean isUnitTest(MethodTree methodTree) { Symbol.MethodSymbol symbol = methodTree.symbol(); while (symbol != null) { if (symbol.metadata().isAnnotatedWith("org.junit.Test")) { return true; } symbol = symbol.overriddenSymbol(); } Symbol.TypeSymbol enclosingClass = methodTree.symbol().enclosingClass(); return enclosingClass != null && enclosingClass.type().isSubtypeOf("junit.framework.TestCase") && methodTree.simpleName().name().startsWith("test"); }