use of org.evosuite.runtime.instrumentation.JSRInlinerClassVisitor in project evosuite by EvoSuite.
the class CarvingClassLoader method instrumentClass.
private Class<?> instrumentClass(String fullyQualifiedTargetClass) throws ClassNotFoundException {
logger.warn("Instrumenting class '" + fullyQualifiedTargetClass + "'.");
try {
String className = fullyQualifiedTargetClass.replace('.', '/');
InputStream is = ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getClassAsStream(className);
if (is == null) {
throw new ClassNotFoundException("Class '" + className + ".class" + "' should be in target project, but could not be found!");
}
ClassReader reader = new ClassReader(is);
ClassNode classNode = new ClassNode();
reader.accept(classNode, ClassReader.SKIP_FRAMES);
instrumenter.transformClassNode(classNode, className);
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
classNode.accept(new JSRInlinerClassVisitor(writer));
// classNode.accept(writer);
byte[] byteBuffer = writer.toByteArray();
Class<?> result = defineClass(fullyQualifiedTargetClass, byteBuffer, 0, byteBuffer.length);
if (Modifier.isPrivate(result.getModifiers())) {
logger.info("REPLACING PRIVATE CLASS " + fullyQualifiedTargetClass);
result = super.loadClass(fullyQualifiedTargetClass);
}
classes.put(fullyQualifiedTargetClass, result);
logger.info("Keeping class: " + fullyQualifiedTargetClass);
return result;
} catch (Throwable t) {
logger.info("Error: " + t);
for (StackTraceElement e : t.getStackTrace()) {
logger.info(e.toString());
}
throw new ClassNotFoundException(t.getMessage(), t);
}
}
Aggregations