String deferredInstanceFromFunctionClass = project.getDeferredInstanceFromFunctionClass();
Name deferredInstanceFromFunctionName = project.getDeferredInstanceFromFunctionName();
if (!(classDefinition.isInstanceOf("mx.core.IStateClient2", project)))
{
final IResolvedQualifiersReference stateClient2Reference = ReferenceFactory.packageQualifiedReference(
this.getProject().getWorkspace(),
"mx.core.IStateClient2");
final Name stateClient2Name = stateClient2Reference.getMName();
IReference[] implementedInterfaces = classDefinition.getImplementedInterfaceReferences();
IReference[] newInterfaces = null;
Name[] newNames = null;
if (implementedInterfaces != null)
{
int n = implementedInterfaces.length;
newInterfaces = new IReference[n + 1];
newNames = new Name[n + 1];
for (int i = 0; i < n; i++)
{
newInterfaces[i] = implementedInterfaces[i];
newNames[i] = iinfo.interfaceNames[i];
}
newInterfaces[n] = ReferenceFactory.packageQualifiedReference(project.getWorkspace(), "mx.core.IStateClient2");
newNames[n] = stateClient2Name;
}
else
{
newInterfaces = new IReference[1];
newInterfaces[0] = ReferenceFactory.packageQualifiedReference(project.getWorkspace(), "mx.core.IStateClient2");
newNames = new Name[1];
newNames[0] = stateClient2Name;
}
classDefinition.setImplementedInterfaceReferences(newInterfaces);
iinfo.interfaceNames = newNames;
}
// now, process all the state dependent nodes
int instanceNodeCounter = 0;
IASNode anInstanceNode = null;
for (IMXMLNode node : stateDependentNodes)
{
// here we only care about instance nodes
if (node instanceof IMXMLInstanceNode)
{
anInstanceNode = node;
// Generate a map that tell for each state dependent instance node, what slot
// it corresponds to in the array of
// deferredInstanceFromFunction's
if (nodeToIndexMap==null)
nodeToIndexMap = new HashMap<IMXMLNode, Integer>();
nodeToIndexMap.put(node, instanceNodeCounter);
++instanceNodeCounter;
InstructionList il;
if (getProject().getTargetSettings().getMxmlChildrenAsData())
{
if (nodeToInstanceDescriptorMap==null)
nodeToInstanceDescriptorMap = new HashMap<IMXMLNode, InstructionList>();
il = new InstructionList();
nodeToInstanceDescriptorMap.put(node, il);
// build the initializer function by processing the node
Context stateContext = new Context((IMXMLInstanceNode)node, il);
stateContext.isContentFactory = true;
processNode(node, stateContext);
stateContext.transfer(IL.MXML_CONTENT_FACTORY);
stateContext.addInstruction(OP_newarray, stateContext.getCounter(IL.MXML_CONTENT_FACTORY));
}
else
{
context.addInstruction(OP_findpropstrict, deferredInstanceFromFunctionName);
// stack: ..., DeferredInstaceFromFunction class
// build the initializer function by processing the node
processNode(node, context);
// stack: ..., DeferredInstaceFromFunction class, initializerFunc
context.addInstruction(OP_constructprop, new Object[] { deferredInstanceFromFunctionName, 1});
// stack: ..., DeferredInstaceFromFunction object
}
}
}
if (getProject().getTargetSettings().getMxmlChildrenAsData())
return;
// if we didn't find any state dependent instance nodes, then leave
if (instanceNodeCounter==0)
return;
// stack: ..., arg[0], arg[1],.., arg[n-1]
context.addInstruction(OP_newarray, instanceNodeCounter);
context.addInstruction(OP_setlocal3);
// now local3= array of deferredInstanceFromFunctionName
// make a dependency on the sdk class DeferredInstanceFromFunction
IWorkspace workspace = project.getWorkspace();
IResolvedQualifiersReference ref = ReferenceFactory.packageQualifiedReference(workspace, deferredInstanceFromFunctionClass);
IScopedNode scopedNode = anInstanceNode.getContainingScope();
IASScope iscope = scopedNode.getScope();
ASScope scope = (ASScope)iscope;
if (ref == null)
assert false;
IDefinition def = ref.resolve(project, scope, DependencyType.EXPRESSION, false);
if (def == null)
assert false;
}