use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class BytecodeCompleterTest method forward_type_parameter_in_classes.
@Test
public void forward_type_parameter_in_classes() throws Exception {
Symbol.TypeSymbol clazz = bytecodeCompleter.getClassSymbol("org.sonar.java.resolve.targets.ForwardParameterInClass");
assertThat(clazz.type()).isNotNull();
Collection<Symbol> symbols = clazz.lookupSymbols("bar");
assertThat(symbols).hasSize(1);
Collection<JavaSymbol> typeParameters = ((JavaSymbol.TypeJavaSymbol) clazz).typeParameters().scopeSymbols();
assertThat(typeParameters).hasSize(2);
JavaSymbol xSymbol = ((JavaSymbol.TypeJavaSymbol) clazz).typeParameters().lookup("X").iterator().next();
JavaSymbol ySymbol = ((JavaSymbol.TypeJavaSymbol) clazz).typeParameters().lookup("Y").iterator().next();
assertThat(((TypeVariableJavaType) xSymbol.type).bounds).hasSize(1);
JavaType bound = ((TypeVariableJavaType) xSymbol.type).bounds.get(0);
assertThat(((ParametrizedTypeJavaType) bound).typeParameters()).hasSize(1);
assertThat(((ParametrizedTypeJavaType) bound).substitution(((ParametrizedTypeJavaType) bound).typeParameters().get(0))).isSameAs(ySymbol.type);
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class BytecodeCompleterTest method innerClassWithDollarName.
@Test
public void innerClassWithDollarName() throws Exception {
JavaSymbol.TypeJavaSymbol classSymbol = bytecodeCompleter.getClassSymbol("org/sonar/java/resolve/targets/UseDollarNames");
// Complete superclass which has an inner class named A$Bq
JavaType superclass = classSymbol.getSuperclass();
JavaType superSuperClass = superclass.getSymbol().getSuperclass();
assertThat(superSuperClass.fullyQualifiedName()).isEqualTo("java.lang.Object");
Collection<Symbol> symbols = superclass.getSymbol().memberSymbols();
for (Symbol symbol : symbols) {
if (symbol.isTypeSymbol()) {
assertThat(symbol.name()).isEqualTo("A$B");
Collection<Symbol> members = ((Symbol.TypeSymbol) symbol).lookupSymbols("C$D");
assertThat(members).isNotEmpty();
}
}
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class SymbolTableTest method enum_protected_constructor_should_not_be_resolved.
@Test
public void enum_protected_constructor_should_not_be_resolved() {
Result result = Result.createFor("EnumConstructor");
Symbol constructorRef = result.referenceTree(2, 3).symbol();
assertThat(constructorRef.name()).isEqualTo("<init>");
assertThat(constructorRef.owner().type().is("java.lang.Enum")).overridingErrorMessage("Wrongly resolving unaccessible protected enum constructor").isFalse();
assertThat(constructorRef.owner().type().is("EnumConstructor")).isTrue();
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class SymbolTableTest method annotations_on_fields.
@Test
public void annotations_on_fields() throws Exception {
Result result = Result.createFor("AnnotationOnFields");
JavaSymbol.TypeSymbol app = (JavaSymbol.TypeSymbol) result.symbol("App");
for (Symbol sym : app.memberSymbols()) {
if (!sym.isMethodSymbol() && !(sym.name().equals("super") || sym.name().equals("this"))) {
assertThat(sym.metadata().isAnnotatedWith("java.lang.Deprecated")).isTrue();
}
}
}
use of org.sonar.plugins.java.api.semantic.Symbol in project sonar-java by SonarSource.
the class SymbolTableTest method symbolNotFound.
@Test
public void symbolNotFound() throws Exception {
Result result = Result.createFor("SymbolsNotFound");
MethodTree methodDeclaration = (MethodTree) result.symbol("method").declaration();
ExpressionStatementTree expression = (ExpressionStatementTree) methodDeclaration.block().body().get(0);
MethodInvocationTree methodInvocation = (MethodInvocationTree) expression.expression();
Symbol symbolNotFound = methodInvocation.symbol();
assertThat(symbolNotFound).isNotNull();
assertThat(symbolNotFound.name()).isNull();
assertThat(symbolNotFound.owner()).isSameAs(Symbols.unknownSymbol);
}
Aggregations