final String keyClassName = analyzer.getKeyClassName();
if (keyClassName == null){
// end of method body
insn = insn.append(Insn.create(opc_return));
final CodeAttribute codeAttr
= new CodeAttribute(getCodeAttributeUtf8(),
0, // maxStack
2, // maxLocals
begin,
new ExceptionTable(),
new AttributeVector());
augmenter.addMethod(methodName, methodSig, accessFlags,
codeAttr, exceptAttr);
return;
}
affirm(keyClassName != null);
// check oid argument
final ConstClass keyConstClass = pool.addClass(keyClassName);
affirm(keyConstClass != null);
insn = appendCheckVarInstanceOf(insn, 1, keyConstClass,
JAVA_IllegalArgumentException_Path,
"arg1");
// downcast argument
insn = insn.append(Insn.create(opc_aload_1));
insn = insn.append(Insn.create(opc_checkcast, keyConstClass));
insn = insn.append(Insn.create(opc_astore_2));
// check argument or delegate to superclass
final boolean isPCRoot = analyzer.isAugmentableAsRoot();
if (!isPCRoot) {
// call super.jdoCopyKeyFieldsToObjectId(oid)
//^olsen: javac uses the truelly declaring class
//final ConstClass superConstClass = classFile.superName();
//affirm(superConstClass != null);
//final String superClassName = superConstClass.asString();
//affirm(superClassName != null);
final String superClassName
= analyzer.getPCSuperKeyOwnerClassName();
affirm(superClassName != null);
insn = insn.append(Insn.create(opc_aload_0));
insn = insn.append(Insn.create(opc_aload_2));
insn = insn.append(
Insn.create(opc_invokespecial,
pool.addMethodRef(
superClassName,
methodName,
methodSig)));
}
// get types of and field references of the key fields
final int keyFieldCount = analyzer.getKeyFieldCount();
final ConstFieldRef[] keyFieldRefs = getKeyFieldRefs();
final ConstFieldRef[] keyClassKeyFieldRefs = getKeyClassKeyFieldRefs();
affirm(keyFieldRefs.length == keyFieldCount);
affirm(keyClassKeyFieldRefs.length == keyFieldCount);
// generate the assignment statements
int maxFieldSize = 0;
for (int i = 0; i < keyFieldCount; i++) {
// assign key field
final ConstFieldRef thisClassKeyRef = keyFieldRefs[i];
final ConstFieldRef keyClassKeyRef = keyClassKeyFieldRefs[i];
affirm(thisClassKeyRef != null);
affirm(keyClassKeyRef != null);
if (isToOid) {
insn = insn.append(Insn.create(opc_aload_2));
insn = insn.append(Insn.create(opc_aload_0));
insn = insn.append(Insn.create(opc_getfield, thisClassKeyRef));
insn = insn.append(Insn.create(opc_putfield, keyClassKeyRef));
} else {
insn = insn.append(Insn.create(opc_aload_0));
insn = insn.append(Insn.create(opc_aload_2));
insn = insn.append(Insn.create(opc_getfield, keyClassKeyRef));
insn = insn.append(Insn.create(opc_putfield, thisClassKeyRef));
}
// compute stack demand
final String sig
= thisClassKeyRef.nameAndType().signature().asString();
affirm(sig != null && sig.length() > 0);
maxFieldSize = max(maxFieldSize, Descriptor.countFieldWords(sig));
}
// end of method body
insn = insn.append(Insn.create(opc_return));
final CodeAttribute codeAttr
= new CodeAttribute(getCodeAttributeUtf8(),
max(maxFieldSize + 1, 3), // maxStack
3, // maxLocals
begin,
new ExceptionTable(),
new AttributeVector());