use of org.objectweb.asm.tree.MethodNode in project evosuite by EvoSuite.
the class GetStaticGraphGenerator method handle.
@SuppressWarnings("unchecked")
private static void handle(GetStaticGraph staticUsageTree, ClassNode targetClass, int depth) {
List<MethodNode> methods = targetClass.methods;
for (MethodNode mn : methods) {
logger.debug("Method: " + mn.name);
handleMethodNode(staticUsageTree, targetClass, mn, depth);
}
}
use of org.objectweb.asm.tree.MethodNode in project evosuite by EvoSuite.
the class InheritanceTreeGenerator method analyzeClassNode.
@SuppressWarnings("unchecked")
private static void analyzeClassNode(InheritanceTree inheritanceTree, ClassNode cn, boolean onlyPublic) {
logger.info("Analyzing class {}", cn.name);
// Don't load classes already seen from a different CP entry
if (inheritanceTree.hasClass(cn.name))
return;
if ((Opcodes.ACC_INTERFACE & cn.access) != Opcodes.ACC_INTERFACE) {
for (Object m : cn.methods) {
MethodNode mn = (MethodNode) m;
inheritanceTree.addAnalyzedMethod(cn.name, mn.name, mn.desc);
}
if ((Opcodes.ACC_ABSTRACT & cn.access) == Opcodes.ACC_ABSTRACT) {
inheritanceTree.registerAbstractClass(cn.name);
}
} else {
inheritanceTree.registerInterface(cn.name);
}
if (onlyPublic) {
if ((cn.access & Opcodes.ACC_PUBLIC) == 0) {
return;
}
// } else {
// if (!canUse(cn)) {
// logger.info("Cannot use "+cn.name);
// return;
// }
}
if (cn.superName != null)
inheritanceTree.addSuperclass(cn.name, cn.superName, cn.access);
List<String> interfaces = cn.interfaces;
for (String interfaceName : interfaces) {
inheritanceTree.addInterface(cn.name, interfaceName);
}
}
use of org.objectweb.asm.tree.MethodNode in project evosuite by EvoSuite.
the class PutStaticMethodCollector method collectMethods.
@SuppressWarnings("unchecked")
public Set<MethodIdentifier> collectMethods() {
Set<MethodIdentifier> methods = new LinkedHashSet<MethodIdentifier>();
for (String calledClassName : getStaticFields.keySet()) {
ClassNode classNode = DependencyAnalysis.getClassNode(calledClassName);
List<MethodNode> classMethods = classNode.methods;
for (MethodNode mn : classMethods) {
if (mn.name.equals(CLINIT))
continue;
InsnList instructions = mn.instructions;
Iterator<AbstractInsnNode> it = instructions.iterator();
while (it.hasNext()) {
AbstractInsnNode insn = it.next();
if (insn instanceof FieldInsnNode) {
FieldInsnNode fieldInsn = (FieldInsnNode) insn;
if (fieldInsn.getOpcode() != Opcodes.PUTSTATIC) {
continue;
}
String calleeClassName = fieldInsn.owner.replaceAll("/", ".");
String calleeFieldName = fieldInsn.name;
if (contains(getStaticFields, calleeClassName, calleeFieldName)) {
MethodIdentifier methodIdentifier = new MethodIdentifier(calledClassName, mn.name, mn.desc);
methods.add(methodIdentifier);
}
}
}
}
}
return methods;
}
use of org.objectweb.asm.tree.MethodNode in project evosuite by EvoSuite.
the class CallGraphGenerator method handle.
@SuppressWarnings("unchecked")
private static void handle(CallGraph callGraph, ClassNode targetClass, int depth) {
List<MethodNode> methods = targetClass.methods;
for (MethodNode mn : methods) {
logger.debug("Method: " + mn.name);
handleMethodNode(callGraph, targetClass, mn, depth);
}
}
use of org.objectweb.asm.tree.MethodNode in project evosuite by EvoSuite.
the class DescriptorMapping method isOutsideMethod.
private boolean isOutsideMethod(String className, String methodName, String desc) {
Set<String> visited = new HashSet<String>();
Queue<String> parents = new LinkedList<String>();
parents.add(className);
while (!parents.isEmpty()) {
String name = parents.poll();
if (name == null)
continue;
visited.add(name);
logger.info("Visiting class " + name + " while looking for source of " + className + "." + methodName);
ClassReader reader;
try {
reader = new ClassReader(ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getClassAsStream(name));
ClassNode parent = new ClassNode();
reader.accept(parent, ClassReader.EXPAND_FRAMES);
boolean isInside = isInside(parent.name);
// boolean isInside = parent.name.startsWith(Properties.PROJECT_PREFIX.replace(".",
// "/"))
// || (!Properties.TARGET_CLASS_PREFIX.isEmpty() && parent.name.startsWith(Properties.TARGET_CLASS_PREFIX.replace(".",
// "/")));
logger.info("Checking " + parent.name);
for (Object o : parent.methods) {
MethodNode mn2 = (MethodNode) o;
if (mn2.name.equals(methodName) && mn2.desc.equals(desc)) {
if (!isInside) {
logger.info("Method " + name + " was defined outside the test package");
return true;
} else {
logger.info("Method " + name + " was defined outside the test package");
// return false;
}
}
}
for (Object o : parent.interfaces) {
String par = (String) o;
if (!visited.contains(par) && !parents.contains(par)) {
parents.add(par);
}
}
if (!visited.contains(parent.superName) && !parents.contains(parent.superName)) {
parents.add(parent.superName);
}
} catch (IOException e) {
logger.info("Error reading class " + name);
}
}
return false;
}
Aggregations