flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [1/2] git commit: [flex-falcon] [refs/heads/develop] - autogenerate missing getters or setters when overriding
Date Wed, 19 Aug 2015 21:51:44 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop 27a080dfe -> 20e015890


autogenerate missing getters or setters when overriding


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

Branch: refs/heads/develop
Commit: 57a8074cff98a022a4f20521c1f3e8403fb2ad6e
Parents: 27a080d
Author: Alex Harui <aharui@apache.org>
Authored: Tue Aug 18 13:33:21 2015 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Tue Aug 18 13:33:21 2015 -0700

----------------------------------------------------------------------
 .../js/flexjs/TestFlexJSAccessorMembers.java    |  26 +++-
 .../internal/codegen/js/jx/AccessorEmitter.java | 120 ++++++++++++++++++-
 2 files changed, 141 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/57a8074c/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessorMembers.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessorMembers.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessorMembers.java
index b073a9a..58769fe 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessorMembers.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessorMembers.java
@@ -64,12 +64,21 @@ public class TestFlexJSAccessorMembers extends TestGoogAccessorMembers
     @Test
     public void testGetAccessor_withNamespaceOverride()
     {
-    	IClassNode node = (IClassNode) getNode("public override function get foo():int{super.foo();
return -1;}",
-        		IClassNode.class, WRAP_LEVEL_CLASS);
+    	IClassNode node = (IClassNode) getNode("public class B extends A { public override function
get foo():int{return super.foo;} }; public class A {public function get foo():int {return
0;}} ",
+        		IClassNode.class, WRAP_LEVEL_PACKAGE);
         asBlockWalker.visitClass(node);
-        assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n};\n\n\nObject.defineProperties(FalconTest_A.prototype,
/** @lends {FalconTest_A.prototype} */ {\n/** @export */\nfoo: {\nget: /** @this {FalconTest_A}
*/ function() {\n  org.apache.flex.utils.Language.superGetter(FalconTest_A, this, 'foo');\n
 return -1;\n}}}\n);");
+        assertOut("/**\n * @constructor\n * @extends {A}\n */\nB = function() {\n  B.base(this,
'constructor');\n};\ngoog.inherits(B, A);\n\n\nObject.defineProperties(B.prototype, /** @lends
{B.prototype} */ {\n/** @export */\nfoo: {\nget: /** @this {B} */ function() {\n  return org.apache.flex.utils.Language.superGetter(B,
this, 'foo');\n}}}\n);");
     }
 
+    @Test
+    public void testGetAccessor_withGeneratedSetOverride()
+    {
+    	IClassNode node = (IClassNode) getNode("public class B extends A { public override function
get foo():int{return super.foo;} }; public class A { public function set foo(value:int):void{}
public function get foo():int {return 0;}}",
+        		IClassNode.class, WRAP_LEVEL_PACKAGE);
+        asBlockWalker.visitClass(node);
+        assertOut("/**\n * @constructor\n * @extends {A}\n */\nB = function() {\n  B.base(this,
'constructor');\n};\ngoog.inherits(B, A);\n\n\nObject.defineProperties(B.prototype, /** @lends
{B.prototype} */ {\n/** @export */\nfoo: {\nget: /** @this {B} */ function() {\n  return org.apache.flex.utils.Language.superGetter(B,
this, 'foo');\n},\nset: /** @this {B} */ function(value) {\norg.apache.flex.utils.Language.superSetter(B,
this, 'foo', value);\n}}}\n);");
+    }
+    
     @Override
     @Test
     public void testGetAccessor_withStatic()
@@ -114,7 +123,7 @@ public class TestFlexJSAccessorMembers extends TestGoogAccessorMembers
     @Test
     public void testSetAccessor_withNamespaceOverride()
     {
-    	IClassNode node = (IClassNode) getNode("public class B extends A { public override function
set foo(value:int):void {super.foo = value;} }; public class A extends B { public override
set foo(value:int):void{}}",
+    	IClassNode node = (IClassNode) getNode("public class B extends A { public override function
set foo(value:int):void {super.foo = value;} }; public class A { public function set foo(value:int):void{}}",
         		IClassNode.class, WRAP_LEVEL_PACKAGE);
         asBlockWalker.visitClass(node);
         assertOut("/**\n * @constructor\n * @extends {A}\n */\nB = function() {\n  B.base(this,
'constructor');\n};\ngoog.inherits(B, A);\n\n\nObject.defineProperties(B.prototype, /** @lends
{B.prototype} */ {\n/** @export */\nfoo: {\nset: /** @this {B} */ function(value) {\n  org.apache.flex.utils.Language.superSetter(B,
this, 'foo', value);\n}}}\n);");
@@ -130,6 +139,15 @@ public class TestFlexJSAccessorMembers extends TestGoogAccessorMembers
         assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n};Object.defineProperties(FalconTest_A,
/** @lends {FalconTest_A} */ {\n/** @export */\nfoo: {\nset: function(value) {\n}}}\n);");
     }
 
+    @Test
+    public void testSetAccessor_withGeneratedGetOverride()
+    {
+    	IClassNode node = (IClassNode) getNode("public class B extends A { public override function
set foo(value:int):void {super.foo = value;} }; public class A { public function set foo(value:int):void{}
public function get foo():int { return 0;}}",
+        		IClassNode.class, WRAP_LEVEL_PACKAGE);
+        asBlockWalker.visitClass(node);
+        assertOut("/**\n * @constructor\n * @extends {A}\n */\nB = function() {\n  B.base(this,
'constructor');\n};\ngoog.inherits(B, A);\n\n\nObject.defineProperties(B.prototype, /** @lends
{B.prototype} */ {\n/** @export */\nfoo: {\nget: /** @this {B} */ function() {\nreturn org.apache.flex.utils.Language.superGetter(B,
this, 'foo');\n},\nset: /** @this {B} */ function(value) {\n  org.apache.flex.utils.Language.superSetter(B,
this, 'foo', value);\n}}}\n);");
+    }
+    
     @Override
     protected IBackend createBackend()
     {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/57a8074c/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AccessorEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AccessorEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AccessorEmitter.java
index f75ce4d..35aabeb 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AccessorEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/AccessorEmitter.java
@@ -27,6 +27,7 @@ import org.apache.flex.compiler.codegen.js.IJSEmitter;
 import org.apache.flex.compiler.common.ASModifier;
 import org.apache.flex.compiler.common.IMetaInfo;
 import org.apache.flex.compiler.common.ModifiersSet;
+import org.apache.flex.compiler.definitions.IAccessorDefinition;
 import org.apache.flex.compiler.definitions.IClassDefinition;
 import org.apache.flex.compiler.definitions.IFunctionDefinition;
 import org.apache.flex.compiler.definitions.ITypeDefinition;
@@ -37,11 +38,17 @@ import org.apache.flex.compiler.internal.codegen.js.JSSessionModel.PropertyNodes
 import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
 import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSDocEmitter;
 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;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.semantics.SemanticUtils;
 import org.apache.flex.compiler.internal.tree.as.FunctionNode;
+import org.apache.flex.compiler.internal.tree.as.GetterNode;
 import org.apache.flex.compiler.internal.tree.as.SetterNode;
+import org.apache.flex.compiler.projects.ICompilerProject;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IAccessorNode;
+import org.apache.flex.compiler.tree.as.IClassNode;
 import org.apache.flex.compiler.tree.as.IGetterNode;
 import org.apache.flex.compiler.tree.as.ISetterNode;
 
@@ -100,6 +107,7 @@ public class AccessorEmitter extends JSSubEmitter implements
                 else
                     writeNewline(ASEmitterTokens.COMMA);
 
+                boolean wroteGetter = false;
                 PropertyNodes p = getModel().getPropertyMap().get(propName);
                 writeNewline("/** @export */");
                 write(propName);
@@ -126,10 +134,64 @@ public class AccessorEmitter extends JSSubEmitter implements
                     fjs.emitParameters(p.getter.getParameterNodes());
 
                     fjs.emitDefinePropertyFunction(p.getter);
+                    wroteGetter = true;
+                }
+                else if (p.setter != null && p.setter.getDefinition().isOverride())
+                {
+                	// see if there is a getter on a base class.  If so, we have to 
+                	// generate a call to the super from this class because 
+                	// Object.defineProperty doesn't allow overriding just the setter.
+                	// If there is no getter defineProp'd the property will seen as
+                	// write-only.
+                	IAccessorDefinition other = (IAccessorDefinition)SemanticUtils.resolveCorrespondingAccessor(p.setter.getDefinition(),
getProject());
+                	if (other != null)
+                	{
+                        write(ASEmitterTokens.GET);
+                        write(ASEmitterTokens.COLON);
+                        write(ASEmitterTokens.SPACE);
+                        write(JSDocEmitterTokens.JSDOC_OPEN);
+                        write(ASEmitterTokens.SPACE);
+                        write(ASEmitterTokens.ATSIGN);
+                        write(ASEmitterTokens.THIS);
+                        write(ASEmitterTokens.SPACE);
+                        write(ASEmitterTokens.BLOCK_OPEN);
+                        write(getEmitter().formatQualifiedName(qname));
+                        write(ASEmitterTokens.BLOCK_CLOSE);
+                        write(ASEmitterTokens.SPACE);
+                        write(JSDocEmitterTokens.JSDOC_CLOSE);
+                        write(ASEmitterTokens.SPACE);
+                        write(ASEmitterTokens.FUNCTION);
+                        write(ASEmitterTokens.PAREN_OPEN);
+                        write(ASEmitterTokens.PAREN_CLOSE);
+                        write(ASEmitterTokens.SPACE);
+                        writeNewline(ASEmitterTokens.BLOCK_OPEN);
+                        
+                        ICompilerProject project = this.getProject();
+                        if (project instanceof FlexJSProject)
+                        	((FlexJSProject)project).needLanguage = true;
+                        // setter is handled in binaryOperator
+                        write(ASEmitterTokens.RETURN);
+                        write(ASEmitterTokens.SPACE);
+                        write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
+                        write(ASEmitterTokens.MEMBER_ACCESS);
+                        write(JSFlexJSEmitterTokens.SUPERGETTER);
+                        write(ASEmitterTokens.PAREN_OPEN);
+                        write(getEmitter().formatQualifiedName(qname));
+                        writeToken(ASEmitterTokens.COMMA);
+                        write(ASEmitterTokens.THIS);
+                        writeToken(ASEmitterTokens.COMMA);
+                        write(ASEmitterTokens.SINGLE_QUOTE);
+                        write(propName);
+                        write(ASEmitterTokens.SINGLE_QUOTE);
+                        write(ASEmitterTokens.PAREN_CLOSE);
+                        writeNewline(ASEmitterTokens.SEMICOLON);
+                        write(ASEmitterTokens.BLOCK_CLOSE);
+                		wroteGetter = true;
+                	}
                 }
                 if (p.setter != null)
                 {
-                    if (p.getter != null)
+                    if (wroteGetter)
                         writeNewline(ASEmitterTokens.COMMA);
 
                     write(ASEmitterTokens.SET);
@@ -151,6 +213,62 @@ public class AccessorEmitter extends JSSubEmitter implements
 
                     fjs.emitDefinePropertyFunction(p.setter);
                 }
+                else if (p.getter != null && p.getter.getDefinition().isOverride())
+                {
+                	// see if there is a getter on a base class.  If so, we have to 
+                	// generate a call to the super from this class because 
+                	// Object.defineProperty doesn't allow overriding just the getter.
+                	// If there is no setter defineProp'd the property will seen as
+                	// read-only.
+                	IAccessorDefinition other = (IAccessorDefinition)SemanticUtils.resolveCorrespondingAccessor(p.getter.getDefinition(),
getProject());
+                	if (other != null)
+                	{
+                        if (wroteGetter)
+                            writeNewline(ASEmitterTokens.COMMA);
+
+                        write(ASEmitterTokens.SET);
+                        write(ASEmitterTokens.COLON);
+                        write(ASEmitterTokens.SPACE);
+                        write(JSDocEmitterTokens.JSDOC_OPEN);
+                        write(ASEmitterTokens.SPACE);
+                        write(ASEmitterTokens.ATSIGN);
+                        write(ASEmitterTokens.THIS);
+                        write(ASEmitterTokens.SPACE);
+                        write(ASEmitterTokens.BLOCK_OPEN);
+                        write(getEmitter().formatQualifiedName(qname));
+                        write(ASEmitterTokens.BLOCK_CLOSE);
+                        write(ASEmitterTokens.SPACE);
+                        write(JSDocEmitterTokens.JSDOC_CLOSE);
+                        write(ASEmitterTokens.SPACE);
+                        write(ASEmitterTokens.FUNCTION);
+                        write(ASEmitterTokens.PAREN_OPEN);
+                        write("value");
+                        write(ASEmitterTokens.PAREN_CLOSE);
+                        write(ASEmitterTokens.SPACE);
+                        writeNewline(ASEmitterTokens.BLOCK_OPEN);
+                        
+                        ICompilerProject project = this.getProject();
+                        if (project instanceof FlexJSProject)
+                        	((FlexJSProject)project).needLanguage = true;
+                        
+                        write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
+                        write(ASEmitterTokens.MEMBER_ACCESS);
+                        write(JSFlexJSEmitterTokens.SUPERSETTER);
+                        write(ASEmitterTokens.PAREN_OPEN);
+                        write(getEmitter().formatQualifiedName(qname));
+                        writeToken(ASEmitterTokens.COMMA);
+                        write(ASEmitterTokens.THIS);
+                        writeToken(ASEmitterTokens.COMMA);
+                        write(ASEmitterTokens.SINGLE_QUOTE);
+                        write(propName);
+                        write(ASEmitterTokens.SINGLE_QUOTE);
+                        writeToken(ASEmitterTokens.COMMA);
+                        write("value");
+                        write(ASEmitterTokens.PAREN_CLOSE);
+                        writeNewline(ASEmitterTokens.SEMICOLON);
+                        write(ASEmitterTokens.BLOCK_CLOSE);
+                	}
+                }
                 write(ASEmitterTokens.BLOCK_CLOSE);
             }
             writeNewline(ASEmitterTokens.BLOCK_CLOSE);


Mime
View raw message