Search in sources :

Example 46 with SyntaxToken

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

the class MethodInvocationTreeImplTest method first_token.

@Test
public void first_token() {
    CompilationUnitTree cut = createTree("class A {\n" + "  void bar(){\n" + "    foo();\n" + "  }" + "}");
    ClassTree classTree = (ClassTree) cut.types().get(0);
    MethodInvocationTree mit = (MethodInvocationTree) ((ExpressionStatementTree) ((MethodTree) (classTree.members().get(0))).block().body().get(0)).expression();
    SyntaxToken firstToken = mit.firstToken();
    assertThat(firstToken.text()).isEqualTo("foo");
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken) MethodTree(org.sonar.plugins.java.api.tree.MethodTree) MethodInvocationTree(org.sonar.plugins.java.api.tree.MethodInvocationTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree) Test(org.junit.Test)

Example 47 with SyntaxToken

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

the class MethodInvocationTreeImplTest method first_token_with_type_arguments.

@Test
public void first_token_with_type_arguments() {
    CompilationUnitTree cut = createTree("class A {\n" + "  void bar(){\n" + "    new A().<String>foo();\n" + "  }" + "  <T> void foo() {}" + "}");
    ClassTree classTree = (ClassTree) cut.types().get(0);
    MethodInvocationTree mit = (MethodInvocationTree) ((ExpressionStatementTree) ((MethodTree) (classTree.members().get(0))).block().body().get(0)).expression();
    SyntaxToken firstToken = mit.firstToken();
    assertThat(firstToken.text()).isEqualTo("new");
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken) MethodTree(org.sonar.plugins.java.api.tree.MethodTree) MethodInvocationTree(org.sonar.plugins.java.api.tree.MethodInvocationTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree) Test(org.junit.Test)

Aggregations

SyntaxToken (org.sonar.plugins.java.api.tree.SyntaxToken)47 Tree (org.sonar.plugins.java.api.tree.Tree)9 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)7 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)7 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)7 Test (org.junit.Test)6 VariableTree (org.sonar.plugins.java.api.tree.VariableTree)6 AssignmentExpressionTree (org.sonar.plugins.java.api.tree.AssignmentExpressionTree)5 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)5 ImmutableList (com.google.common.collect.ImmutableList)4 BlockTree (org.sonar.plugins.java.api.tree.BlockTree)4 ClassTree (org.sonar.plugins.java.api.tree.ClassTree)4 IfStatementTree (org.sonar.plugins.java.api.tree.IfStatementTree)3 MethodInvocationTree (org.sonar.plugins.java.api.tree.MethodInvocationTree)3 StatementTree (org.sonar.plugins.java.api.tree.StatementTree)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 CheckForNull (javax.annotation.CheckForNull)2