Search in sources :

Example 1 with MethodJavaSymbol

use of org.sonar.java.resolve.JavaSymbol.MethodJavaSymbol in project sonar-java by SonarSource.

the class ThreadAsRunnableArgumentCheck method visitNode.

@Override
public void visitNode(Tree tree) {
    if (!hasSemantic()) {
        return;
    }
    List<ExpressionTree> arguments;
    Symbol methodSymbol;
    if (tree.is(Kind.NEW_CLASS)) {
        NewClassTree nct = (NewClassTree) tree;
        methodSymbol = nct.constructorSymbol();
        arguments = nct.arguments();
    } else {
        MethodInvocationTree mit = (MethodInvocationTree) tree;
        methodSymbol = mit.symbol();
        arguments = mit.arguments();
    }
    if (!arguments.isEmpty() && methodSymbol.isMethodSymbol()) {
        checkArgumentsTypes(arguments, (MethodJavaSymbol) methodSymbol);
    }
}
Also used : MethodJavaSymbol(org.sonar.java.resolve.JavaSymbol.MethodJavaSymbol) Symbol(org.sonar.plugins.java.api.semantic.Symbol) MethodInvocationTree(org.sonar.plugins.java.api.tree.MethodInvocationTree) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) NewClassTree(org.sonar.plugins.java.api.tree.NewClassTree)

Example 2 with MethodJavaSymbol

use of org.sonar.java.resolve.JavaSymbol.MethodJavaSymbol in project sonar-java by SonarSource.

the class GenericsTest method test_method_resolution_with_unchecked_conversions.

@Test
public void test_method_resolution_with_unchecked_conversions() {
    // JLS8 5.1.9 + JLS8 15.12.2.6
    JavaType bType = (JavaType) declaredTypesFromFile("src/test/files/resolve/UncheckedConversion.java").get(0);
    MethodJavaSymbol foo = getMethodSymbol(bType, "foo");
    Type type = getMethodInvocationType(foo, 0);
    assertThat(type.isArray()).isTrue();
    assertThat(((ArrayJavaType) type).elementType.is("java.lang.Object")).isTrue();
    type = getMethodInvocationType(foo, 1);
    assertThat(type.isArray()).isTrue();
    assertThat(((ArrayJavaType) type).elementType.is("org.foo.A")).isTrue();
    type = getMethodInvocationType(foo, 2);
    assertThat(type.isArray()).isTrue();
    assertThat(((ArrayJavaType) type).elementType.is("org.foo.A")).isTrue();
    methodHasUsagesWithSameTypeAs(bType, "bar", "objectType", "aType", "aType");
    methodHasUsagesWithSameTypeAs(bType, "qix", "bRawType", "bAType", "bAType");
    methodHasUsagesWithSameTypeAs(bType, "gul", "bRawType", "bBAType", "bBAType");
    methodHasUsagesWithSameTypeAs(bType, "lot", "aType", "cType", "cType");
}
Also used : Type(org.sonar.plugins.java.api.semantic.Type) MethodJavaSymbol(org.sonar.java.resolve.JavaSymbol.MethodJavaSymbol) Test(org.junit.Test)

Aggregations

MethodJavaSymbol (org.sonar.java.resolve.JavaSymbol.MethodJavaSymbol)2 Test (org.junit.Test)1 Symbol (org.sonar.plugins.java.api.semantic.Symbol)1 Type (org.sonar.plugins.java.api.semantic.Type)1 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)1 MethodInvocationTree (org.sonar.plugins.java.api.tree.MethodInvocationTree)1 NewClassTree (org.sonar.plugins.java.api.tree.NewClassTree)1