{
String initializer = _idAllocator.allocateId("initializer");
try
{
CtConstructor defaultConstructor = _ctClass.getConstructor("()V");
CtMethod initializerMethod = defaultConstructor.toMethod(initializer, _ctClass);
_ctClass.addMethod(initializerMethod);
}
catch (Exception ex)
{
throw new RuntimeException(ex);
}
_formatter.format("convert default constructor: %s();\n\n", initializer);
int count = _constructorArgs.size();
CtClass[] types = new CtClass[count];
for (int i = 0; i < count; i++)
{
ConstructorArg arg = _constructorArgs.get(i);
types[i] = arg.getType();
}
// Add a call to the initializer; the method converted fromt the classes default
// constructor.
_constructor.append(" ");
_constructor.append(initializer);
// This finally matches the "{" added inside the constructor
_constructor.append("();\n\n}");
String constructorBody = _constructor.toString();
try
{
CtConstructor cons = CtNewConstructor.make(types, null, constructorBody, _ctClass);
_ctClass.addConstructor(cons);
}
catch (CannotCompileException ex)
{
throw new RuntimeException(ex);