MethodDelta md = new MethodDelta(oMethod.name, oMethod.desc);
if (oMethod.access != nMethod.access) {
md.setAccessChanged(oMethod.access, nMethod.access);
}
// TODO annotations
InsnList oInstructions = oMethod.instructions;
InsnList nInstructions = nMethod.instructions;
if (oInstructions.size() != nInstructions.size()) {
md.setInstructionsChanged(oInstructions.toArray(), nInstructions.toArray());
} else {
// TODO Just interested in constructors right now - should add others
if (oMethod.name.charAt(0) == '<') {
String oInvokeSpecialDescriptor = null;
String nInvokeSpecialDescriptor = null;
int oUninitCount = 0;
int nUninitCount = 0;
boolean codeChange = false;
for (int i = 0, max = oInstructions.size(); i < max; i++) {
AbstractInsnNode oInstruction = oInstructions.get(i);
AbstractInsnNode nInstruction = nInstructions.get(i);
if (!codeChange) {
if (!sameInstruction(oInstruction, nInstruction)) {
codeChange = true;
}
}
if (oInstruction.getType() == AbstractInsnNode.TYPE_INSN) {
if (oInstruction.getOpcode() == Opcodes.NEW) {
oUninitCount++;
}
}
if (nInstruction.getType() == AbstractInsnNode.TYPE_INSN) {
if (nInstruction.getOpcode() == Opcodes.NEW) {
nUninitCount++;
}
}
if (oInstruction.getType() == AbstractInsnNode.METHOD_INSN) {
MethodInsnNode mi = (MethodInsnNode) oInstruction;
if (mi.getOpcode() == INVOKESPECIAL && mi.name.equals("<init>")) {
if (oUninitCount == 0) {
// this is the one!
oInvokeSpecialDescriptor = mi.desc;
} else {
oUninitCount--;
}
}
}
if (nInstruction.getType() == AbstractInsnNode.METHOD_INSN) {
MethodInsnNode mi = (MethodInsnNode) nInstruction;
if (mi.getOpcode() == INVOKESPECIAL && mi.name.equals("<init>")) {
if (nUninitCount == 0) {
// this is the one!
nInvokeSpecialDescriptor = mi.desc;
} else {
nUninitCount--;
}
}
}
}
// Has the invokespecial changed?
if (oInvokeSpecialDescriptor == null) {
if (nInvokeSpecialDescriptor != null) {
md.setInvokespecialChanged(oInvokeSpecialDescriptor, nInvokeSpecialDescriptor);
}
} else {
if (!oInvokeSpecialDescriptor.equals(nInvokeSpecialDescriptor)) {
md.setInvokespecialChanged(oInvokeSpecialDescriptor, nInvokeSpecialDescriptor);
}
}
if (codeChange) {
md.setCodeChanged(oInstructions.toArray(), nInstructions.toArray());
}
}
}
if (md.hasAnyChanges()) {
// it needs recording