private void modifyClassConstructor(ClassFile cf, Bytecode code,
int stacksize, int localsize)
throws CannotCompileException
{
MethodInfo m = cf.getStaticInitializer();
if (m == null) {
code.add(Bytecode.RETURN);
code.setMaxStack(stacksize);
code.setMaxLocals(localsize);
m = new MethodInfo(cf.getConstPool(), "<clinit>", "()V");
m.setAccessFlags(AccessFlag.STATIC);
m.setCodeAttribute(code.toCodeAttribute());
cf.addMethod(m);
CtMember.Cache cache = hasMemberCache();
if (cache != null)
cache.addConstructor(new CtConstructor(m, this));
}
else {
CodeAttribute codeAttr = m.getCodeAttribute();
if (codeAttr == null)
throw new CannotCompileException("empty <clinit>");
try {
CodeIterator it = codeAttr.iterator();
int pos = it.insertEx(code.get());
it.insert(code.getExceptionTable(), pos);
int maxstack = codeAttr.getMaxStack();
if (maxstack < stacksize)
codeAttr.setMaxStack(stacksize);
int maxlocals = codeAttr.getMaxLocals();
if (maxlocals < localsize)
codeAttr.setMaxLocals(localsize);
}
catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}
try {
m.rebuildStackMapIf6(classPool, cf);
}
catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}