List<Label> copyLabels = copy.getLabels();
for (int i = 0; i < labels.size(); i++) {
if (copyLabels.get(i) == null) {
throw new AssertionError("Copied label is null for instruction: " + inst + " : " + copyLabels);
}
Label label = labels.get(i);
int labelIndex = list.indexOf(label);
if (labelIndex != -1) {
list.set(labelIndex, copyLabels.get(i));
} else {
list.add(copyLabels.get(i));
}
}
}
codeBlock.add(0, list);
transferrable.setCode(codeBlock);
}
transferrable.setExceptions(exceptionNames);
transferables.add(transferrable);
}
} else if (obj instanceof FieldDefRow) {
FieldDefRow fdr = (FieldDefRow) obj;
Field field = fdr.getField();
// TODO: Attributes are not being copied
TransferrableField transferrable = new TransferrableField();
transferrable.setFieldName(field.getName());
transferrable.setDescriptor(field.getDescriptor());
transferrable.setAccessFlags(field.getAccessFlags());
transferables.add(transferrable);
} else if (obj instanceof CodeRow || obj instanceof LabelRow) {
code.add((EditorRow) obj);
}
}
if (!transferables.isEmpty()) {
return transferables;
} else {
List<Instruction> list = new ArrayList<Instruction>();
for (EditorRow er : code) {
if (er instanceof CodeRow) {
list.add(((CodeRow) er).getInstruction());
} else if (er instanceof LabelRow) {
list.add(((LabelRow) er).getLabel());
} else {
throw new AssertionError(
"Object of invalid class (not CodeRow and not LabelRow) in list: "
+ er.getClass());
}
}
ConstantPool newPool = new ConstantPool();
Code codeBlock = new Code(newPool);
InstructionCopier instructionCopier = new InstructionCopier();
for (EditorRow er : code) {
if (er instanceof LabelRow)
continue;
CodeRow cr = (CodeRow) er;
Instruction inst = cr.getInstruction();
Instruction copy = instructionCopier.copyInstruction(inst, cr
.getDecompilationContext().getConstantPool(), newPool);
int index = list.indexOf(inst);
list.set(index, copy);
List<Label> labels = inst.getLabels();
List<Label> copyLabels = copy.getLabels();
for (int i = 0; i < labels.size(); i++) {
Label label = labels.get(i);
int labelIndex = list.indexOf(label);
if (labelIndex != -1) {
list.set(labelIndex, copyLabels.get(i));
} else {
list.add(copyLabels.get(i));