use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class SyntacticEquivalenceTest method getAssertion.
private AbstractBooleanAssert<?> getAssertion(List<String> statement1, List<String> statement2) {
CompilationUnitTree compilationUnitTree = compilationUnitTree("class A { void method1() { " + Joiner.on(";").join(statement1) + ";} " + "void method2(){ " + Joiner.on(";").join(statement2) + ";} }");
ClassTree classTree = ((ClassTree) compilationUnitTree.types().get(0));
assertThat(classTree.members()).hasSize(2);
return assertThat(SyntacticEquivalence.areEquivalent(((MethodTree) classTree.members().get(0)).block().body(), ((MethodTree) classTree.members().get(1)).block().body()));
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class MethodTreeImplTest method hiding_of_static_methods.
@Test
public void hiding_of_static_methods() {
CompilationUnitTree cut = createTree("class A { static void foo() {} } class B extends A { void foo(){} } ");
ClassTree clazz = (ClassTree) cut.types().get(1);
MethodTreeImpl methodTree = (MethodTreeImpl) clazz.members().get(0);
assertThat(methodTree.isOverriding()).isFalse();
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class MethodTreeImplTest method override_with_generic_parameters_should_be_detected.
@Test
public void override_with_generic_parameters_should_be_detected() throws Exception {
CompilationUnitTree cut = createTree("public class ReferenceQueue<T> {\n" + "\n" + " private static class Null extends ReferenceQueue {\n" + " boolean enqueue(Reference r) {\n" + " return false;\n" + " }\n" + " }\n" + " boolean enqueue(Reference<? extends T> r) {}}" + "public abstract class Reference<T> {}");
ClassTree innerClass = (ClassTree) cut.types().get(0);
MethodTreeImpl methodInterface = (MethodTreeImpl) ((ClassTree) innerClass.members().get(0)).members().get(0);
assertThat(methodInterface.isOverriding()).isTrue();
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class MethodTreeImplTest method override_without_annotation_should_be_detected.
@Test
public void override_without_annotation_should_be_detected() {
CompilationUnitTree cut = createTree("interface T { int m(); } class A implements T { int m(){return 0;}}");
ClassTree interfaze = (ClassTree) cut.types().get(0);
MethodTreeImpl methodInterface = (MethodTreeImpl) interfaze.members().get(0);
ClassTree clazz = (ClassTree) cut.types().get(1);
MethodTreeImpl methodClazz = (MethodTreeImpl) clazz.members().get(0);
assertThat(methodInterface.isOverriding()).isFalse();
assertThat(methodClazz.isOverriding()).isTrue();
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class MethodTreeImplTest method createTree.
private CompilationUnitTree createTree(String code) {
CompilationUnitTree compilationUnitTree = (CompilationUnitTree) p.parse(code);
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return compilationUnitTree;
}
Aggregations