use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class ModifiersUtilsTest method test_find_modifier.
@Test
public void test_find_modifier() {
File file = new File("src/test/files/model/ModifiersUtilsTest.java");
CompilationUnitTree tree = (CompilationUnitTree) JavaParser.createParser().parse(file);
ClassTree classTree = (ClassTree) tree.types().get(0);
assertThat(ModifiersUtils.findModifier(classTree.modifiers(), Modifier.PUBLIC).isPresent()).isTrue();
assertThat(ModifiersUtils.findModifier(classTree.modifiers(), Modifier.ABSTRACT).isPresent()).isFalse();
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class ModifiersUtilsTest method test_int_and_long_value.
@Test
public void test_int_and_long_value() throws Exception {
File file = new File("src/test/files/model/ModifiersUtilsTest.java");
CompilationUnitTree tree = (CompilationUnitTree) JavaParser.createParser().parse(file);
ClassTree classTree = (ClassTree) tree.types().get(0);
assertThat(ModifiersUtils.hasModifier(classTree.modifiers(), Modifier.PUBLIC)).isTrue();
assertThat(ModifiersUtils.getModifier(classTree.modifiers(), Modifier.PUBLIC).keyword().text()).isEqualTo("public");
assertThat(ModifiersUtils.hasModifier(classTree.modifiers(), Modifier.ABSTRACT)).isFalse();
assertThat(ModifiersUtils.getModifier(classTree.modifiers(), Modifier.ABSTRACT)).isNull();
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class ClassTreeImplTest method getLine.
@Test
public void getLine() {
CompilationUnitTree tree = createTree("class A {\n" + "A a = new A() {};" + "\n}");
ClassTree classTree = (ClassTree) tree.types().get(0);
assertThat(((JavaTree) classTree).getLine()).isEqualTo(1);
// get line of anonymous class
NewClassTree newClassTree = (NewClassTree) ((VariableTree) classTree.members().get(0)).initializer();
assertThat(((JavaTree) newClassTree.classBody()).getLine()).isEqualTo(2);
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class MethodTreeImplTest method symbol_not_set_should_lead_to_null_result.
@Test
public void symbol_not_set_should_lead_to_null_result() throws Exception {
CompilationUnitTree cut = (CompilationUnitTree) p.parse("class A { String toString(){return \"\";}}");
MethodTreeImpl methodTree = (MethodTreeImpl) ((ClassTree) cut.types().get(0)).members().get(0);
assertThat(methodTree.isOverriding()).isNull();
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class MethodInvocationTreeImplTest method symbol_should_be_set.
@Test
public void symbol_should_be_set() {
CompilationUnitTree cut = createTree("class A { void foo(){} void bar(){foo();} }");
ClassTree classTree = (ClassTree) cut.types().get(0);
Symbol.MethodSymbol declaration = ((MethodTree) classTree.members().get(0)).symbol();
StatementTree statementTree = ((MethodTree) classTree.members().get(1)).block().body().get(0);
MethodInvocationTree mit = (MethodInvocationTree) ((ExpressionStatementTree) statementTree).expression();
assertThat(mit.symbol()).isSameAs(declaration);
assertThat(mit.arguments()).isNotNull();
assertThat(mit.arguments().openParenToken()).isNotNull();
assertThat(mit.arguments().closeParenToken()).isNotNull();
}
Aggregations