if (unit.icon != null)
{
// We used to resolve the icon here, but that was moved
// upstream to SyntaxTreeEvaluator.processIconFileMetaData(),
// so we don't have to hang on to the PathResolver until now.
VirtualFile iconFile = unit.iconFile;
Source source = unit.getSource();
// If the source came from a SWC, try looking for the icon in the SWC.
if ((iconFile == null) && source.isSwcScriptOwner())
{
for (int i = 0, s = unit.topLevelDefinitions.size();i < s; i++)
{
String def = unit.topLevelDefinitions.get(i).toString();
if (components.containsKey(def))
{
String swcIcon = components.get(def).getIcon();
if (swcIcon != null)
{
iconFile = (((SwcScript) source.getOwner()).getLibrary().getSwc().getFile(swcIcon));
if (iconFile != null)
{
// we then put the resolved file into an InMemoryFile so that we can changed its name
VirtualFile inMemFile = new InMemoryFile(iconFile.getInputStream(), swcIcon,
MimeMappings.getMimeType(swcIcon),
iconFile.getLastModified());
archive.putFile( inMemFile );
return;
}
}
}
}
// It seems like this will never be true, because if
// the icon was missing when the original SWC was
// created, a MissingIconFile would have been thrown.
if (iconFile == null)
{
return;
}
}
if (iconFile == null)
{
throw new SwcException.MissingIconFile(unit.icon, sourceName);
}
// yes using both toDot and toColon here feels very wacky
String workingSourceName = NameFormatter.toColon(NameFormatter.toDot(sourceName, '/'));
SwcComponent comp = components.get(workingSourceName);
String rel = source.getRelativePath();
String iconName = (rel == null || rel.length() == 0) ? unit.icon : rel + "/" + unit.icon;
if (comp != null)
{
comp.setIcon(iconName);
}
// we then put the resolved file into an InMemoryFile so that we can changed its name
VirtualFile inMemFile = new InMemoryFile(iconFile.getInputStream(), iconName,
MimeMappings.getMimeType(iconName),
iconFile.getLastModified());
archive.putFile( inMemFile );
}
}