private void openStackFrame(IStackFrame sf) {
ClassIndex ci = SystemFacade.getInstance().getClassIndex();
ClassLocator cl = ci.getLocator(sf.location().declaringType().name());
if (cl != null) {
try {
ClassFile cf = SystemFacade.getInstance().getClassFile(cl);
IMethod bpMethod = sf.location().method();
for (net.sf.rej.java.Method method : cf.getMethods()) {
if (method.getName().equals(bpMethod.name()) && method.getDescriptor().getRawDesc().equals(bpMethod.signature())) {
Integer pc = null;
if (sf.location().codeIndex() != -1) {
pc = (int)sf.location().codeIndex();
}
Event event = new Event(EventType.CLASS_OPEN);
event.setClassFile(cf);
event.setFile(cl.getFile());
this.dispatcher.notifyObservers(event);
setExecutionRow(method.getName(), method.getDescriptor(), pc);
break;
}
}
} catch(Exception ioe) {
ioe.printStackTrace();
}
} else {
ClassFactory factory = new ClassFactory();
IReferenceType rt = sf.location().declaringType();
String superClass = null;
if (!"java.lang.Object".equals(rt.name())) {
superClass = rt.getSuperClassName();
}
ClassFile cf = factory.createClass(rt.name(), superClass);
ConstantPool cp = cf.getPool();
FieldFactory fieldFactory = new FieldFactory();
for (IField field : rt.visibleFields()) {
AccessFlags flags = new AccessFlags(field.modifiers());
Field fieldToAdd = fieldFactory.createField(cf, flags, cp.optionalAddUtf8(field.name()), cp.optionalAddUtf8(field.signature()));
cf.add(fieldToAdd);
}
MethodFactory methodFactory = new MethodFactory();
for (IMethod method : rt.visibleMethods()) {
AccessFlags flags = new AccessFlags(method.modifiers());
net.sf.rej.java.Method methodToAdd = methodFactory.createMethod(cf, flags, cp.optionalAddUtf8(method.name()), cp.optionalAddUtf8(method.signature()), cp.optionalAddUtf8("Code"), 0, 0, cp.optionalAddUtf8("Exceptions"), new ArrayList<ExceptionDescriptor>());
cf.add(methodToAdd);
}
SystemFacade.getInstance().setStatus("Class definition pulled from VM: " + sf.location().declaringType().name());
Event event = new Event(EventType.CLASS_OPEN);
event.setClassFile(cf);