Search in sources :

Example 21 with ExpressionStatementTree

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

the class SyntaxTreeNameFinderTest method testClassCast.

@Test
public void testClassCast() {
    MethodTree tree = buildSyntaxTree("public boolean equals(Object obj) {((String) obj).length;}");
    BlockTree block = tree.block();
    StatementTree statementTree = block.body().get(0);
    MemberSelectExpressionTree mse = (MemberSelectExpressionTree) ((ExpressionStatementTree) statementTree).expression();
    assertThat(SyntaxTreeNameFinder.getName(mse)).isEqualTo("obj");
}
Also used : ExpressionStatementTree(org.sonar.plugins.java.api.tree.ExpressionStatementTree) StatementTree(org.sonar.plugins.java.api.tree.StatementTree) MemberSelectExpressionTree(org.sonar.plugins.java.api.tree.MemberSelectExpressionTree) MethodTree(org.sonar.plugins.java.api.tree.MethodTree) BlockTree(org.sonar.plugins.java.api.tree.BlockTree) Test(org.junit.Test)

Aggregations

ExpressionStatementTree (org.sonar.plugins.java.api.tree.ExpressionStatementTree)21 Test (org.junit.Test)11 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)11 MethodInvocationTree (org.sonar.plugins.java.api.tree.MethodInvocationTree)11 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)10 Symbol (org.sonar.plugins.java.api.semantic.Symbol)7 AssignmentExpressionTree (org.sonar.plugins.java.api.tree.AssignmentExpressionTree)7 CompilationUnitTree (org.sonar.plugins.java.api.tree.CompilationUnitTree)7 StatementTree (org.sonar.plugins.java.api.tree.StatementTree)7 ClassTree (org.sonar.plugins.java.api.tree.ClassTree)6 MemberSelectExpressionTree (org.sonar.plugins.java.api.tree.MemberSelectExpressionTree)6 BlockTree (org.sonar.plugins.java.api.tree.BlockTree)5 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)5 ReturnStatementTree (org.sonar.plugins.java.api.tree.ReturnStatementTree)5 Tree (org.sonar.plugins.java.api.tree.Tree)4 ArrayAccessExpressionTree (org.sonar.plugins.java.api.tree.ArrayAccessExpressionTree)3 UnaryExpressionTree (org.sonar.plugins.java.api.tree.UnaryExpressionTree)3 VariableTree (org.sonar.plugins.java.api.tree.VariableTree)3 CheckForNull (javax.annotation.CheckForNull)2 SquidClassLoader (org.sonar.java.bytecode.loader.SquidClassLoader)2