flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [3/3] git commit: [flex-falcon] - Fix MXMLFlexJSEmitter so it handles top tag properties on all MXML files
Date Wed, 01 May 2013 19:03:49 GMT
Fix MXMLFlexJSEmitter so it handles top tag properties on all MXML files


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/d80c9857
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/d80c9857
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/d80c9857

Branch: refs/heads/develop
Commit: d80c98572c23adf691a0e6cc35787a8363d9180d
Parents: 7bf1bda
Author: Alex Harui <aharui@apache.org>
Authored: Wed May 1 12:03:31 2013 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Wed May 1 12:03:31 2013 -0700

----------------------------------------------------------------------
 .../flexjs/files/FlexJSTest_again_result.js        |   23 --
 .../test-files/flexjs/files/MyInitialView.mxml     |    2 +-
 .../flexjs/files/MyInitialView_result.js           |   24 +--
 .../flexjs/files/wildcard_import_result.js         |   48 ---
 .../flex/compiler/internal/codegen/Emitter.java    |    3 +-
 .../mxml/flexjs/MXMLDescriptorSpecifier.java       |   22 +--
 .../codegen/mxml/flexjs/MXMLFlexJSEmitter.java     |  224 ++++++++-------
 7 files changed, 128 insertions(+), 218 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d80c9857/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js b/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js
index 0e9dc85..dc592ed 100644
--- a/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js
+++ b/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js
@@ -137,29 +137,6 @@ FlexJSTest_again.prototype.set_collection = function(value)
  * @this {FlexJSTest_again}
  * @return {Array} the Array of UI element descriptors.
  */
-FlexJSTest_again.prototype.get_MXMLDescriptor = function()
-{
-	if (this.mxmldd == undefined)
-	{
-		/** @type {Array} */
-		var arr = goog.base(this, 'get_MXMLDescriptor');
-		/** @type {Array} */
-		var data = [
-];
-	
-		if (arr)
-			this.mxmldd = arr.concat(data);
-		else
-			this.mxmldd = data;
-	}
-	return this.mxmldd;
-};
-
-/**
- * @override
- * @this {FlexJSTest_again}
- * @return {Array} the Array of UI element descriptors.
- */
 FlexJSTest_again.prototype.get_MXMLProperties = function()
 {
 	if (this.mxmldp == undefined)

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d80c9857/compiler.jx.tests/test-files/flexjs/files/MyInitialView.mxml
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/MyInitialView.mxml b/compiler.jx.tests/test-files/flexjs/files/MyInitialView.mxml
index 69fdf71..f2cc9c7 100644
--- a/compiler.jx.tests/test-files/flexjs/files/MyInitialView.mxml
+++ b/compiler.jx.tests/test-files/flexjs/files/MyInitialView.mxml
@@ -69,7 +69,7 @@ limitations under the License.
 								 destinationPropertyName="text" />
 		</basic:beads>
 	</basic:Label>
-	<basic:TextButton text="Start Timer" x="100" y="75" click="startTimer()" />
+	<basic:TextButton text="Let's Start Timer" x="100" y="75" click="startTimer()" />
 	<basic:TextButton text="Stop Timer" x="100" y="100" click="timer.removeEventListener('timer',
timerHandler);timer.stop()" />
 	<basic:Label id="timerLabel" x="100" y="125" />
 	

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d80c9857/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js b/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
index 3e91753..7ac5c67 100644
--- a/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
+++ b/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
@@ -484,7 +484,7 @@ true,
 '$ID1',
 'text',
 true,
-'Start Timer',
+'Let\'s Start Timer',
 'y',
 true,
 75,
@@ -843,26 +843,4 @@ null
 	return this.mxmldd;
 };
 
-/**
- * @override
- * @this {MyInitialView}
- * @return {Array} the Array of UI element descriptors.
- */
-MyInitialView.prototype.get_MXMLProperties = function()
-{
-	if (this.mxmldp == undefined)
-	{
-		/** @type {Array} */
-		var arr = goog.base(this, 'get_MXMLProperties');
-		/** @type {Array} */
-		var data = [
-];
-	
-		if (arr)
-			this.mxmldp = arr.concat(data);
-		else
-			this.mxmldp = data;
-	}
-	return this.mxmldp;
-};
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d80c9857/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js b/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js
index 9c7c4c9..6923f67 100644
--- a/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js
+++ b/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js
@@ -32,52 +32,4 @@ wildcard_import.prototype.tmp = function() {
 	myButton = new org.apache.flex.html.staticControls.Button();
 };
 
-/**
- * @override
- * @this {wildcard_import}
- * @return {Array} the Array of UI element descriptors.
- */
-wildcard_import.prototype.get_MXMLDescriptor = function()
-{
-	if (this.mxmldd == undefined)
-	{
-		/** @type {Array} */
-		var arr = goog.base(this, 'get_MXMLDescriptor');
-		/** @type {Array} */
-		var data = [
-];
-	
-		if (arr)
-			this.mxmldd = arr.concat(data);
-		else
-			this.mxmldd = data;
-	}
-	return this.mxmldd;
-};
-
-/**
- * @override
- * @this {wildcard_import}
- * @return {Array} the Array of UI element descriptors.
- */
-wildcard_import.prototype.get_MXMLProperties = function()
-{
-	if (this.mxmldp == undefined)
-	{
-		/** @type {Array} */
-		var arr = goog.base(this, 'get_MXMLProperties');
-		/** @type {Array} */
-		var data = [
-0,
-0,
-0
-];
-	
-		if (arr)
-			this.mxmldp = arr.concat(data);
-		else
-			this.mxmldp = data;
-	}
-	return this.mxmldp;
-};
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d80c9857/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java
index 82d7163..c399d73 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java
@@ -154,7 +154,8 @@ public class Emitter implements IEmitter
     @Override
     public void indentPop()
     {
-        currentIndent--;
+        if (currentIndent > 0)
+            currentIndent--;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d80c9857/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java
index c8fd737..e4c98a5 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java
@@ -76,10 +76,10 @@ public class MXMLDescriptorSpecifier extends MXMLNodeSpecifier
     public String id;
 
     //---------------------------------
-    //    isTopNodeInMainFile
+    //    isTopNode
     //---------------------------------
 
-    public boolean isTopNodeInMainFile;
+    public boolean isTopNode;
 
     //---------------------------------
     //    isProperty
@@ -88,23 +88,11 @@ public class MXMLDescriptorSpecifier extends MXMLNodeSpecifier
     public boolean isProperty;
     
     //---------------------------------
-    //    name
-    //---------------------------------
-
-    public String name;
-
-    //---------------------------------
     //    parent
     //---------------------------------
 
     public MXMLDescriptorSpecifier parent;
 
-    //---------------------------------
-    //    value
-    //---------------------------------
-
-    public String value;
-
     //--------------------------------------------------------------------------
     //
     //    Methods
@@ -205,7 +193,7 @@ public class MXMLDescriptorSpecifier extends MXMLNodeSpecifier
     @Override
     public String output(boolean writeNewline)
     {
-        if (isTopNodeInMainFile)
+        if (isTopNode)
         {
             int count = 0;
             for (MXMLDescriptorSpecifier md : propertySpecifiers)
@@ -257,7 +245,7 @@ public class MXMLDescriptorSpecifier extends MXMLNodeSpecifier
 
             outputEventSpecifier(writeNewline);
             
-            if (!isTopNodeInMainFile)
+            if (!isTopNode)
             {
                 writeDelimiter(writeNewline);
                 
@@ -270,7 +258,7 @@ public class MXMLDescriptorSpecifier extends MXMLNodeSpecifier
                     && parent.propertySpecifiers.indexOf(this) == parent.propertySpecifiers
                             .size() - 1;
 
-            if (!isLastChild && !isTopNodeInMainFile)
+            if (!isLastChild && !isTopNode)
                 writeDelimiter(writeNewline);
         }
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d80c9857/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 0f10cd8..a2bd7e3 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
@@ -58,6 +58,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
     private ArrayList<MXMLDescriptorSpecifier> currentInstances;
     private ArrayList<MXMLDescriptorSpecifier> currentPropertySpecifiers;
     private ArrayList<MXMLDescriptorSpecifier> descriptorTree;
+    private MXMLDescriptorSpecifier propertiesTree;
     private ArrayList<MXMLEventSpecifier> events;
     private ArrayList<MXMLDescriptorSpecifier> instances;
     private ArrayList<MXMLScriptSpecifier> scripts;
@@ -66,7 +67,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
     private int eventCounter;
     private int idCounter;
 
-    private boolean isMainFile;
+    private boolean inMXMLContent;
 
     public MXMLFlexJSEmitter(FilterWriter out)
     {
@@ -79,6 +80,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
     public void emitDocument(IMXMLDocumentNode node)
     {
         descriptorTree = new ArrayList<MXMLDescriptorSpecifier>();
+        propertiesTree = new MXMLDescriptorSpecifier();
 
         events = new ArrayList<MXMLEventSpecifier>();
         instances = new ArrayList<MXMLDescriptorSpecifier>();
@@ -88,25 +90,9 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
         currentInstances = new ArrayList<MXMLDescriptorSpecifier>();
         currentPropertySpecifiers = new ArrayList<MXMLDescriptorSpecifier>();
 
-        isMainFile = true;
-        IMXMLPropertySpecifierNode[] propertySpecifierNodes = node
-                .getPropertySpecifierNodes();
-        if (propertySpecifierNodes != null && propertySpecifierNodes.length >
0)
-            isMainFile = !isMXMLContentNode((IMXMLPropertySpecifierNode) node
-                    .getPropertySpecifierNodes()[0]);
-
         eventCounter = 0;
         idCounter = 0;
 
-        if (isMainFile)
-        {
-            // fake root node; the main file doesn't have 'mxmlContent' as root 
-            MXMLDescriptorSpecifier fakeRoot = new MXMLDescriptorSpecifier();
-            fakeRoot.name = "mxmlContent";
-            descriptorTree.add(fakeRoot);
-            currentInstances.add(fakeRoot);
-        }
-
         // visit MXML
         IClassDefinition cdef = node.getClassDefinition();
         IASEmitter asEmitter = ((IMXMLBlockWalker) getMXMLWalker())
@@ -124,9 +110,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
 
         emitHeader(node);
 
-        boolean indent = !isMainFile || propertySpecifierNodes == null;
-
-        emitClassDeclStart(cname, node, indent);
+        emitClassDeclStart(cname, node, false);
 
         emitPropertyDecls();
 
@@ -302,89 +286,94 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
     protected void emitMXMLDescriptorFuncs(String cname)
     {
         // top level is 'mxmlContent', skip it...
-        if (descriptorTree.size() == 0)
-            return;
-
-        MXMLDescriptorSpecifier root = descriptorTree.get(0);
-        root.isTopNodeInMainFile = isMainFile;
-
-        writeNewline("/**");
-        writeNewline(" * @override");
-        writeNewline(" * @this {" + cname + "}");
-        writeNewline(" * @return {Array} the Array of UI element descriptors.");
-        writeNewline(" */");
-        writeNewline(cname + ".prototype.get_MXMLDescriptor = function()");
-        indentPush();
-        writeNewline("{");
-        writeNewline("if (this.mxmldd == undefined)");
-        indentPush();
-        writeNewline("{");
-        writeNewline("/** @type {Array} */");
-        writeNewline("var arr = goog.base(this, 'get_MXMLDescriptor');");
-        writeNewline("/** @type {Array} */");
-        indentPop();
-        indentPop();
-        writeNewline("var data = [");
-
-        if (!isMainFile)
+        if (descriptorTree.size() > 0)
+        {
+            MXMLDescriptorSpecifier root = descriptorTree.get(0);
+            root.isTopNode = false;
+    
+            writeNewline("/**");
+            writeNewline(" * @override");
+            writeNewline(" * @this {" + cname + "}");
+            writeNewline(" * @return {Array} the Array of UI element descriptors.");
+            writeNewline(" */");
+            writeNewline(cname + ".prototype.get_MXMLDescriptor = function()");
+            indentPush();
+            writeNewline("{");
+            writeNewline("if (this.mxmldd == undefined)");
+            indentPush();
+            writeNewline("{");
+            writeNewline("/** @type {Array} */");
+            writeNewline("var arr = goog.base(this, 'get_MXMLDescriptor');");
+            writeNewline("/** @type {Array} */");
+            indentPop();
+            indentPop();
+            writeNewline("var data = [");
+    
             writeNewline(root.output(true));
-
-        indentPush();
-        writeNewline("];");
-        indentPush();
-        writeNewline("");
-        indentPush();
-        writeNewline("if (arr)");
-        indentPop();
-        writeNewline("this.mxmldd = arr.concat(data);");
-        indentPush();
-        writeNewline("else");
-        indentPop();
-        indentPop();
-        writeNewline("this.mxmldd = data;");
-        writeNewline("}");
-        indentPop();
-        writeNewline("return this.mxmldd;");
-        writeNewline("};");
-        writeNewline();
-        writeNewline("/**");
-        writeNewline(" * @override");
-        writeNewline(" * @this {" + cname + "}");
-        writeNewline(" * @return {Array} the Array of UI element descriptors.");
-        writeNewline(" */");
-        writeNewline(cname + ".prototype.get_MXMLProperties = function()");
-        indentPush();
-        writeNewline("{");
-        writeNewline("if (this.mxmldp == undefined)");
-        indentPush();
-        writeNewline("{");
-        writeNewline("/** @type {Array} */");
-        writeNewline("var arr = goog.base(this, 'get_MXMLProperties');");
-        writeNewline("/** @type {Array} */");
-        indentPop();
-        indentPop();
-        writeNewline("var data = [");
-
-        if (isMainFile)
+    
+            indentPush();
+            writeNewline("];");
+            indentPush();
+            writeNewline("");
+            indentPush();
+            writeNewline("if (arr)");
+            indentPop();
+            writeNewline("this.mxmldd = arr.concat(data);");
+            indentPush();
+            writeNewline("else");
+            indentPop();
+            indentPop();
+            writeNewline("this.mxmldd = data;");
+            writeNewline("}");
+            indentPop();
+            writeNewline("return this.mxmldd;");
+            writeNewline("};");
+            writeNewline();
+        }
+        
+        if (propertiesTree.propertySpecifiers.size() > 0 ||
+                propertiesTree.eventSpecifiers.size() > 0)
+        {
+            writeNewline("/**");
+            writeNewline(" * @override");
+            writeNewline(" * @this {" + cname + "}");
+            writeNewline(" * @return {Array} the Array of UI element descriptors.");
+            writeNewline(" */");
+            writeNewline(cname + ".prototype.get_MXMLProperties = function()");
+            indentPush();
+            writeNewline("{");
+            writeNewline("if (this.mxmldp == undefined)");
+            indentPush();
+            writeNewline("{");
+            writeNewline("/** @type {Array} */");
+            writeNewline("var arr = goog.base(this, 'get_MXMLProperties');");
+            writeNewline("/** @type {Array} */");
+            indentPop();
+            indentPop();
+            writeNewline("var data = [");
+    
+            MXMLDescriptorSpecifier root = propertiesTree;
+            root.isTopNode = true;
             writeNewline(root.output(true));
-
-        indentPush();
-        writeNewline("];");
-        indentPush();
-        writeNewline("");
-        indentPush();
-        writeNewline("if (arr)");
-        indentPop();
-        writeNewline("this.mxmldp = arr.concat(data);");
-        indentPush();
-        writeNewline("else");
-        indentPop();
-        indentPop();
-        writeNewline("this.mxmldp = data;");
-        writeNewline("}");
-        indentPop();
-        writeNewline("return this.mxmldp;", false);
-        writeNewline("};");
+    
+            indentPush();
+            writeNewline("];");
+            indentPush();
+            writeNewline("");
+            indentPush();
+            writeNewline("if (arr)");
+            indentPop();
+            writeNewline("this.mxmldp = arr.concat(data);");
+            indentPush();
+            writeNewline("else");
+            indentPop();
+            indentPop();
+            writeNewline("this.mxmldp = data;");
+            writeNewline("}");
+            indentPop();
+            writeNewline("return this.mxmldp;", false);
+            writeNewline("};");
+        }
     }
 
     //--------------------------------------------------------------------------    
@@ -426,6 +415,8 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
 
         if (currentDescriptor != null)
             currentDescriptor.eventSpecifiers.add(eventSpecifier);
+        else  // in theory, if no currentdescriptor must be top tag event
+            propertiesTree.eventSpecifiers.add(eventSpecifier);
 
         events.add(eventSpecifier);
     }
@@ -451,8 +442,13 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
 
         if (currentPropertySpecifier != null)
             currentPropertySpecifier.propertySpecifiers.add(currentInstance);
-        else
+        else if (inMXMLContent)
             descriptorTree.add(currentInstance);
+        else
+        {
+            currentInstance.parent = propertiesTree;
+            propertiesTree.propertySpecifiers.add(currentInstance);
+        }
 
         instances.add(currentInstance);
 
@@ -497,10 +493,19 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
         currentPropertySpecifier.name = cdef.getQualifiedName();
         currentPropertySpecifier.parent = currentInstance;
 
+        boolean oldInMXMLContent = inMXMLContent;
+        if (currentPropertySpecifier.name.equals("mxmlContent"))
+            inMXMLContent = true;
+        
         if (currentInstance != null)
             currentInstance.propertySpecifiers.add(currentPropertySpecifier);
-        else
+        else if (inMXMLContent)
             descriptorTree.add(currentPropertySpecifier);
+        else
+        {
+            currentPropertySpecifier.parent = propertiesTree;
+            propertiesTree.propertySpecifiers.add(currentPropertySpecifier);
+        }
 
         boolean bypass = cnode != null && cnode instanceof IMXMLArrayNode;
 
@@ -511,6 +516,8 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
         getMXMLWalker().walk(cnode); // Array or Instance
 
         moveUp(bypass, false);
+        
+        inMXMLContent = oldInMXMLContent;
     }
 
     @Override
@@ -593,8 +600,15 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
         if (ps.valueNeedsQuotes)
             ps.value += ASEmitterTokens.SINGLE_QUOTE.getToken();
 
-        ps.value += node.getValue().toString();
-
+        String s = node.getValue().toString();
+        if (ps.valueNeedsQuotes)
+        {
+            // escape all single quotes found within the string
+            s = s.replace(ASEmitterTokens.SINGLE_QUOTE.getToken(), 
+                    "\\" + ASEmitterTokens.SINGLE_QUOTE.getToken());
+        }
+        ps.value += s;
+        
         if (ps.valueNeedsQuotes)
             ps.value += ASEmitterTokens.SINGLE_QUOTE.getToken();
     }


Mime
View raw message