}
protected void enhanceStaticInitializers()
{
InstructionList il = null;
InstructionFactory factory = new InstructionFactory(newClass);
Method clinit = null;
InstructionList ilOriginal = null;
MethodGen methodGen = null;
MethodGen methodGenOriginal = null;
{
Method methods[] = newClass.getMethods();
for (int i = 0; i < methods.length; i++)
{
if (methods[i].getName().equals(Constants.STATIC_INITIALIZER_NAME))
{
clinit = methods[i];
methodGenOriginal = new MethodGen(clinit, className, constantPoolGen);
ilOriginal = methodGenOriginal.getInstructionList();
break;
}
}
}
il = new InstructionList();
methodGen = new MethodGen(Constants.ACC_STATIC, Type.VOID, Type.NO_ARGS, null, Constants.STATIC_INITIALIZER_NAME,
className, il, constantPoolGen);
if (ilOriginal != null)
{
// remove return instruction and add to top of static initialization block
il.append(ilOriginal);
InstructionHandle h[] = il.getInstructionHandles();
if ("return".equalsIgnoreCase(h[h.length - 1].getInstruction().getName()))
{
try
{
il.delete(h[h.length - 1]);
}
catch (TargetLostException e)
{
InstructionHandle[] targets = e.getTargets();
for (int i2 = 0; i2 < targets.length; i2++)
{
InstructionTargeter[] targeters = targets[i2].getTargeters();
for (int j = 0; j < targeters.length; j++)
{
targeters[j].updateTarget(targets[i2], h[j]);
}
}
}
}
}
if (addSerialVersionUID != 0)
{
int svUidIndex = constantPoolGen.addLong(addSerialVersionUID);
il.append(new LDC2_W(svUidIndex));
il.append(factory.createPutStatic(className, FN_serialVersionUID, Type.LONG));
}
// field init MN_jdoFieldNamesInit
il.append(factory.createInvoke(className, MN_FieldNamesInitMethod, new ArrayType(Type.STRING, 1), Type.NO_ARGS,
Constants.INVOKESTATIC));
il.append(factory.createPutStatic(className, FN_FieldNames, new ArrayType(Type.STRING, 1)));
// field init MN_jdoFieldTypesInit
il.append(factory.createInvoke(className, MN_FieldTypesInitMethod, new ArrayType(OT_CLASS, 1), Type.NO_ARGS, Constants.INVOKESTATIC));
il.append(factory.createPutStatic(className, FN_FieldTypes, new ArrayType(OT_CLASS, 1)));
// field init MN_FieldFlagsInitMethod
il.append(factory.createInvoke(className, MN_FieldFlagsInitMethod, new ArrayType(Type.BYTE, 1), Type.NO_ARGS,
Constants.INVOKESTATIC));
il.append(factory.createPutStatic(className, FN_FieldFlags, new ArrayType(Type.BYTE, 1)));
// field init MN_JdoFieldCounInitMethod
il.append(factory.createInvoke(className, MN_JdoGetInheritedFieldCount, Type.INT, Type.NO_ARGS, Constants.INVOKESTATIC));
il.append(factory.createPutStatic(className, FN_JdoInheritedFieldCount, Type.INT));
// ___jdo$PersistenceCapableSuperclass =
// ___jdo$PersistenceCapableSuperclassInit();
il.append(factory.createInvoke(className, MN_JdoPersistenceCapableSuperclassInit, OT_CLASS, Type.NO_ARGS, Constants.INVOKESTATIC));
il.append(factory.createPutStatic(className, FN_PersistenceCapableSuperclass, OT_CLASS));
// class init
/*
* JDOImplHelper.registerClass( ___jdo$loadClass("fullclassname"),
* ___jdo$fieldNames, ___jdo$fieldTypes, ___jdo$FieldFlags,
* ___jdo$PersistenceCapableSuperclass, new ClassConstrutor());
*/
il.append(new LDC(constantPoolGen.addString(className)));
il.append(factory.createInvoke(className, MN_jdoLoadClass, OT_CLASS, new Type[]{Type.STRING}, Constants.INVOKESTATIC));
il.append(factory.createGetStatic(className, FN_FieldNames, new ArrayType(Type.STRING, 1)));
il.append(factory.createGetStatic(className, FN_FieldTypes, new ArrayType(OT_CLASS, 1)));
il.append(factory.createGetStatic(className, FN_FieldFlags, new ArrayType(Type.BYTE, 1)));
il.append(factory.createGetStatic(className, FN_PersistenceCapableSuperclass, OT_CLASS));
if (((BCELClassMetaData) cmd).getClassGen().isAbstract())
{
// null
il.append(InstructionConstants.ACONST_NULL);
}
else
{
// new ClassConstrutor()
il.append(factory.createNew(new ObjectType(className)));
il.append(InstructionConstants.DUP);
il.append(factory.createInvoke(className, Constants.CONSTRUCTOR_NAME, Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
}
il.append(factory.createInvoke(CN_JDOImplHelper, "registerClass", Type.VOID, new Type[]{OT_CLASS, new ArrayType(Type.STRING, 1),
new ArrayType(OT_CLASS, 1), new ArrayType(Type.BYTE, 1), OT_CLASS, OT_PersistenceCapable}, Constants.INVOKESTATIC));
staticInitializerAppend(factory, il);
il.append(InstructionConstants.RETURN);