use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class TypeSubstitutionSolverTest method setUp.
@Before
public void setUp() {
parametrizedTypeCache = new ParametrizedTypeCache();
symbols = new Symbols(new BytecodeCompleter(new SquidClassLoader(Collections.emptyList()), parametrizedTypeCache));
typeSubstitutionSolver = new TypeSubstitutionSolver(parametrizedTypeCache, symbols);
T = getTypeVariable("T");
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class JavaPropertiesHelperTest method firstExpression.
private ExpressionTree firstExpression(String code) {
CompilationUnitTree compilationUnitTree = (CompilationUnitTree) p.parse("class A { " + code + "}");
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
ClassTree firstType = (ClassTree) compilationUnitTree.types().get(0);
StatementTree firstStatement = ((MethodTree) firstType.members().get(0)).block().body().get(0);
return ((ExpressionStatementTree) firstStatement).expression();
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class BytecodeCFGBuilderTest method getCFGForMethod.
private BytecodeCFG getCFGForMethod(String methodName) {
SquidClassLoader squidClassLoader = new SquidClassLoader(Lists.newArrayList(new File("target/test-classes"), new File("target/classes")));
File file = new File("src/test/java/org/sonar/java/bytecode/cfg/BytecodeCFGBuilderTest.java");
CompilationUnitTree tree = (CompilationUnitTree) JavaParser.createParser().parse(file);
SemanticModel.createFor(tree, squidClassLoader);
Symbol.TypeSymbol innerClass = ((Symbol.TypeSymbol) ((ClassTree) tree.types().get(0)).symbol().lookupSymbols("InnerClass").iterator().next());
Symbol.MethodSymbol symbol = (Symbol.MethodSymbol) innerClass.lookupSymbols(methodName).iterator().next();
return SETestUtils.bytecodeCFG(((JavaSymbol.MethodJavaSymbol) symbol).completeSignature(), squidClassLoader);
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class BytecodeCFGBuilderTest method test_class_not_found_logs.
@Test
public void test_class_not_found_logs() throws Exception {
SquidClassLoader squidClassLoader = new SquidClassLoader(Lists.newArrayList(new File("target/test-classes"), new File("target/classes")));
BytecodeCFG cfg = SETestUtils.bytecodeCFG("nonsense#foo", squidClassLoader);
assertThat(cfg).isNull();
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains(".class not found for nonsense");
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class BytecodeCFGBuilderTest method test_all_instructions_are_part_of_CFG.
@Test
public void test_all_instructions_are_part_of_CFG() throws Exception {
SquidClassLoader squidClassLoader = new SquidClassLoader(Lists.newArrayList(new File("target/test-classes"), new File("target/classes")));
File file = new File("src/test/java/org/sonar/java/bytecode/cfg/testdata/CFGTestData.java");
CompilationUnitTree tree = (CompilationUnitTree) JavaParser.createParser().parse(file);
SemanticModel.createFor(tree, squidClassLoader);
Symbol.TypeSymbol testClazz = ((ClassTree) tree.types().get(0)).symbol();
ClassReader cr = new ClassReader(squidClassLoader.getResourceAsStream(Convert.bytecodeName(CFGTestData.class.getCanonicalName()) + ".class"));
ClassNode classNode = new ClassNode(Opcodes.ASM5);
cr.accept(classNode, 0);
for (MethodNode method : classNode.methods) {
Multiset<String> opcodes = Arrays.stream(method.instructions.toArray()).map(AbstractInsnNode::getOpcode).filter(opcode -> opcode != -1).map(opcode -> Printer.OPCODES[opcode]).collect(Collectors.toCollection(HashMultiset::create));
Symbol methodSymbol = Iterables.getOnlyElement(testClazz.lookupSymbols(method.name));
BytecodeCFG bytecodeCFG = SETestUtils.bytecodeCFG(((JavaSymbol.MethodJavaSymbol) methodSymbol).completeSignature(), squidClassLoader);
Multiset<String> cfgOpcodes = cfgOpcodes(bytecodeCFG);
assertThat(cfgOpcodes).isEqualTo(opcodes);
}
}
Aggregations