use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class OpensDirectiveTreeImplTest method moduleDirective.
private OpensDirectiveTree moduleDirective(String exportsDirective) {
CompilationUnitTree compilationUnitTree = createTree("module org.foo {\n " + exportsDirective + "\n}");
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return (OpensDirectiveTree) compilationUnitTree.moduleDeclaration().moduleDirectives().get(0);
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class MethodInvocationTreeImplTest method createTree.
private CompilationUnitTree createTree(String code) {
CompilationUnitTree compilationUnitTree = (CompilationUnitTree) p.parse(code);
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return compilationUnitTree;
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method athrow_should_not_be_linked_to_next_label.
@Test
public void athrow_should_not_be_linked_to_next_label() throws Exception {
CompilationUnitTree tree = (CompilationUnitTree) JavaParser.createParser().parse("class A {int field;}");
SquidClassLoader classLoader = new SquidClassLoader(Collections.singletonList(new File("src/test/JsrRet")));
SemanticModel semanticModel = SemanticModel.createFor(tree, classLoader);
BehaviorCache behaviorCache = new BehaviorCache(classLoader);
behaviorCache.setFileContext(null, semanticModel);
BytecodeEGWalker walker = new BytecodeEGWalker(behaviorCache, semanticModel);
MethodBehavior methodBehavior = walker.getMethodBehavior("org.apache.commons.io.FileUtils#readFileToString(Ljava/io/File;)Ljava/lang/String;", classLoader);
assertThat(methodBehavior.happyPathYields().collect(Collectors.toList())).hasSize(1);
assertThat(methodBehavior.exceptionalPathYields().collect(Collectors.toList())).hasSize(2);
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class LiveVariablesTest method buildCFG.
private static CFG buildCFG(String methodCode) {
CompilationUnitTree cut = (CompilationUnitTree) PARSER.parse("class A { int field1; int field2; static int staticField; " + methodCode + " }");
SemanticModel.createFor(cut, new SquidClassLoader(Collections.emptyList()));
MethodTree tree = ((MethodTree) ((ClassTree) cut.types().get(0)).members().get(3));
return CFG.build(tree);
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class ClassLoaderBuilder method create.
public static SquidClassLoader create(Collection<File> bytecodeFilesOrDirectories) {
List<File> files = Lists.newArrayList();
for (File file : bytecodeFilesOrDirectories) {
if (file.isFile() && file.getPath().endsWith(".class")) {
LOG.info("SonarQube Squid ClassLoader was expecting a JAR file instead of CLASS file : '" + file.getAbsolutePath() + "'");
} else {
files.add(file);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("----- Classpath analyzed by Squid:");
for (File file : files) {
LOG.debug(file.getAbsolutePath());
}
LOG.debug("-----");
}
try {
return new SquidClassLoader(files);
} catch (Exception e) {
throw new IllegalStateException("Can not create ClassLoader", e);
}
}
Aggregations