*/
void processInstanceOverride(IMXMLInstanceNode instanceNode, Context context)
{
FlexProject project = getProject();
Name instanceOverrideName = project.getInstanceOverrideClassName();
assert nodeToIndexMap != null;
if (getProject().getTargetSettings().getMxmlChildrenAsData())
{
context.addInstruction(OP_findpropstrict, instanceOverrideName);
context.addInstruction(OP_getproperty, instanceOverrideName);
}
else
{
// create the AddItems object
context.addInstruction(OP_findpropstrict, instanceOverrideName);
context.addInstruction(OP_constructprop, new Object[] {instanceOverrideName, 0});
// stack: AddItems
}
// Now set properties on it!
//----------------------------------------------------------------------
// First property: set itemsFactory to the deferredInstanceFunction we created earlier
Integer index = nodeToIndexMap.get(instanceNode);
assert index != null;
InstructionList addItemsIL = new InstructionList();
int addItemsCounter = 0;
if (getProject().getTargetSettings().getMxmlChildrenAsData())
{
addItemsIL.addInstruction(OP_pushstring, "itemsDescriptor");
addItemsIL.addInstruction(OP_pushtrue); // the value is an array of descriptor data that will be parsed later
InstructionList il = nodeToInstanceDescriptorMap.get(instanceNode);
InstructionList ilCopy = (InstructionList)il.clone();
addItemsIL.addAll(ilCopy);
addItemsCounter++;
}
else
{
context.addInstruction(OP_dup); // stack: ..., addItems, addItems
context.addInstruction(OP_getlocal3); // stack: ..., addItems, addItems, instanceFuncs[]
context.pushNumericConstant(index); // stack: ..., addItems, addItems, instanceFuncs[], index
context.addInstruction(OP_getproperty, IMXMLTypeConstants.NAME_ARRAYINDEXPROP);
// stack: ..., addItems, addItems, instanceFunction
context.addInstruction(OP_setproperty, new Name("itemsFactory"));
// stack: ..., addItems
}
//-----------------------------------------------------------------------------
// Second property set: maybe set destination and propertyName
// get the property specifier node for the property the instanceNode represents
IMXMLPropertySpecifierNode propertySpecifier = (IMXMLPropertySpecifierNode)
instanceNode.getAncestorOfType( IMXMLPropertySpecifierNode.class);
if (propertySpecifier == null)
{
assert false; // I think this indicates an invalid tree...
}
else
{
// Check the parent - if it's an instance then we want to use these
// nodes to get our property values from. If not, then it's the root
// and we don't need to specify destination
IASNode parent = propertySpecifier.getParent();
if (parent instanceof IMXMLInstanceNode)
{
IMXMLInstanceNode parentInstance = (IMXMLInstanceNode)parent;
String parentId = parentInstance.getEffectiveID();
assert parentId != null;
String propName = propertySpecifier.getName();
if (getProject().getTargetSettings().getMxmlChildrenAsData())
{
addItemsIL.addInstruction(OP_pushstring, "destination");
addItemsIL.addInstruction(OP_pushtrue); // simple type
addItemsIL.addInstruction(OP_pushstring, parentId);
addItemsIL.addInstruction(OP_pushstring, "propertyName");
addItemsIL.addInstruction(OP_pushtrue); // simple type
addItemsIL.addInstruction(OP_pushstring, propName);
addItemsCounter += 2;
}
else
{
context.addInstruction(OP_dup); // stack: ..., addItems, addItems
context.addInstruction(OP_pushstring, parentId);
context.addInstruction(OP_setproperty, new Name("destination"));
// stack: ..., addItems
context.addInstruction(OP_dup); // stack: ..., addItems, addItems
context.addInstruction(OP_pushstring, propName);
context.addInstruction(OP_setproperty, new Name("propertyName"));
// stack: ..., addItems
}
}
}
//---------------------------------------------------------------
// Third property set: position and relativeTo
String positionPropertyValue = null;
String relativeToPropertyValue = null;
// look to see if we have any sibling nodes that are not state dependent
// that come BEFORE us
IASNode instanceParent = instanceNode.getParent();
IASNode prevStatelessSibling=null;
for (int i=0; i< instanceParent.getChildCount(); ++i)
{
IASNode sib = instanceParent.getChild(i);
if (sib instanceof IMXMLInstanceNode)
{
// stop looking for previous nodes when we find ourself
if (sib == instanceNode)
break;
if (!isStateDependent(sib))
{
prevStatelessSibling = sib;
}
}
}
if (prevStatelessSibling == null) {
positionPropertyValue = "first"; // TODO: these should be named constants
}
else {
positionPropertyValue = "after";
relativeToPropertyValue = ((IMXMLInstanceNode)prevStatelessSibling).getEffectiveID();
}
if (getProject().getTargetSettings().getMxmlChildrenAsData())
{
// position
addItemsIL.addInstruction(OP_pushstring, "position");
addItemsIL.addInstruction(OP_pushtrue);
addItemsIL.addInstruction(OP_pushstring, positionPropertyValue);
addItemsCounter++;
}
else
{
// position
context.addInstruction(OP_dup);
context.addInstruction(OP_pushstring, positionPropertyValue);
context.addInstruction(OP_setproperty, new Name("position"));
}
// relativeTo
if (relativeToPropertyValue != null)
{
if (getProject().getTargetSettings().getMxmlChildrenAsData())
{
// position
addItemsIL.addInstruction(OP_pushstring, "relativeTo");
addItemsIL.addInstruction(OP_pushtrue);
addItemsIL.addInstruction(OP_pushstring, relativeToPropertyValue);
addItemsCounter++;
}
else
{
context.addInstruction(OP_dup);
context.addInstruction(OP_pushstring, relativeToPropertyValue);
context.addInstruction(OP_setproperty, new Name("relativeTo"));
}
}
if (getProject().getTargetSettings().getMxmlChildrenAsData())
{
context.pushNumericConstant(addItemsCounter);