use of org.sonar.plugins.java.api.semantic.SymbolMetadata in project sonar-java by SonarSource.
the class NullableAnnotationUtils method nonNullAnnotation.
@CheckForNull
public static String nonNullAnnotation(Symbol symbol) {
SymbolMetadata metadata = symbol.metadata();
if (isNullableThroughNonNull(symbol)) {
return null;
}
Optional<String> result = NONNULL_ANNOTATIONS.stream().filter(metadata::isAnnotatedWith).findFirst();
if (result.isPresent()) {
return result.get();
}
if (isMethodAnnotatedWithEclipseNonNullReturnType(symbol)) {
return ORG_ECLIPSE_JDT_ANNOTATION_NON_NULL_BY_DEFAULT;
}
return null;
}
use of org.sonar.plugins.java.api.semantic.SymbolMetadata in project sonar-java by SonarSource.
the class BytecodeCompleterTest method annotationArrayOfEnum.
@Test
public void annotationArrayOfEnum() {
JavaSymbol.TypeJavaSymbol classSymbol = bytecodeCompleter.getClassSymbol("org.sonar.java.resolve.targets.AnnotationSymbolMethod");
Symbol barMethod = classSymbol.memberSymbols().stream().filter(symbol -> "bar".equals(symbol.name())).findFirst().get();
SymbolMetadata barMetadata = barMethod.metadata();
assertThat(barMetadata.annotations()).hasSize(1);
List<SymbolMetadata.AnnotationValue> valuesForAnnotation = barMetadata.valuesForAnnotation("org.sonar.java.resolve.targets.ArrayEnumAnnotation");
assertThat(valuesForAnnotation).hasSize(1);
assertThat(valuesForAnnotation.get(0).name()).isEqualTo("value");
Object annotationValue = valuesForAnnotation.get(0).value();
assertThat(annotationValue).isInstanceOf(Object[].class);
assertThat((Object[]) annotationValue).hasSize(2);
assertThat(Arrays.stream((Object[]) annotationValue)).allMatch(o -> o instanceof Symbol && ((Symbol) o).type().is("org.sonar.java.resolve.targets.MyEnum"));
}
use of org.sonar.plugins.java.api.semantic.SymbolMetadata in project sonar-java by SonarSource.
the class SpringComponentWithWrongScopeCheck method visitNode.
@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);
}
}
use of org.sonar.plugins.java.api.semantic.SymbolMetadata in project sonar-java by SonarSource.
the class NoTestInTestClassCheck method isJUnitTestableMetaAnnotated.
private boolean isJUnitTestableMetaAnnotated(Type type) {
if (seenAnnotations.contains(type.fullyQualifiedName())) {
return false;
}
seenAnnotations.add(type.fullyQualifiedName());
SymbolMetadata metadata = type.symbol().metadata();
if (metadata.isAnnotatedWith("org.junit.platform.commons.annotation.Testable")) {
testAnnotations.add(type.fullyQualifiedName());
return true;
}
for (SymbolMetadata.AnnotationInstance annotation : metadata.annotations()) {
if (isJUnitTestableMetaAnnotated(annotation.symbol().type())) {
testAnnotations.add(type.fullyQualifiedName());
return true;
}
}
return false;
}
use of org.sonar.plugins.java.api.semantic.SymbolMetadata in project sonar-java by SonarSource.
the class SpringComponentWithNonAutowiredMembersCheck method visitNode.
@Override
public void visitNode(Tree tree) {
ClassTree clazzTree = (ClassTree) tree;
SymbolMetadata clazzMeta = clazzTree.symbol().metadata();
if (isSpringComponent(clazzMeta) && !hasUniqueConstructor(clazzTree)) {
clazzTree.members().stream().filter(v -> v.is(Kind.VARIABLE)).map(m -> (VariableTree) m).filter(v -> !v.symbol().isStatic()).filter(v -> !isSpringInjectionAnnotated(v.symbol().metadata())).forEach(v -> reportIssue(v.simpleName(), "Annotate this member with \"@Autowired\", \"@Resource\", \"@Inject\", or \"@Value\", or remove it."));
}
}
Aggregations