public static Transcoder.TranscodingResults transcode(Transcoder[] transcoders,
CompilationUnit unit, SymbolTable symbolTable,
String className, Map<String, Object> args, int line, int col,
boolean generateCode)
{
PathResolver context = new PathResolver();
Transcoder.TranscodingResults results = null;
Source source = unit.getSource();
if (!args.containsKey(Transcoder.RESOLVED_SOURCE))
{
String embedSource = (String) args.get(Transcoder.SOURCE);
// paths starting with slash are either relative to a source path root or
// fully qualified.
if (embedSource != null && embedSource.charAt(0) == '/')
{
VirtualFile pathRoot = source.getPathRoot();
if (pathRoot != null)
{
context.addSinglePathResolver(pathRoot);
}
Object owner = source.getOwner();
if (owner instanceof SinglePathResolver)
{
context.addSinglePathResolver((SinglePathResolver) owner);
}
}
else
{
if ( args.containsKey(Transcoder.FILE) )
{
String path = (String) args.get(Transcoder.FILE);
String pathSep = (String) args.get(Transcoder.PATHSEP);
if ("true".equals(pathSep))
{
path = path.replace('/', '\\');
}
VirtualFile contextFile = LocalFilePathResolver.getSingleton().resolve(path);
// If the contextFile is the same as the Source's file, then don't add
// it as a path resolver, because we'll rely on the Source's
// delegate/backing file. If we don't do this, then some relative
// paths might incorrectly be resolved relative to the generated .as
// file, instead of the original mxml file.
if ((contextFile != null) && !contextFile.getName().equals(source.getName()))
{
context.addSinglePathResolver(contextFile);
}
}
VirtualFile backingFile = source.getBackingFile();
if (backingFile != null)
{
context.addSinglePathResolver(backingFile);
}
}
context.addSinglePathResolver( ThreadLocalToolkit.getPathResolver() );
}
else
{
// This is necessary to handle FlexInit's Embeds, because
// FlexInit is recompiled any time something changes in an
// incremental compilation and the original document might
// not have needed to be recompiled, so the resolved
// VirtualFile won't be cached in the ThreadLocalToolkit.
// The LocalFilePathResolver should be sufficient to turn
// the resolved path into a VirtualFile.
context.addSinglePathResolver(LocalFilePathResolver.getSingleton());
}
if (!unit.hasAssets() || !unit.getAssets().contains(className))
{
results = transcode(transcoders, symbolTable, className, args, line, col, generateCode, source, context);