flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject git commit: [flex-falcon] [refs/heads/develop] - need to handle case where there are statements in the constructor
Date Thu, 20 Aug 2015 17:20:08 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop 20e015890 -> 29b522018


need to handle case where there are statements in the constructor


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

Branch: refs/heads/develop
Commit: 29b522018ef13fd4ad3c9129c19946a9b63fee07
Parents: 20e0158
Author: Alex Harui <aharui@apache.org>
Authored: Thu Aug 20 10:20:00 2015 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Thu Aug 20 10:20:00 2015 -0700

----------------------------------------------------------------------
 .../codegen/js/flexjs/TestFlexJSClass.java         | 17 ++++++++++++++++-
 .../codegen/js/flexjs/TestFlexJSFieldMembers.java  |  8 ++++----
 .../flexjs/files/models/MyModel_result.js          |  3 ++-
 .../internal/codegen/as/ASBeforeNodeStrategy.java  |  3 +++
 .../codegen/js/flexjs/JSFlexJSEmitter.java         | 12 ++++++++++++
 .../internal/codegen/js/jx/ClassEmitter.java       |  6 +++++-
 6 files changed, 42 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/29b52201/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
index 8dacb04..24bff91 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
@@ -108,7 +108,7 @@ public class TestFlexJSClass extends TestGoogClass
     {
         IClassNode node = getClassNode("public class B {public function B() {}; public var
button:Button = new Button(); public function foo():String {return button.label;};}");
         asBlockWalker.visitClass(node);
-        String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n\nthis.button
= new spark.components.Button();};\n\n\n/**\n * @export\n * @type {spark.components.Button}\n
*/\norg.apache.flex.B.prototype.button;\n\n\n/**\n * @export\n * @return {string}\n */\norg.apache.flex.B.prototype.foo
= function() {\n  return this.button.label;\n};";
+        String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n\nthis.button
= new spark.components.Button();\n};\n\n\n/**\n * @export\n * @type {spark.components.Button}\n
*/\norg.apache.flex.B.prototype.button;\n\n\n/**\n * @export\n * @return {string}\n */\norg.apache.flex.B.prototype.foo
= function() {\n  return this.button.label;\n};";
         assertOut(expected);
     }
 
@@ -357,6 +357,21 @@ public class TestFlexJSClass extends TestGoogClass
         assertOut("/**\n * @constructor\n * @param {string} arg1\n * @param {number} arg2\n
*/\norg.apache.flex.A = function(arg1, arg2) {\n};");
     }
 
+    @Test
+    public void testConstructor_withBodyAndComplexInitializer()
+    {
+        IClassNode node = getClassNode("public class A {public function A(arg1:String, arg2:int)
{arg2 = arg2 + 2;} public var foo:Array = [];}");
+        asBlockWalker.visitClass(node);
+        assertOut("/**\n * @constructor\n * @param {string} arg1\n * @param {number} arg2\n
*/\norg.apache.flex.A = function(arg1, arg2) {\n  \n  this.foo = [];\n  arg2 = arg2 + 2;\n};\n\n\n/**\n
* @export\n * @type {Array}\n */\norg.apache.flex.A.prototype.foo;");
+    }
+
+    @Test
+    public void testConstructor_withImplicitSuperAndBodyAndComplexInitializer()
+    {
+        IClassNode node = getClassNode("public class A extends Button {public function A(arg1:String,
arg2:int) {arg2 = arg2 + 2;} public var foo:Array = [];}");
+        asBlockWalker.visitClass(node);
+        assertOut("/**\n * @constructor\n * @extends {spark.components.Button}\n * @param
{string} arg1\n * @param {number} arg2\n */\norg.apache.flex.A = function(arg1, arg2) {\n
 org.apache.flex.A.base(this, 'constructor', arg1, arg2);\n  \n  this.foo = [];\n  arg2 =
arg2 + 2;\n};\ngoog.inherits(org.apache.flex.A, spark.components.Button);\n\n\n/**\n * @export\n
* @type {Array}\n */\norg.apache.flex.A.prototype.foo;");
+    }
 
     protected IBackend createBackend()
     {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/29b52201/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
index e15eb9c..6b8b4fa 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
@@ -117,7 +117,7 @@ public class TestFlexJSFieldMembers extends TestGoogFieldMembers
     	IClassNode node = (IClassNode) getNode("protected var foo:Foo = new Foo('bar', 42);",
     			IClassNode.class, WRAP_LEVEL_CLASS);
         asBlockWalker.visitClass(node);
-        assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n\nthis.foo = new
Foo('bar', 42);};\n\n\n/**\n * @protected\n * @type {Foo}\n */\nFalconTest_A.prototype.foo;");
+        assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n\nthis.foo = new
Foo('bar', 42);\n};\n\n\n/**\n * @protected\n * @type {Foo}\n */\nFalconTest_A.prototype.foo;");
     }
 
     @Test
@@ -126,7 +126,7 @@ public class TestFlexJSFieldMembers extends TestGoogFieldMembers
     	IClassNode node = (IClassNode) getNode("protected var foo:Array = [ 'foo' ]",
         		IClassNode.class, WRAP_LEVEL_CLASS);
         asBlockWalker.visitClass(node);
-        assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n\nthis.foo = ['foo'];};\n\n\n/**\n
* @protected\n * @type {Array}\n */\nFalconTest_A.prototype.foo;");
+        assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n\nthis.foo = ['foo'];\n};\n\n\n/**\n
* @protected\n * @type {Array}\n */\nFalconTest_A.prototype.foo;");
     }
     
     @Test
@@ -135,7 +135,7 @@ public class TestFlexJSFieldMembers extends TestGoogFieldMembers
     	IClassNode node = (IClassNode) getNode("protected var foo:Object = { 'foo': 'bar' }",
         		IClassNode.class, WRAP_LEVEL_CLASS);
         asBlockWalker.visitClass(node);
-        assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n\nthis.foo = {'foo':'bar'};};\n\n\n/**\n
* @protected\n * @type {Object}\n */\nFalconTest_A.prototype.foo;");
+        assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n\nthis.foo = {'foo':'bar'};\n};\n\n\n/**\n
* @protected\n * @type {Object}\n */\nFalconTest_A.prototype.foo;");
     }
     
     @Test
@@ -144,7 +144,7 @@ public class TestFlexJSFieldMembers extends TestGoogFieldMembers
     	IClassNode node = (IClassNode) getNode("protected var foo:Number = parseFloat('1E2')",
         		IClassNode.class, WRAP_LEVEL_CLASS);
         asBlockWalker.visitClass(node);
-        assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n\nthis.foo = parseFloat('1E2');};\n\n\n/**\n
* @protected\n * @type {number}\n */\nFalconTest_A.prototype.foo;");
+        assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n\nthis.foo = parseFloat('1E2');\n};\n\n\n/**\n
* @protected\n * @type {number}\n */\nFalconTest_A.prototype.foo;");
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/29b52201/compiler.jx.tests/test-files/flexjs/files/models/MyModel_result.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/models/MyModel_result.js b/compiler.jx.tests/test-files/flexjs/files/models/MyModel_result.js
index 79b8c5d..7e3e371 100644
--- a/compiler.jx.tests/test-files/flexjs/files/models/MyModel_result.js
+++ b/compiler.jx.tests/test-files/flexjs/files/models/MyModel_result.js
@@ -31,7 +31,8 @@ models.MyModel = function() {
   models.MyModel.base(this, 'constructor');
 
 this._strings = ["AAPL", "ADBE", "GOOG", "MSFT", "YHOO"];
-this._cities = ["London", "Miami", "Paris", "Sydney", "Tokyo"];};
+this._cities = ["London", "Miami", "Paris", "Sydney", "Tokyo"];
+};
 goog.inherits(models.MyModel, org.apache.flex.events.EventDispatcher);
 
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/29b52201/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBeforeNodeStrategy.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBeforeNodeStrategy.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBeforeNodeStrategy.java
index d481573..f232bf3 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBeforeNodeStrategy.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBeforeNodeStrategy.java
@@ -21,8 +21,11 @@ package org.apache.flex.compiler.internal.codegen.as;
 
 import org.apache.flex.compiler.codegen.IEmitter;
 import org.apache.flex.compiler.codegen.as.IASEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.tree.as.FunctionNode;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IClassNode;
 import org.apache.flex.compiler.tree.as.IContainerNode;
 import org.apache.flex.compiler.tree.as.IContainerNode.ContainerType;
 import org.apache.flex.compiler.visitor.IASNodeStrategy;

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/29b52201/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
index ac83b58..eb301e5 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
@@ -182,6 +182,18 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
     }
 
     @Override
+    public void emitFunctionBlockHeader(IFunctionNode node)
+    {
+    	super.emitFunctionBlockHeader(node);
+    	if (node.isConstructor())
+    	{
+            IClassNode cnode = (IClassNode) node
+            .getAncestorOfType(IClassNode.class);
+            emitComplexInitializers(cnode);
+    	}
+    }
+    
+    @Override
     public void emitMemberKeyword(IDefinitionNode node)
     {
         if (node instanceof IFunctionNode)

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/29b52201/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
index 98f9c35..5112cba 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
@@ -144,6 +144,7 @@ public class ClassEmitter extends JSSubEmitter implements
     
     public void emitComplexInitializers(IClassNode node)
     {
+    	boolean wroteOne = false;
         IDefinitionNode[] dnodes = node.getAllMemberNodes();
         for (IDefinitionNode dnode : dnodes)
         {
@@ -161,8 +162,11 @@ public class ClassEmitter extends JSSubEmitter implements
                     writeToken(ASEmitterTokens.EQUAL);
                     getEmitter().getWalker().walk(vnode);
                     write(ASEmitterTokens.SEMICOLON);
+                    wroteOne = true;
                 }
             }
-        }    	
+        }    
+        if (wroteOne)
+        	writeNewline();
     }
 }


Mime
View raw message