flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erikdebr...@apache.org
Subject [2/2] git commit: [flex-falcon] [refs/heads/develop] - FLEX-33887 "super.foo = value; " is now correctly translated to "goog.base(this, 'set_foo', value); "
Date Sat, 09 Nov 2013 01:00:04 GMT
FLEX-33887 "super.foo = value;" is now correctly translated to "goog.base(this, 'set_foo',
value);"

Test cases are added and one old test case is bypassed

Signed-off-by: Erik de Bruin <erik@ixsoftware.nl>


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

Branch: refs/heads/develop
Commit: 8e96bb9bc2bf6813f8bdc9bb68f9bce72c30ad6c
Parents: e2b5a13
Author: Erik de Bruin <erik@ixsoftware.nl>
Authored: Sat Nov 9 01:59:42 2013 +0100
Committer: Erik de Bruin <erik@ixsoftware.nl>
Committed: Sat Nov 9 01:59:42 2013 +0100

----------------------------------------------------------------------
 .../codegen/js/flexjs/TestFlexJSClass.java      | 45 ++++++++++++++++++++
 .../js/flexjs/TestFlexJSExpressions.java        | 14 ++++++
 .../codegen/js/flexjs/JSFlexJSEmitter.java      | 40 +++++++++++++++--
 3 files changed, 96 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8e96bb9b/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 ca98a71..d710904 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
@@ -76,6 +76,51 @@ public class TestFlexJSClass extends TestGoogClass
         assertOut(expected);
     }
 
+    @Test
+    public void testMethod_override()
+    {
+        IClassNode node = getClassNode("public class B {public function B() {}; override
public function foo():void {};}");
+        asBlockWalker.visitClass(node);
+        String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n/**\n
* @expose\n * @override\n */\norg.apache.flex.B.prototype.foo = function() {\n};";
+        assertOut(expected);
+    }
+
+    @Test
+    public void testMethod_overrideWithFunctionBody()
+    {
+        IClassNode node = getClassNode("public class B {public function B() {}; override
public function foo(value:Object):void {baz = ''};}");
+        asBlockWalker.visitClass(node);
+        String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n/**\n
* @expose\n * @param {Object} value\n * @override\n */\norg.apache.flex.B.prototype.foo =
function(value) {\n\tbaz = '';\n};";
+        assertOut(expected);
+    }
+
+    @Test
+    public void testMethod_overrideSuperCall()
+    {
+        IClassNode node = getClassNode("public class B {public function B() {}; override
public function foo():void {super.foo();};}");
+        asBlockWalker.visitClass(node);
+        String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n/**\n
* @expose\n * @override\n */\norg.apache.flex.B.prototype.foo = function() {\n\tgoog.base(this,
'foo');\n};";
+        assertOut(expected);
+    }
+
+    @Test
+    public void testMethod_setterCall()
+    {
+        IClassNode node = getClassNode("public class B {public function B() {}; public function
set baz(value:Object):void {}; public function set foo(value:Object):void {baz = value;};}");
+        asBlockWalker.visitClass(node);
+        String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n/**\n
* @expose\n * @param {Object} value\n */\norg.apache.flex.B.prototype.set_baz = function(value)
{\n};\n\n/**\n * @expose\n * @param {Object} value\n */\norg.apache.flex.B.prototype.set_foo
= function(value) {\n\tthis.set_baz(value);\n};";
+        assertOut(expected);
+    }
+
+    @Test
+    public void testMethod_overrideSetterSuperCall()
+    {
+        IClassNode node = getClassNode("public class B {public function B() {}; override
public function set foo(value:Object):void {super.foo = value;};}");
+        asBlockWalker.visitClass(node);
+        String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n/**\n
* @expose\n * @param {Object} value\n * @override\n */\norg.apache.flex.B.prototype.set_foo
= function(value) {\n\tgoog.base(this, 'set_foo', value);\n};";
+        assertOut(expected);
+    }
+
     @Override
     @Test
     public void testAccessors()

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8e96bb9b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
index 8c15248..6057016 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
@@ -29,6 +29,8 @@ import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
 import org.apache.flex.compiler.tree.as.IClassNode;
 import org.apache.flex.compiler.tree.as.IFileNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -37,6 +39,18 @@ import org.junit.Test;
 public class TestFlexJSExpressions extends TestGoogExpressions
 {
 
+    @Ignore
+    @Override
+    @Test
+    public void testVisitLanguageIdentifierNode_SuperMember()
+    {
+        // (erikdebruin) this test doesn't make sense in FlexJS context
+        IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getNode(
+                "if (a) super.foo;", IMemberAccessExpressionNode.class);
+        asBlockWalker.visitMemberAccessExpression(node);
+        assertOut("super.foo");
+    }
+
     @Override
     @Test
     public void testVisitLanguageIdentifierNode_SuperMethod_1()

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8e96bb9b/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 49ab7e0..5edb70b 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
@@ -606,7 +606,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
                         .getAncestorOfType(IFunctionNode.class);
         }
 
-        if (fnode.isConstructor() && !hasSuperClass(fnode))
+        if (fnode != null && fnode.isConstructor() && !hasSuperClass(fnode))
             return;
 
         write(JSGoogEmitterTokens.GOOG_BASE);
@@ -638,6 +638,23 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
 
             writeArguments = (anodes != null && anodes.length > 0);
         }
+        else if (fnode == null && node instanceof BinaryOperatorAssignmentNode)
+        {
+            BinaryOperatorAssignmentNode bnode = (BinaryOperatorAssignmentNode) node;
+            
+            IFunctionNode pnode = (IFunctionNode) bnode.getAncestorOfType(IFunctionNode.class);
+            
+            if (pnode.getNodeID() == ASTNodeID.SetterID)
+            {
+                writeToken(ASEmitterTokens.COMMA);
+                write(ASEmitterTokens.SINGLE_QUOTE);
+                writeGetSetPrefix(false);
+                getWalker().walk(bnode.getLeftOperandNode());
+                write(ASEmitterTokens.SINGLE_QUOTE);
+                writeToken(ASEmitterTokens.COMMA);
+                getWalker().walk(bnode.getRightOperandNode());
+            }
+        }
 
         if (writeArguments)
         {
@@ -728,6 +745,15 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
                 def = ((IIdentifierNode) property).resolve(getWalker()
                         .getProject());
 
+            boolean isSuper = false;
+            if (leftSide.getNodeID() == ASTNodeID.MemberAccessExpressionID)
+            {
+                IASNode cnode = leftSide.getChild(0);
+                ASTNodeID cId = cnode.getNodeID();
+
+                isSuper = cId == ASTNodeID.SuperID;
+            }
+
             String op = node.getOperator().getOperatorText();
             boolean isAssignment = !(op.contains("==") || !op.contains("="));
 
@@ -735,6 +761,10 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
             {
                 getWalker().walk(leftSide);
             }
+            else if (isSuper) 
+            {
+                emitSuperCall(node, "");
+            }
             else
             {
                 if (ASNodeUtils.hasParenOpen(node))
@@ -773,8 +803,11 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
             if (!(leftNode instanceof ILanguageIdentifierNode && ((ILanguageIdentifierNode)
leftNode)
                         .getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.THIS))
             {
-                getWalker().walk(node.getLeftOperandNode());
-                write(node.getOperator().getOperatorText());
+                if (leftNode.getNodeID() != ASTNodeID.SuperID)
+                {
+                    getWalker().walk(node.getLeftOperandNode());
+                    write(node.getOperator().getOperatorText());
+                }
             }
             else
             {
@@ -783,6 +816,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
             }
         
         }
+        
         getWalker().walk(node.getRightOperandNode());
     }
 


Mime
View raw message