if (benchmarkHelper != null)
{
benchmarkHelper.startPhase(CompilerBenchmarkHelper.PARSE1, source.getNameForReporting());
}
CompilationUnit unit = source.getCompilationUnit();
if (unit != null && unit.hasTypeInfo)
{
return unit;
}
// System.out.println("parse1: " + source.getNameForReporting());
FontManager fontManager = configuration.getFontsConfiguration().getTopLevelManager();
StyleSheet styleSheet = new StyleSheet();
styleSheet.checkDeprecation(configuration.showDeprecationWarnings());
InputStream in = null;
try
{
in = source.getInputStream();
styleSheet.parse(source.getName(),
in,
ThreadLocalToolkit.getLogger(),
fontManager);
}
catch (Exception exception)
{
if (Trace.error)
{
exception.printStackTrace();
}
ParseError parseError = new ParseError(exception.getLocalizedMessage());
parseError.setPath(source.getName());
ThreadLocalToolkit.log(parseError);
return null;
}
finally
{
if (in != null)
{
try
{
in.close();
}
catch (IOException ex)
{
}
}
}
if (styleSheet.errorsExist())
{
// Error
ThreadLocalToolkit.getLogger().log(new StyleSheetParseError(source.getName()));
}
StyleModule styleModule = new StyleModule(source, symbolTable.perCompileData);
// Flex3 and earlier didn't support qualified types or advanced css.
if (configuration.getCompatibilityVersion() <= flex2.compiler.common.MxmlConfiguration.VERSION_3_0)
{
styleModule.setAdvanced(false);
styleModule.setQualifiedTypeSelectors(false);
}
else
{
styleModule.setQualifiedTypeSelectors(configuration.getQualifiedTypeSelectors());
}
styleModule.setNameMappings(nameMappings);
String styleName = generateStyleName(source);
styleModule.setName(styleName);
styleModule.extractStyles(styleSheet, false);
CompilerContext context = new CompilerContext();
CompilationUnit cssCompilationUnit = source.newCompilationUnit(null, context);
VirtualFile generatedFile = generateSourceCodeFile(cssCompilationUnit, styleModule);
Source generatedSource = new Source(generatedFile, source);
// when building a SWC, we want to locate all the asset sources and ask compc to put them in the SWC.
Collection<AtEmbed> atEmbeds = styleModule.getAtEmbeds();
if (atEmbeds != null && configuration.archiveClassesAndAssets())
{
Map<String, LocalFile> archiveFiles = new HashMap<String, LocalFile>();
for (Iterator<AtEmbed> i = atEmbeds.iterator(); i.hasNext(); )
{
AtEmbed e = (AtEmbed) i.next();
String src = (String) e.getAttributes().get(Transcoder.SOURCE);
String original = (String) e.getAttributes().get(Transcoder.ORIGINAL);
if (src != null)
{
archiveFiles.put(original, new LocalFile(new File(src)));
}
}
if (archiveFiles.size() > 0)
{
context.setAttribute(CompilerContext.CSS_ARCHIVE_FILES, archiveFiles);
}
}
// Use MxmlLogAdapter to do filtering, e.g. -generated.as -> .css, as line -> css
// line, etc...
Logger original = ThreadLocalToolkit.getLogger();
LineNumberMap lineNumberMap = styleModule.getLineNumberMap();
Logger adapter = new MxmlLogAdapter(original, lineNumberMap);
ThreadLocalToolkit.setLogger(adapter);
CompilationUnit ascCompilationUnit = delegateSubCompiler.parse1(generatedSource, symbolTable);
if (ascCompilationUnit != null)
{
// transfer includes from the ASC unit to the CSS unit
cssCompilationUnit.getSource().addFileIncludes(ascCompilationUnit.getSource());
context.setAttribute(DELEGATE_UNIT, ascCompilationUnit);
context.setAttribute(LINE_NUMBER_MAP, lineNumberMap);
Source.transferMetaData(ascCompilationUnit, cssCompilationUnit);
Source.transferGeneratedSources(ascCompilationUnit, cssCompilationUnit);
Source.transferDefinitions(ascCompilationUnit, cssCompilationUnit);