Search in sources :

Example 11 with Type

use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.

the class CastArithmeticOperandCheck method checkMethodInvocationArgument.

private void checkMethodInvocationArgument(MethodInvocationTree mit) {
    Symbol symbol = mit.symbol();
    if (symbol.isMethodSymbol()) {
        List<Type> parametersTypes = ((Symbol.MethodSymbol) symbol).parameterTypes();
        if (mit.arguments().size() == parametersTypes.size()) {
            int i = 0;
            for (Type argType : parametersTypes) {
                checkExpression(argType, mit.arguments().get(i));
                i++;
            }
        }
    }
}
Also used : Type(org.sonar.plugins.java.api.semantic.Type) Symbol(org.sonar.plugins.java.api.semantic.Symbol)

Example 12 with Type

use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.

the class CastArithmeticOperandCheck method visitAssignmentExpression.

@Override
public void visitAssignmentExpression(AssignmentExpressionTree aet) {
    if (aet.is(Tree.Kind.ASSIGNMENT)) {
        Type varType = aet.symbolType();
        ExpressionTree expr = aet.expression();
        checkExpression(varType, expr);
    }
    super.visitAssignmentExpression(aet);
}
Also used : Type(org.sonar.plugins.java.api.semantic.Type) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) AssignmentExpressionTree(org.sonar.plugins.java.api.tree.AssignmentExpressionTree) BinaryExpressionTree(org.sonar.plugins.java.api.tree.BinaryExpressionTree)

Example 13 with Type

use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.

the class BytecodeCompleterTest method class_not_found_should_have_unknown_super_type_and_no_interfaces.

@Test
public void class_not_found_should_have_unknown_super_type_and_no_interfaces() {
    Symbol.TypeSymbol clazz = bytecodeCompleter.getClassSymbol("org.sonar.java.resolve.targets.UnknownClass");
    assertThat(clazz.type()).isNotNull();
    Type superClass = clazz.superClass();
    assertThat(superClass).isNotNull();
    assertThat(superClass).isSameAs(Symbols.unknownType);
    List<Type> interfaces = clazz.interfaces();
    assertThat(interfaces).isNotNull();
    assertThat(interfaces).isEmpty();
    assertThat(bytecodeCompleter.classesNotFound()).containsOnly("org.sonar.java.resolve.targets.UnknownClass");
}
Also used : Type(org.sonar.plugins.java.api.semantic.Type) TypeJavaSymbol(org.sonar.java.resolve.JavaSymbol.TypeJavaSymbol) Symbol(org.sonar.plugins.java.api.semantic.Symbol) Test(org.junit.Test)

Example 14 with Type

use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.

the class LeastUpperBoundTest method declaredTypes.

private static List<Type> declaredTypes(String... lines) {
    CompilationUnitTree tree = treeOf(lines);
    List<Type> results = Lists.newLinkedList();
    for (Tree classTree : tree.types()) {
        Type type = ((ClassTree) classTree).symbol().type();
        results.add(type);
    }
    return results;
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) Type(org.sonar.plugins.java.api.semantic.Type) CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) Tree(org.sonar.plugins.java.api.tree.Tree) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree)

Example 15 with Type

use of org.sonar.plugins.java.api.semantic.Type in project sonar-java by SonarSource.

the class LeastUpperBoundTest method lub_with_shared_supertypes3.

@Test
public void lub_with_shared_supertypes3() {
    List<Type> typesFromInput = declaredTypes("class A extends Exception {}", "class B {}");
    Type a = typesFromInput.get(0);
    Type b = typesFromInput.get(1);
    Type lub = leastUpperBound(a, b);
    assertThat(lub.is("java.lang.Object")).isTrue();
}
Also used : Type(org.sonar.plugins.java.api.semantic.Type) Test(org.junit.Test)

Aggregations

Type (org.sonar.plugins.java.api.semantic.Type)164 Test (org.junit.Test)67 Symbol (org.sonar.plugins.java.api.semantic.Symbol)23 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)23 MethodJavaSymbol (org.sonar.java.resolve.JavaSymbol.MethodJavaSymbol)18 ClassTree (org.sonar.plugins.java.api.tree.ClassTree)18 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)17 MethodInvocationTree (org.sonar.plugins.java.api.tree.MethodInvocationTree)17 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)17 JavaType (org.sonar.java.resolve.JavaType)16 Tree (org.sonar.plugins.java.api.tree.Tree)15 VariableTree (org.sonar.plugins.java.api.tree.VariableTree)13 MemberSelectExpressionTree (org.sonar.plugins.java.api.tree.MemberSelectExpressionTree)12 SymbolicValue (org.sonar.java.se.symbolicvalues.SymbolicValue)11 AssignmentExpressionTree (org.sonar.plugins.java.api.tree.AssignmentExpressionTree)10 ArrayList (java.util.ArrayList)9 TypeTree (org.sonar.plugins.java.api.tree.TypeTree)9 VisibleForTesting (com.google.common.annotations.VisibleForTesting)8 RelationalSymbolicValue (org.sonar.java.se.symbolicvalues.RelationalSymbolicValue)8 CompilationUnitTree (org.sonar.plugins.java.api.tree.CompilationUnitTree)8