* application class at runtme. May not be null but a library.swf for a SWC
* may pass in a {@link Name} that resolves to "Object" at runtime.
*/
protected final void codegenCreateMethod(ClassGeneratorHelper classGen, Name mainApplicationName)
{
IResolvedQualifiersReference applyReference = ReferenceFactory.resolvedQualifierQualifiedReference(flexProject.getWorkspace(),
NamespaceDefinition.getAS3NamespaceDefinition(), "apply");
IResolvedQualifiersReference getDefinitionByNameReference =
ReferenceFactory.packageQualifiedReference(flexProject.getWorkspace(), IASLanguageConstants.getDefinitionByName);
IResolvedQualifiersReference iFlexModule =
ReferenceFactory.packageQualifiedReference(flexProject.getWorkspace(), IMXMLTypeConstants.IFlexModule);
Name getDefinitionByName = getDefinitionByNameReference.getMName();
InstructionList create = new InstructionList();
create.addInstruction(ABCConstants.OP_getlocal1);
create.addInstruction(ABCConstants.OP_getproperty, new Name("length"));
create.addInstruction(ABCConstants.OP_pushbyte, 0);
Label createL1 = new Label();
create.addInstruction(ABCConstants.OP_ifgt, createL1);
create.addInstruction(ABCConstants.OP_findproperty, mainApplicationName);
create.addInstruction(ABCConstants.OP_getproperty, mainApplicationName);
Label createL3 = new Label();
create.addInstruction(ABCConstants.OP_jump, createL3);
create.labelNext(createL1);
create.addInstruction(ABCConstants.OP_getlocal1);
create.addInstruction(ABCConstants.OP_getproperty, new Name("0"));
create.addInstruction(ABCConstants.OP_istype, new Name("String"));
Label createL2 = new Label();
create.addInstruction(ABCConstants.OP_iffalse, createL2);
create.addInstruction(ABCConstants.OP_finddef, getDefinitionByName);
create.addInstruction(ABCConstants.OP_getlocal1);
create.addInstruction(ABCConstants.OP_getproperty, new Name("0"));
create.addInstruction(ABCConstants.OP_callproperty, new Object[] {getDefinitionByName, 1});
create.addInstruction(ABCConstants.OP_jump, createL3);
create.labelNext(createL2);
create.addInstruction(ABCConstants.OP_getlocal0);
create.addInstruction(ABCConstants.OP_getsuper, new Name("create"));
create.addInstruction(ABCConstants.OP_getlocal0);
create.addInstruction(ABCConstants.OP_getlocal1);
create.addInstruction(ABCConstants.OP_callproperty, new Object[] {applyReference.getMName(), 2});
create.addInstruction(ABCConstants.OP_returnvalue);
create.labelNext(createL3);
create.addInstruction(ABCConstants.OP_astype, new Name("Class"));
create.addInstruction(ABCConstants.OP_dup);
Label createL5 = new Label();
create.addInstruction(ABCConstants.OP_iffalse, createL5);
create.addInstruction(ABCConstants.OP_construct, 0);
create.addInstruction(ABCConstants.OP_dup);
create.addInstruction(ABCConstants.OP_istype, iFlexModule.getMName());
Label createL4 = new Label();
create.addInstruction(ABCConstants.OP_iffalse, createL4);
create.addInstruction(ABCConstants.OP_dup);
create.addInstruction(ABCConstants.OP_getlocal0);
create.addInstruction(ABCConstants.OP_setproperty, new Name("moduleFactory"));