Updated Branches: refs/heads/develop dc0c5fe49 -> 1228acacf
output encoded CSS from fx:Style blocks Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/1228acac Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/1228acac Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/1228acac Branch: refs/heads/develop Commit: 1228acacfee1be216becf0acba514fe12fa1410e Parents: dc0c5fe Author: Alex Harui <[email protected]> Authored: Tue Nov 12 15:31:06 2013 -0800 Committer: Alex Harui <[email protected]> Committed: Tue Nov 12 15:31:06 2013 -0800 ---------------------------------------------------------------------- .../internal/codegen/mxml/MXMLBlockWalker.java | 4 +- .../mxml/flexjs/MXMLFlexJSBlockWalker.java | 42 +++++++++++++++++++ .../codegen/mxml/flexjs/MXMLFlexJSEmitter.java | 44 ++++++++++++++++++++ .../internal/projects/FlexJSProject.java | 8 ++++ .../compiler/internal/projects/FlexProject.java | 8 ++++ .../internal/tree/mxml/MXMLFileNode.java | 2 +- 6 files changed, 105 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1228acac/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java index 9c968e9..d7dfabd 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java @@ -88,7 +88,7 @@ public class MXMLBlockWalker implements IMXMLBlockVisitor, IMXMLBlockWalker // errors //---------------------------------- - private List<ICompilerProblem> errors; + protected List<ICompilerProblem> errors; List<ICompilerProblem> getErrors() { @@ -99,7 +99,7 @@ public class MXMLBlockWalker implements IMXMLBlockVisitor, IMXMLBlockWalker // project //---------------------------------- - private IASProject project; + protected IASProject project; public IASProject getProject() { http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1228acac/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSBlockWalker.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSBlockWalker.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSBlockWalker.java index 70d99ed..6e62dbe 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSBlockWalker.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSBlockWalker.java @@ -19,18 +19,30 @@ package org.apache.flex.compiler.internal.codegen.mxml.flexjs; +import java.util.Collection; +import java.util.HashSet; import java.util.List; import org.apache.flex.compiler.codegen.as.IASEmitter; import org.apache.flex.compiler.codegen.mxml.IMXMLEmitter; import org.apache.flex.compiler.codegen.mxml.flexjs.IMXMLFlexJSEmitter; +import org.apache.flex.compiler.css.ICSSDocument; +import org.apache.flex.compiler.css.ICSSRule; +import org.apache.flex.compiler.internal.caches.CSSDocumentCache; import org.apache.flex.compiler.internal.codegen.mxml.MXMLBlockWalker; +import org.apache.flex.compiler.internal.css.codegen.CSSCompilationSession; +import org.apache.flex.compiler.internal.driver.js.flexjs.JSCSSCompilationSession; +import org.apache.flex.compiler.internal.projects.FlexJSProject; import org.apache.flex.compiler.problems.ICompilerProblem; import org.apache.flex.compiler.projects.IASProject; +import org.apache.flex.compiler.projects.IFlexProject; import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode; import org.apache.flex.compiler.tree.mxml.IMXMLFileNode; +import org.apache.flex.compiler.tree.mxml.IMXMLStyleNode; import org.apache.flex.compiler.visitor.IBlockWalker; +import com.google.common.collect.ImmutableList; + /** * @author Michael Schmalle * @author Erik de Bruin @@ -49,6 +61,8 @@ public class MXMLFlexJSBlockWalker extends MXMLBlockWalker this.mxmlEmitter = mxmlEmitter; } + public String encodedCSS = ""; + //-------------------------------------------------------------------------- @Override @@ -67,4 +81,32 @@ public class MXMLFlexJSBlockWalker extends MXMLBlockWalker ((IMXMLFlexJSEmitter) mxmlEmitter).emitDocument(node); } + @Override + public void visitStyleBlock(IMXMLStyleNode node) + { + ICSSDocument css = node.getCSSDocument(errors); + StringBuilder sb = new StringBuilder(); + ImmutableList<ICSSRule> rules = css.getRules(); + for (ICSSRule rule : rules) + { + sb.append(rule.toString()); + sb.append("\n\n"); + } + ((FlexJSProject)project).cssDocument += sb.toString(); + + // Ignore semanticProblems. They should have been collected during the semantic analysis phase already. + final Collection<ICompilerProblem> problems = new HashSet<ICompilerProblem>(); + if (css == CSSDocumentCache.EMPTY_CSS_DOCUMENT) + return; + + final IFlexProject flexProject = (IFlexProject)getProject(); + + final CSSCompilationSession session = node.getFileNode().getCSSCompilationSession(); + if (session == null) + return; + + session.setKeepAllTypeSelectors(true); + encodedCSS += ((JSCSSCompilationSession)session).getEncodedCSS(flexProject, problems); + } + } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1228acac/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java index d05067e..732fc4b 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java @@ -20,6 +20,7 @@ package org.apache.flex.compiler.internal.codegen.mxml.flexjs; +import java.io.File; import java.io.FilterWriter; import java.util.ArrayList; import java.util.List; @@ -42,6 +43,7 @@ import org.apache.flex.compiler.internal.codegen.databinding.StaticPropertyWatch import org.apache.flex.compiler.internal.codegen.databinding.WatcherInfoBase; import org.apache.flex.compiler.internal.codegen.databinding.WatcherInfoBase.WatcherType; import org.apache.flex.compiler.internal.codegen.databinding.XMLWatcherInfo; +import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens; import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter; import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens; import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens; @@ -164,6 +166,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements emitBindingData(cname, cdef); + emitEncodedCSS(cname); } //-------------------------------------------------------------------------- @@ -1328,6 +1331,36 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements // JS output //-------------------------------------------------------------------------- + private void emitEncodedCSS(String cname) + { + String s = ((MXMLFlexJSBlockWalker)getMXMLWalker()).encodedCSS; + if (!s.isEmpty()) + { + int reqidx = s.indexOf("goog.require"); + if (reqidx != -1) + s = s.substring(0, reqidx - 1); + + writeNewline(); + writeNewline("/**"); + writeNewline(" * @expose"); + writeNewline(" * @this {" + cname + "}"); + writeNewline(" */"); + StringBuilder sb = new StringBuilder(); + sb.append(cname); + sb.append(ASEmitterTokens.MEMBER_ACCESS.getToken()); + sb.append(JSEmitterTokens.PROTOTYPE.getToken()); + sb.append(ASEmitterTokens.MEMBER_ACCESS.getToken()); + sb.append("cssData"); + sb.append(ASEmitterTokens.SPACE.getToken() + + ASEmitterTokens.EQUAL.getToken() + + ASEmitterTokens.SPACE.getToken() + + ASEmitterTokens.SQUARE_OPEN.getToken()); + sb.append(s); + write(sb.toString()); + writeNewline(); + } + } + private void emitHeader(IMXMLDocumentNode node) { String cname = node.getFileNode().getName(); @@ -1395,6 +1428,17 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements } } + String s = ((MXMLFlexJSBlockWalker)getMXMLWalker()).encodedCSS; + if (!s.isEmpty()) + { + int reqidx = s.indexOf("goog.require"); + if (reqidx != -1) + { + String reqs = s.substring(reqidx); + writeNewline(reqs); + } + } + // erikdebruin: Add missing language feature support, like the 'is' and // 'as' operators. We don't need to worry about requiring // this in every project: ADVANCED_OPTIMISATIONS will NOT http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1228acac/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java b/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java index d3ee538..eb1fa63 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java @@ -25,7 +25,9 @@ import java.util.Set; import org.apache.flex.compiler.common.DependencyType; import org.apache.flex.compiler.definitions.IDefinition; import org.apache.flex.compiler.internal.codegen.mxml.flexjs.MXMLFlexJSEmitterTokens; +import org.apache.flex.compiler.internal.css.codegen.CSSCompilationSession; import org.apache.flex.compiler.internal.definitions.InterfaceDefinition; +import org.apache.flex.compiler.internal.driver.js.flexjs.JSCSSCompilationSession; import org.apache.flex.compiler.internal.scopes.ASProjectScope.DefinitionPromise; import org.apache.flex.compiler.internal.tree.mxml.MXMLClassDefinitionNode; import org.apache.flex.compiler.internal.workspaces.Workspace; @@ -141,4 +143,10 @@ public class FlexJSProject extends FlexProject return null; } + @Override + public CSSCompilationSession getCSSCompilationSession() + { + return new JSCSSCompilationSession(); + } + } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1228acac/compiler/src/org/apache/flex/compiler/internal/projects/FlexProject.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/projects/FlexProject.java b/compiler/src/org/apache/flex/compiler/internal/projects/FlexProject.java index 69f0bff..a6b5761 100644 --- a/compiler/src/org/apache/flex/compiler/internal/projects/FlexProject.java +++ b/compiler/src/org/apache/flex/compiler/internal/projects/FlexProject.java @@ -56,6 +56,7 @@ import org.apache.flex.compiler.exceptions.LibraryCircularDependencyException; import org.apache.flex.compiler.filespecs.IFileSpecification; import org.apache.flex.compiler.internal.as.codegen.BindableHelper; import org.apache.flex.compiler.internal.css.CSSManager; +import org.apache.flex.compiler.internal.css.codegen.CSSCompilationSession; import org.apache.flex.compiler.internal.definitions.ClassDefinition; import org.apache.flex.compiler.internal.definitions.NamespaceDefinition; import org.apache.flex.compiler.internal.definitions.PackageDefinition; @@ -1452,6 +1453,13 @@ public class FlexProject extends ASProject implements IFlexProject return cssManager; } + + public CSSCompilationSession getCSSCompilationSession() + { + return new CSSCompilationSession(); + } + + /** * String that replaces occurrences of "{context.root}" in the * services-config.xml. The context root is specified using the http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1228acac/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLFileNode.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLFileNode.java b/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLFileNode.java index 7bf0aaa..b31898e 100644 --- a/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLFileNode.java +++ b/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLFileNode.java @@ -511,7 +511,7 @@ public class MXMLFileNode extends MXMLNodeBase implements IMXMLFileNode, IScoped public synchronized CSSCompilationSession getCSSCompilationSession() { if (cssCompilationSession == null) - cssCompilationSession = new CSSCompilationSession(); + cssCompilationSession = project.getCSSCompilationSession(); return cssCompilationSession; }
