use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class VisitorsBridge method visitFile.
public void visitFile(@Nullable Tree parsedTree) {
semanticModel = null;
CompilationUnitTree tree = new JavaTree.CompilationUnitTreeImpl(null, new ArrayList<>(), new ArrayList<>(), null, null);
boolean fileParsed = parsedTree != null;
if (fileParsed && parsedTree.is(Tree.Kind.COMPILATION_UNIT)) {
tree = (CompilationUnitTree) parsedTree;
if (isNotJavaLangOrSerializable(PackageUtils.packageName(tree.packageDeclaration(), "/"))) {
try {
semanticModel = SemanticModel.createFor(tree, classLoader);
} catch (Exception e) {
LOG.error("Unable to create symbol table for : " + currentFile.getAbsolutePath(), e);
addAnalysisError(e, currentFile.getPath(), AnalysisError.Kind.SEMANTIC_ERROR);
return;
}
createSonarSymbolTable(tree);
} else {
SemanticModel.handleMissingTypes(tree);
}
}
JavaFileScannerContext javaFileScannerContext = createScannerContext(tree, semanticModel, sonarComponents, fileParsed);
// Symbolic execution checks
if (symbolicExecutionEnabled && isNotJavaLangOrSerializable(PackageUtils.packageName(tree.packageDeclaration(), "/"))) {
runScanner(javaFileScannerContext, new SymbolicExecutionVisitor(executableScanners, behaviorCache), AnalysisError.Kind.SE_ERROR);
behaviorCache.cleanup();
}
executableScanners.forEach(scanner -> runScanner(javaFileScannerContext, scanner, AnalysisError.Kind.CHECK_ERROR));
if (semanticModel != null) {
classesNotFound.addAll(semanticModel.classesNotFound());
}
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class ExportsDirectiveTreeImplTest method exportsDirective.
private ExportsDirectiveTree exportsDirective(String exportsDirective) {
CompilationUnitTree compilationUnitTree = createTree("module org.foo {\n " + exportsDirective + "\n}");
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return (ExportsDirectiveTree) compilationUnitTree.moduleDeclaration().moduleDirectives().get(0);
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class ExportsDirectiveTreeImplTest 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 ProvidesDirectiveTreeImplTest method providesDirective.
private ProvidesDirectiveTree providesDirective(String exportsDirective) {
CompilationUnitTree compilationUnitTree = createTree("module org.foo {\n " + exportsDirective + "\n}");
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return (ProvidesDirectiveTree) compilationUnitTree.moduleDeclaration().moduleDirectives().get(0);
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class UsesDirectiveTreeImplTest method test_BaseTreeVisitor.
@Test
public void test_BaseTreeVisitor() {
CompilationUnitTree cut = createTree("open module com.greetings {", " uses org.bar.MyInterface;", " uses org.gul.MyOtherInterface;", "}");
UsesDirectiveVisitor moduleDeclarationVisitor = new UsesDirectiveVisitor();
cut.accept(moduleDeclarationVisitor);
assertThat(moduleDeclarationVisitor.visited).isTrue();
assertThat(moduleDeclarationVisitor.directives).hasSize(2);
assertThat(moduleDeclarationVisitor.identifiers).containsExactly("com", "greetings", "MyInterface", "MyOtherInterface");
}
Aggregations