more scenarios for custom namespaces

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

Branch: refs/heads/develop
Commit: 0b52f615f3c53f120605029888a6f57e5db12ab3
Parents: 15aef85
Author: Alex Harui <aha...@apache.org>
Authored: Tue Sep 20 11:58:34 2016 -0700
Committer: Alex Harui <aha...@apache.org>
Committed: Wed Sep 21 15:22:30 2016 -0700

----------------------------------------------------------------------
 .../codegen/js/flexjs/JSFlexJSEmitter.java        |  6 ++++++
 .../internal/codegen/js/jx/IdentifierEmitter.java | 18 ++++++++++++++++--
 .../codegen/js/flexjs/TestFlexJSAccessors.java    | 11 +++++++++++
 .../codegen/js/flexjs/TestFlexJSFieldMembers.java |  9 +++++++++
 4 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0b52f615/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
----------------------------------------------------------------------
diff --git 
a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
 
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
index 827d2c0..d9c7bb9 100644
--- 
a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
+++ 
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
@@ -61,6 +61,7 @@ import 
org.apache.flex.compiler.internal.codegen.js.jx.VarDeclarationEmitter;
 import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
 import org.apache.flex.compiler.internal.codegen.mxml.flexjs.MXMLFlexJSEmitter;
 import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
+import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
 import org.apache.flex.compiler.internal.projects.FlexJSProject;
 import org.apache.flex.compiler.internal.projects.FlexProject;
 import org.apache.flex.compiler.internal.tree.as.BinaryOperatorAsNode;
@@ -435,6 +436,11 @@ public class JSFlexJSEmitter extends JSGoogEmitter 
implements IJSFlexJSEmitter
                return false;
     }
     
+    public boolean isCustomNamespace(FunctionDefinition def)
+    {
+               return !def.getNamespaceReference().isLanguageNamespace();
+    }
+    
     @Override
     public void emitMemberName(IDefinitionNode node)
     {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0b52f615/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java
----------------------------------------------------------------------
diff --git 
a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java
 
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java
index 4d14bad..04a673e 100644
--- 
a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java
+++ 
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java
@@ -28,11 +28,13 @@ import 
org.apache.flex.compiler.definitions.IVariableDefinition;
 import 
org.apache.flex.compiler.definitions.IVariableDefinition.VariableClassification;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
 import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
 import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
 import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
 import org.apache.flex.compiler.internal.definitions.TypeDefinitionBase;
+import org.apache.flex.compiler.internal.tree.as.FunctionNode;
 import org.apache.flex.compiler.internal.tree.as.NonResolvingIdentifierNode;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
@@ -72,6 +74,11 @@ public class IdentifierEmitter extends JSSubEmitter 
implements
         boolean identifierIsPlainFunction = nodeDef instanceof 
FunctionDefinition
                 && !identifierIsAccessorFunction;
         boolean emitName = true;
+       JSFlexJSEmitter fjs = (JSFlexJSEmitter)getEmitter();
+       boolean isCustomNamespace = false;
+        if (nodeDef instanceof FunctionDefinition &&
+                 fjs.isCustomNamespace((FunctionDefinition)nodeDef))
+               isCustomNamespace = true;
 
         if (nodeDef != null && nodeDef.isStatic())
         {
@@ -168,7 +175,8 @@ public class IdentifierEmitter extends JSSubEmitter 
implements
                     endMapping(prevSibling);
                     startMapping(parentNode, prevSibling);
                 }
-                write(ASEmitterTokens.MEMBER_ACCESS);
+                if (!isCustomNamespace)
+                       write(ASEmitterTokens.MEMBER_ACCESS);
                 endMapping(parentNode);
             }
         }
@@ -208,7 +216,8 @@ public class IdentifierEmitter extends JSSubEmitter 
implements
                 else
                     write(ASEmitterTokens.THIS);
 
-                write(ASEmitterTokens.MEMBER_ACCESS);
+                if (!isCustomNamespace)
+                       write(ASEmitterTokens.MEMBER_ACCESS);
                 endMapping(node);
             }
 
@@ -279,6 +288,11 @@ public class IdentifierEmitter extends JSSubEmitter 
implements
                     write(getEmitter().formatQualifiedName(qname));
                 else if (nodeDef instanceof TypeDefinitionBase)
                     write(getEmitter().formatQualifiedName(qname));
+                else if (isCustomNamespace)
+                {
+                       String ns = 
((FunctionDefinition)nodeDef).getNamespaceReference().resolveAETNamespace(getProject()).getName();
+                       write("[\"" + ns + "::" + qname + "\"]");
+                }
                 else
                     write(qname);
                 endMapping(node);

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0b52f615/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessors.java
----------------------------------------------------------------------
diff --git 
a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessors.java
 
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessors.java
index 7083e3a..eeec770 100644
--- 
a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessors.java
+++ 
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessors.java
@@ -75,6 +75,17 @@ public class TestFlexJSAccessors extends ASTestBase
         assertOut(expected);
     }
 
+    @Test
+    public void testGetSetCustomNamespaceAccessor()
+    {
+        IClassNode node = (IClassNode) getNode(
+                "import flash.utils.flash_proxy;use namespace 
flash_proxy;public class B { public function B() {}; public function 
doStuff():void {var theLabel:String = label; label = theLabel;}; private var 
_label:String; flash_proxy function get label():String {return _label}; 
flash_proxy function set label(value:String):void {_label = value};}",
+                IClassNode.class, WRAP_LEVEL_PACKAGE);
+        asBlockWalker.visitClass(node);
+        String expected = "/**\n * @constructor\n */\nB = function() 
{\n};\n\n\n/**\n * @export\n */\nB.prototype.doStuff = function() {\n  var /** 
@type {string} */ theLabel = 
this[\"http://www.adobe.com/2006/actionscript/flash/proxy::label\"];\n  
this[\"http://www.adobe.com/2006/actionscript/flash/proxy::label\";] = 
theLabel;\n};\n\n\n/**\n * @private\n * @type {string}\n 
*/\nB.prototype._label;\n\n\nObject.defineProperties(B.prototype, /** @lends 
{B.prototype} */ {\n/** @export 
*/\n\"http://www.adobe.com/2006/actionscript/flash/proxy::label\": {\nget: /** 
@this {B} */ function() {\n  return this._label;\n},\nset: /** @this {B} */ 
function(value) {\n  this._label = value;\n}}}\n);";
+        assertOut(expected);
+    }
+
     @Override
     protected IBackend createBackend()
     {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0b52f615/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
----------------------------------------------------------------------
diff --git 
a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
 
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
index 76edcd1..16a1f9f 100644
--- 
a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
+++ 
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
@@ -171,6 +171,15 @@ public class TestFlexJSFieldMembers extends 
TestGoogFieldMembers
     }
     
     @Test
+    public void testField_withTypeValueCustomNamespaceStaticMethodCall()
+    {
+       IClassNode node = (IClassNode) getNode("import 
flash.utils.flash_proxy;use namespace flash_proxy;public static var foo:Object 
= initFoo(); flash_proxy static function initFoo():Object { return null; }",
+                       IClassNode.class, WRAP_LEVEL_CLASS);
+        asBlockWalker.visitClass(node);
+        assertOut("/**\n * @constructor\n */\nFalconTest_A = function() 
{\n};\n\n\n/**\n * @export\n * @type {Object}\n */\nFalconTest_A.foo = 
FalconTest_A[\"http://www.adobe.com/2006/actionscript/flash/proxy::initFoo\";]();\n\n\n/**\n
 * @export\n * @return {Object}\n 
*/\nFalconTest_A[\"http://www.adobe.com/2006/actionscript/flash/proxy::initFoo\";]
 = function() {\n  return null;\n};");
+    }
+    
+    @Test
     public void testStaticField_withTypeValueObjectLiteral()
     {
        IClassNode node = (IClassNode) getNode("static public var foo:Object = 
{ 'foo': 'bar' }",

Reply via email to