final MXMLTreeBuilder builder =
new MXMLTreeBuilder(this, getFileSpecificationGetter(), qname, mxmlData, fileScope, problems);
// Use the MXMLTreeBuilder to build an MXMLFileNode (the root of an MXML AST)
// from the MXMLData (the MXML DOM) and the MXMLFileScope.
final IMXMLFileNode fileNode = builder.build();
try
{
// TODO This belongs in MXMLDocumentNode.
MXMLDocumentNode documentNode = (MXMLDocumentNode)fileNode.getDocumentNode();
if (documentNode != null)
{
ClassDefinition mainClassDefinition = fileScope.getMainClassDefinition();
if (mainClassDefinition != null)
{
TypeScope mainClassScope = (TypeScope)mainClassDefinition.getContainedScope();
documentNode.setScope(mainClassScope);
}
}
// Start CSS semantic analysis.
final Function<IMXMLStyleNode, ICSSDocument> parseMXMLStyleNode = new Function<IMXMLStyleNode, ICSSDocument>()
{
@Override
public ICSSDocument apply(IMXMLStyleNode mxmlStyleNode)
{
// This method will trigger the CSS parser to parse the CSS fragment.
return mxmlStyleNode.getCSSDocument(problems);
}
};
final Collection<ICSSDocument> cssDocumentList =
transform(fileNode.getStyleNodes(), parseMXMLStyleNode);
// This method will resolve dependencies introduced by the CSS fragment, and add the
// dependee's to the dependency graph. This is done at the last step in MXML tree
// building phase.
// - It can't be done in MXML semantic analysis, because MXML code generation doesn't
// depend on MXML semantic analysis;
// - It can't be done in MXML code generation either, because the "problems" in that phase are
// generated from inside ABCGenerator.
updateStyleCompilationUnitDependencies(
fileNode.getCSSCompilationSession(),
fileScope,
cssDocumentList,
problems);
fileNode.getCSSCompilationSession().cssDocuments.addAll(cssDocumentList);
}
catch (Throwable e)
{
//something went wrong, so log it.
problems.add(new UnexpectedExceptionProblem(e));
}
finally
{
stopProfile(Operation.GET_SYNTAX_TREE);
}
return new SyntaxTreeRequestResult(fileNode, ImmutableSet.<String>copyOf(fileScope.getSourceDependencies()), fileNode.getIncludeTreeLastModified(), problems);
}