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");
}
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");
}
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");
}
Aggregations