flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erikdebr...@apache.org
Subject [3/9] git commit: [flex-falcon] [refs/heads/develop] - output encoded CSS from fx:Style blocks
Date Wed, 13 Nov 2013 10:52:22 GMT
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/d98ce9dc
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/d98ce9dc
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/d98ce9dc

Branch: refs/heads/develop
Commit: d98ce9dc259f51253cbe7c3d792e46ff5a8a4a79
Parents: 9e10215
Author: Alex Harui <aharui@apache.org>
Authored: Tue Nov 12 15:31:06 2013 -0800
Committer: Erik de Bruin <erik@ixsoftware.nl>
Committed: Wed Nov 13 08:13:38 2013 +0100

----------------------------------------------------------------------
 .../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/d98ce9dc/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/d98ce9dc/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/d98ce9dc/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/d98ce9dc/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/d98ce9dc/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/d98ce9dc/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;
     }
 


Mime
View raw message