use of org.objectweb.asm.tree.ClassNode in project evosuite by EvoSuite.
the class CallGraphGenerator method analyze.
public static CallGraph analyze(String className) {
ClassNode targetClass = DependencyAnalysis.getClassNode(className);
CallGraph callgraph = new CallGraph(className);
if (targetClass != null)
handle(callgraph, targetClass, 0);
if (Properties.INSTRUMENT_PARENT) {
handleSuperClasses(callgraph, targetClass);
}
return callgraph;
}
use of org.objectweb.asm.tree.ClassNode 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);
}
}
use of org.objectweb.asm.tree.ClassNode in project evosuite by EvoSuite.
the class ProjectGraph method isAbstract.
/**
* Is the given class name representing an abstract class in the SUT?
* @param className
* @return
* @throws IllegalArgumentException
*/
public boolean isAbstract(String className) throws IllegalArgumentException {
checkClass(className);
ClassNode node = getClassNode(className);
return (node.access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT;
}
use of org.objectweb.asm.tree.ClassNode in project evosuite by EvoSuite.
the class ProjectGraph method isInterface.
/**
* Is the given class name representing an interface in the SUT?
* @param className
* @return
* @throws IllegalArgumentException
*/
public boolean isInterface(String className) throws IllegalArgumentException {
checkClass(className);
ClassNode node = getClassNode(className);
if ((node.access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE)
return true;
return false;
}
use of org.objectweb.asm.tree.ClassNode in project evosuite by EvoSuite.
the class DetermineSUT method determineCalledClasses.
public Set<String> determineCalledClasses(String fullyQualifiedTargetClass, Set<String> targetClasses) throws ClassNotFoundException, NoJUnitClassException {
Set<String> calledClasses = new HashSet<String>();
String className = fullyQualifiedTargetClass.replace('.', '/');
try {
InputStream is = ClassLoader.getSystemResourceAsStream(className + ".class");
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);
superClasses = getSuperClasses(classNode);
if (isJUnitTest(classNode)) {
handleClassNode(calledClasses, classNode, targetClasses);
} else {
throw new NoJUnitClassException();
}
} catch (IOException e) {
e.printStackTrace();
}
calledClasses.remove("java.lang.Object");
calledClasses.remove(fullyQualifiedTargetClass);
return calledClasses;
}
Aggregations