Search in sources :

Example 51 with StatementTree

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

the class SyntaxTreeNameFinderTest method testMethodInvocationOnIdentifier.

@Test
public void testMethodInvocationOnIdentifier() {
    MethodTree tree = buildSyntaxTree("public void test() {String s; s.length();}");
    BlockTree block = tree.block();
    StatementTree statementTree = block.body().get(1);
    assertThat(SyntaxTreeNameFinder.getName(statementTree)).isEqualTo("length");
}
Also used : ExpressionStatementTree(org.sonar.plugins.java.api.tree.ExpressionStatementTree) StatementTree(org.sonar.plugins.java.api.tree.StatementTree) MethodTree(org.sonar.plugins.java.api.tree.MethodTree) BlockTree(org.sonar.plugins.java.api.tree.BlockTree) Test(org.junit.Test)

Example 52 with StatementTree

use of org.sonar.plugins.java.api.tree.StatementTree 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)

Example 53 with StatementTree

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

the class SyntaxTreeNameFinderTest method testMethodInvocationOnOtherInvocation.

@Test
public void testMethodInvocationOnOtherInvocation() {
    MethodTree tree = buildSyntaxTree("public void test() {int i = checkForNullMethod().length();}");
    BlockTree block = tree.block();
    StatementTree statementTree = block.body().get(0);
    assertThat(SyntaxTreeNameFinder.getName(statementTree)).isEqualTo("length");
}
Also used : ExpressionStatementTree(org.sonar.plugins.java.api.tree.ExpressionStatementTree) StatementTree(org.sonar.plugins.java.api.tree.StatementTree) MethodTree(org.sonar.plugins.java.api.tree.MethodTree) BlockTree(org.sonar.plugins.java.api.tree.BlockTree) Test(org.junit.Test)

Aggregations

StatementTree (org.sonar.plugins.java.api.tree.StatementTree)53 IfStatementTree (org.sonar.plugins.java.api.tree.IfStatementTree)27 Test (org.junit.Test)26 ExpressionStatementTree (org.sonar.plugins.java.api.tree.ExpressionStatementTree)26 ReturnStatementTree (org.sonar.plugins.java.api.tree.ReturnStatementTree)24 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)21 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)17 BlockTree (org.sonar.plugins.java.api.tree.BlockTree)15 AssignmentExpressionTree (org.sonar.plugins.java.api.tree.AssignmentExpressionTree)13 ForStatementTree (org.sonar.plugins.java.api.tree.ForStatementTree)9 WhileStatementTree (org.sonar.plugins.java.api.tree.WhileStatementTree)8 ClassTree (org.sonar.plugins.java.api.tree.ClassTree)7 VariableTree (org.sonar.plugins.java.api.tree.VariableTree)7 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)6 MethodInvocationTree (org.sonar.plugins.java.api.tree.MethodInvocationTree)6 SwitchStatementTree (org.sonar.plugins.java.api.tree.SwitchStatementTree)6 ThrowStatementTree (org.sonar.plugins.java.api.tree.ThrowStatementTree)6 CompilationUnitTree (org.sonar.plugins.java.api.tree.CompilationUnitTree)5 Tree (org.sonar.plugins.java.api.tree.Tree)5 TryStatementTree (org.sonar.plugins.java.api.tree.TryStatementTree)5