final int accessFlags = 0;
final ExceptionsAttribute exceptAttr = null;
// begin of method body
final InsnTarget begin = new InsnTarget();
Insn insn = begin;
//@olsen: disabled code
if (false) {
// reset jdoFlags = LOAD_REQUIRED
insn = insn.append(Insn.create(opc_aload_0));
insn = insn.append(Insn.create(opc_iconst_1));
insn = insn.append(
Insn.create(opc_putfield,
pool.addFieldRef(className,
JDO_PC_jdoFlags_Name,
JDO_PC_jdoFlags_Sig)));
}
// iterate over all declared fields of the class
final ClassField[] managedFields = null; //analyzer.annotatedFields();
final int managedFieldCount = managedFields.length;
for (int i = 0; i < managedFieldCount; i++) {
final ClassField field = managedFields[i];
final String fieldName = field.name().asString();
final String fieldSig = field.signature().asString();
/*
// ignore primary managed fields
if (field.isManaged())
continue;
*/
/*
//@olsen: disconnect mutable SCOs before clear
if (field.isMutableSCO()) {
// fetch field
insn = insn.append(Insn.create(opc_aload_0));
insn = insn.append(
Insn.create(opc_getfield,
pool.addFieldRef(
className,
fieldName,
fieldSig)));
// test whether instanceof SCO base type
// skip disconnecting if == 0
final ConstClass cc
= pool.addClass(JDO_SecondClassObjectBase_Path);
InsnTarget disconnect = new InsnTarget();
InsnTarget afterDisconnect = new InsnTarget();
insn = insn.append(
Insn.create(opc_dup));
insn = insn.append(
Insn.create(opc_instanceof,
cc));
insn = insn.append(
Insn.create(opc_ifne,
disconnect));
// pop field and skip disconnecting
insn = insn.append(
Insn.create(opc_pop));
insn = insn.append(
Insn.create(opc_goto, afterDisconnect));
// disconnect SCO field's object
insn = insn.append(disconnect);
// cast to SCO base type
insn = insn.append(
Insn.create(opc_checkcast,
cc));
// call method: void unsetOwner();
final int requiredStack = 1;
insn = insn.append(
new InsnInterfaceInvoke(
pool.addInterfaceMethodRef(
JDO_SecondClassObjectBase_Path,
"unsetOwner",
"()V"),
requiredStack));
insn = insn.append(afterDisconnect);
}
*/
// get this
insn = insn.append(Insn.create(opc_aload_0));
// use the getMethodReturn type to decide how to clear field
switch (fieldSig.charAt(0)) {
case 'D':
insn = insn.append(Insn.create(opc_dconst_0));
break;
case 'F':
insn = insn.append(Insn.create(opc_fconst_0));
break;
case 'J':
insn = insn.append(Insn.create(opc_lconst_0));
break;
case 'Z':
case 'C':
case 'B':
case 'S':
case 'I':
insn = insn.append(Insn.create(opc_iconst_0));
break;
case 'L':
case '[':
insn = insn.append(Insn.create(opc_aconst_null));
break;
default:
throw new InternalError("Illegal field type: " + fieldSig);
}
// put default value to field
insn = insn.append(
Insn.create(opc_putfield,
pool.addFieldRef(className,
fieldName,
fieldSig)));
}
// end of method body
insn = insn.append(Insn.create(opc_return));
final CodeAttribute codeAttr
= new CodeAttribute(getCodeAttributeUtf8(),
3, // maxStack
1, // maxLocals