if (LazyMethodGen.isConstructor(aMethod)) {
InstructionList insList = aMethod.getBody();
InstructionHandle handle = insList.getStart();
while (handle != null) {
if (handle.getInstruction().opcode == Constants.INVOKESPECIAL) {
ConstantPool cpg = newParentTarget.getConstantPool();
InvokeInstruction invokeSpecial = (InvokeInstruction) handle.getInstruction();
if (invokeSpecial.getClassName(cpg).equals(currentParent)
&& invokeSpecial.getMethodName(cpg).equals("<init>")) {
// System.err.println("Transforming super call '<init>" + invokeSpecial.getSignature(cpg) + "'");
// 1. Check there is a ctor in the new parent with
// the same signature
ResolvedMember newCtor = getConstructorWithSignature(newParent, invokeSpecial.getSignature(cpg));
if (newCtor == null) {
// 2. Check ITDCs to see if the necessary ctor is provided that way
boolean satisfiedByITDC = false;
for (Iterator<ConcreteTypeMunger> ii = newParentTarget.getType()
.getInterTypeMungersIncludingSupers().iterator(); ii.hasNext() && !satisfiedByITDC;) {
ConcreteTypeMunger m = ii.next();
if (m.getMunger() instanceof NewConstructorTypeMunger) {
if (m.getSignature().getSignature().equals(invokeSpecial.getSignature(cpg))) {
satisfiedByITDC = true;
}
}
}
if (!satisfiedByITDC) {
String csig = createReadableCtorSig(newParent, cpg, invokeSpecial);
weaver.getWorld()
.getMessageHandler()
.handleMessage(
MessageUtil.error(
"Unable to modify hierarchy for " + newParentTarget.getClassName()
+ " - the constructor " + csig + " is missing",
this.getSourceLocation()));
return false;
}
}
int idx = cpg.addMethodref(newParent.getName(), invokeSpecial.getMethodName(cpg),
invokeSpecial.getSignature(cpg));
invokeSpecial.setIndex(idx);
}
}
handle = handle.getNext();