Search in sources :

Example 86 with VariableTree

use of org.sonar.plugins.java.api.tree.VariableTree in project sonar-java by SonarSource.

the class GenericsTest method declaredTypesOfVariablesFromLastClass.

private static List<Type> declaredTypesOfVariablesFromLastClass(String... lines) {
    CompilationUnitTree tree = treeOf(lines);
    List<Tree> declaredClasses = tree.types();
    Tree last = declaredClasses.get(declaredClasses.size() - 1);
    if (!(last instanceof ClassTree)) {
        return Collections.emptyList();
    }
    ClassTree testClass = (ClassTree) last;
    List<Type> types = new ArrayList<>();
    for (Tree member : testClass.members()) {
        if (member instanceof VariableTree) {
            types.add(((VariableTree) member).type().symbolType());
        }
    }
    return types;
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) Type(org.sonar.plugins.java.api.semantic.Type) ClassTree(org.sonar.plugins.java.api.tree.ClassTree) ArrayList(java.util.ArrayList) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) Tree(org.sonar.plugins.java.api.tree.Tree) MethodInvocationTree(org.sonar.plugins.java.api.tree.MethodInvocationTree) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree)

Aggregations

VariableTree (org.sonar.plugins.java.api.tree.VariableTree)86 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)32 Tree (org.sonar.plugins.java.api.tree.Tree)32 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)29 ClassTree (org.sonar.plugins.java.api.tree.ClassTree)27 Test (org.junit.Test)25 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)22 Symbol (org.sonar.plugins.java.api.semantic.Symbol)18 MethodInvocationTree (org.sonar.plugins.java.api.tree.MethodInvocationTree)18 MemberSelectExpressionTree (org.sonar.plugins.java.api.tree.MemberSelectExpressionTree)17 AssignmentExpressionTree (org.sonar.plugins.java.api.tree.AssignmentExpressionTree)16 NewClassTree (org.sonar.plugins.java.api.tree.NewClassTree)13 List (java.util.List)12 CompilationUnitTree (org.sonar.plugins.java.api.tree.CompilationUnitTree)12 ReturnStatementTree (org.sonar.plugins.java.api.tree.ReturnStatementTree)12 BinaryExpressionTree (org.sonar.plugins.java.api.tree.BinaryExpressionTree)11 BlockTree (org.sonar.plugins.java.api.tree.BlockTree)11 StatementTree (org.sonar.plugins.java.api.tree.StatementTree)10 TypeTree (org.sonar.plugins.java.api.tree.TypeTree)10 Type (org.sonar.plugins.java.api.semantic.Type)9