* @param unLinked the SWF to process
* @return A SWF that is the resulting of merging, optimizing, etc.
*/
protected ISWF linkSWF(ISWF unLinked)
{
SWF result = new SWF();
if( unLinked.getBackgroundColor() != null )
result.setBackgroundColor(unLinked.getBackgroundColor());
result.setEnableDebugger2(unLinked.getEnableDebugger2());
result.setFrameRate(unLinked.getFrameRate());
result.setFrameSize(unLinked.getFrameSize());
result.setMetadata(unLinked.getMetadata());
ScriptLimitsTag scriptLimits = unLinked.getScriptLimits();
if (scriptLimits != null)
result.setScriptLimits(scriptLimits.getMaxRecursionDepth(), scriptLimits.getScriptTimeoutSeconds());
result.setTopLevelClass(unLinked.getTopLevelClass());
result.setUseAS3(unLinked.getUseAS3());
result.setUseDirectBlit(unLinked.getUseDirectBlit());
result.setUseGPU(unLinked.getUseGPU());
result.setUseNetwork(unLinked.getUseNetwork());
result.setVersion(unLinked.getVersion());
result.setProductInfo(unLinked.getProductInfo());
ITargetSettings settings = getTargetSettings();
ABCLinker.ABCLinkerSettings linkSettings = new ABCLinker.ABCLinkerSettings();
linkSettings.setOptimize(settings.isOptimized());
linkSettings.setEnableInlining(project.isInliningEnabled());
linkSettings.setStripDebugOpcodes(!settings.isDebugEnabled());
linkSettings.setStripGotoDefinitionHelp(!settings.isDebugEnabled());
linkSettings.setStripFileAttributeFromGotoDefinitionHelp(settings.isOptimized());
linkSettings.setProblemsCollection(this.problemCollection);
linkSettings.setRemoveDeadCode(settings.getRemoveDeadCode());
Collection<String> metadataNames = getASMetadataNames();
if (settings.isDebugEnabled() && metadataNames != null)
{
Collection<String> names = new ArrayList<String>(metadataNames);
names.add(IMetaAttributeConstants.ATTRIBUTE_GOTODEFINITIONHELP);
names.add(IMetaAttributeConstants.ATTRIBUTE_GOTODEFINITION_CTOR_HELP);
metadataNames = names;
}
setKeepAS3MetadataLinkerSetting(linkSettings);
for (int i = 0; i < unLinked.getFrameCount(); ++i)
{
SWFFrame unlinkedFrame = unLinked.getFrameAt(i);
SWFFrame resultFrame = new SWFFrame();
if( unlinkedFrame.getName() != null )
resultFrame.setName(unlinkedFrame.getName(), unlinkedFrame.hasNamedAnchor());
LinkedList<DoABCTag> accumulatedABC = new LinkedList<DoABCTag>();
for (ITag unlinkedTag : unlinkedFrame)
{
if (unlinkedTag instanceof DoABCTag)
{
final DoABCTag abcTag = (DoABCTag)unlinkedTag;
accumulatedABC.add(abcTag);
}
else
{
if (!accumulatedABC.isEmpty())
{
try
{
addLinkedABCToFrame(resultFrame, accumulatedABC, linkSettings);
}
catch (Exception e)
{
return unLinked;
}
accumulatedABC.clear();
}
if (!(unlinkedTag instanceof IManagedTag))
{
resultFrame.addTag(unlinkedTag);
}
else if( unlinkedTag instanceof SymbolClassTag )
{
SymbolClassTag s = (SymbolClassTag)unlinkedTag;
for( String symbol_name : s.getSymbolNames() )
{
resultFrame.defineSymbol(s.getSymbol(symbol_name), symbol_name);
}
}
}
}
if (!accumulatedABC.isEmpty())
{
try
{
addLinkedABCToFrame(resultFrame, accumulatedABC, linkSettings);
}
catch (Exception e)
{
return unLinked;
}
accumulatedABC.clear();
}
result.addFrame(resultFrame);
}
return result;
}