ClassAnnotationDefRow adr = new ClassAnnotationDefRow(annotation);
this.rows.add(adr);
}
// Class
this.classDef = new ClassDefRow(cf, true);
this.rows.add(this.classDef);
this.rows.add(new BlankRow());
// Fields
java.util.List fields = cf.getFields();
for (int i = 0; i < fields.size(); i++) {
Field field = (Field) fields.get(i);
// Field annotations
RuntimeInvisibleAnnotationsAttribute fieldAnnInvisible = field
.getAttributes().getRuntimeInvisibleAnnotationsAttribute();
RuntimeVisibleAnnotationsAttribute fieldAnnVisible = field
.getAttributes().getRuntimeVisibleAnnotationsAttribute();
List<Annotation> fieldAnnotations = new ArrayList<Annotation>();
if (fieldAnnInvisible != null) {
fieldAnnotations.addAll(fieldAnnInvisible.getAnnotations());
}
if (fieldAnnVisible != null) {
fieldAnnotations.addAll(fieldAnnVisible.getAnnotations());
}
for (Annotation annotation : fieldAnnotations) {
FieldAnnotationDefRow fadr = new FieldAnnotationDefRow(
annotation);
this.rows.add(fadr);
}
FieldDefRow fdr = new FieldDefRow(cf, field);
this.rows.add(fdr);
this.classDef.addField(fdr);
}
if (fields.size() > 0) {
this.rows.add(new BlankRow());
}
// Methods
java.util.List methods = cf.getMethods();
for (int i = 0; i < methods.size(); i++) {
Method method = (Method) methods.get(i);
// Method annotations
boolean deprecatedAnnotationAdded = false;
RuntimeInvisibleAnnotationsAttribute methodAnnInvisible = method
.getAttributes().getRuntimeInvisibleAnnotationsAttribute();
RuntimeVisibleAnnotationsAttribute methodAnnVisible = method
.getAttributes().getRuntimeVisibleAnnotationsAttribute();
List<Annotation> methodAnnotations = new ArrayList<Annotation>();
if (methodAnnInvisible != null) {
methodAnnotations.addAll(methodAnnInvisible.getAnnotations());
}
if (methodAnnVisible != null) {
methodAnnotations.addAll(methodAnnVisible.getAnnotations());
}
for (Annotation annotation : methodAnnotations) {
MethodAnnotationDefRow madr = new MethodAnnotationDefRow(
annotation);
this.rows.add(madr);
if ("java.lang.Deprecated".equals(annotation.getName())) {
deprecatedAnnotationAdded = true;
// store this information so that
// the Deprecated attribute isn't used to
// create another deprecation EditorRow
}
}
Attributes attr = method.getAttributes();
CodeAttribute codeAttr = attr.getCode();
MethodDefRow mdr = new MethodDefRow(cf, method, true,
codeAttr != null);
if (!deprecatedAnnotationAdded && method.isDeprecated()) {
DeprecatedAnnotationDefRow ddr = new DeprecatedAnnotationDefRow();
this.rows.add(ddr);
}
this.rows.add(mdr);
this.classDef.addMethod(mdr);
LineNumberTableAttribute lnAttr = null;
LocalVariableTableAttribute lvs = null;
if (codeAttr != null) {
if (codeAttr.getAttributes() != null) {
lnAttr = codeAttr.getAttributes().getLineNumberTable();
lvs = codeAttr.getAttributes().getLocalVariableTable();
}
Code code = codeAttr.getCode();
DecompilationContext dc = code.createDecompilationContext();
dc.setPosition(0);
for (Instruction instruction : code.getInstructions()) {
if (instruction instanceof Label) {
LabelRow lr = new LabelRow((Label) instruction, mdr);
lr.setParentCode(code);
this.rows.add(lr);
mdr.addCodeRow(lr);
} else {
int lineNumber = -1;
if (lnAttr != null) {
lineNumber = lnAttr.getLineNumber(dc.getPosition());
}
if (lvs != null) {
List locals = lvs
.getLocalVariable(dc.getPosition());
for (int k = 0; k < locals.size(); k++) {
LocalVariable lv = (LocalVariable) locals
.get(k);
LocalVariableDefRow lvdr = new LocalVariableDefRow(
lv, mdr);
this.rows.add(lvdr);
mdr.addLocalVariable(lvdr);
}
}
CodeRow cd = new CodeRow(cf, mdr, instruction);
cd.setPosition(dc.getPosition());
cd.setDecompilationContext(dc);
cd.setParentCode(code);
cd.setBreakpoint(EditorFacade.getInstance()
.getBreakpoint(cf.getFullClassName(),
method.getName(),
method.getDescriptor(),
dc.getPosition()));
if (lineNumber != -1) {
cd.setLineNumber(lineNumber);
}
this.rows.add(cd);
mdr.addCodeRow(cd);
dc.incrementPosition(instruction);
}
}
this.rows.add(new MethodDefRow(cf, method, false, true));
}
this.rows.add(new BlankRow());
}
this.rows.add(new ClassDefRow(cf, false));
this.label.setText("Bytecode Editor: " + cf.getFullClassName());
this.model.clear();
for (EditorRow er : rows) {
this.model.addElement(er);