use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class OpensDirectiveTreeImplTest method createTree.
private CompilationUnitTree createTree(String... lines) {
CompilationUnitTree compilationUnitTree = (CompilationUnitTree) p.parse(Arrays.stream(lines).collect(Collectors.joining("\n")));
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return compilationUnitTree;
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class OpensDirectiveTreeImplTest method test_BaseTreeVisitor.
@Test
public void test_BaseTreeVisitor() {
CompilationUnitTree cut = createTree("@org.foo.Bar", "open module com.greetings {", " exports foo;", " requires org.gul;", " opens org.bar to com.module1, module2;", "}");
OpensDirectiveVisitor moduleDeclarationVisitor = new OpensDirectiveVisitor();
cut.accept(moduleDeclarationVisitor);
assertThat(moduleDeclarationVisitor.visited).isTrue();
assertThat(moduleDeclarationVisitor.directives).hasSize(1);
assertThat(moduleDeclarationVisitor.identifiers).containsExactly("com", "greetings", "com", "module1", "module2");
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class ReassignmentFinderTest method classTree.
private ClassTree classTree(String classBody) {
CompilationUnitTree compilationUnitTree = (CompilationUnitTree) p.parse(classBody);
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return (ClassTree) compilationUnitTree.types().get(0);
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class ValueBasedUtilsTest method testIsValueBased.
@Test
public void testIsValueBased() throws Exception {
File file = new File("src/test/files/checks/helpers/ValueBasedUtilsTest.java");
CompilationUnitTree tree = (CompilationUnitTree) JavaParser.createParser().parse(file);
SemanticModel.createFor(tree, new SquidClassLoader(Collections.emptyList()));
List<Tree> members = ((ClassTree) tree.types().get(0)).members();
members.stream().forEach(member -> checkMember((VariableTree) member));
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method initializeClassLoaderAndSemanticModel.
@BeforeClass
public static void initializeClassLoaderAndSemanticModel() {
List<File> files = new ArrayList<>(FileUtils.listFiles(new File("target/test-jars"), new String[] { "jar", "zip" }, true));
files.add(new File("target/classes"));
files.add(new File("target/test-classes"));
squidClassLoader = new SquidClassLoader(files);
File file = new File("src/test/java/org/sonar/java/bytecode/se/BytecodeEGWalkerExecuteTest.java");
CompilationUnitTree tree = (CompilationUnitTree) JavaParser.createParser().parse(file);
semanticModel = SemanticModel.createFor(tree, squidClassLoader);
}
Aggregations