flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cd...@apache.org
Subject [07/18] git commit: [flex-falcon] [refs/heads/feature/maven-migration] - initial support for QName and Namespace
Date Sat, 12 Mar 2016 12:11:22 GMT
initial support for QName and Namespace


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

Branch: refs/heads/feature/maven-migration
Commit: 92d2b983ad00b8d8c68490afe0d66bc66c6687cf
Parents: 8e27013
Author: Alex Harui <aharui@apache.org>
Authored: Thu Mar 10 19:27:09 2016 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Thu Mar 10 19:32:14 2016 -0800

----------------------------------------------------------------------
 .../js/flexjs/TestFlexJSGlobalClasses.java      | 34 +++++-------
 .../internal/codegen/as/ASBlockWalker.java      |  1 +
 .../codegen/js/flexjs/JSFlexJSEmitter.java      | 21 ++++++++
 .../codegen/js/jx/MemberAccessEmitter.java      | 55 ++++++++++++++++++++
 .../codegen/js/jx/PackageHeaderEmitter.java     |  5 +-
 .../internal/projects/FlexJSProject.java        | 12 ++++-
 6 files changed, 105 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/92d2b983/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
index a3a50c1..96a9a0a 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
@@ -519,60 +519,52 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
         assertOut("var foreachiter0_target = a;\nfor (var foreachiter0 in foreachiter0_target.elementNames())
\n{\nvar p = foreachiter0_target.child(foreachiter0);\n\n  var /** @type {number} */ i = p.length();}\n");
     }
     
-    @Ignore
+    @Test
     public void testNamespaceNoArg()
     {
         IVariableNode node = getVariable("var a:Namespace = new Namespace();");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = new Array(['Hello', 'World'])");
+        assertOut("var /** @type {Namespace} */ a = new Namespace()");
     }
     
-    @Ignore
+    @Test
     public void testNamespaceOneArg()
     {
         IVariableNode node = getVariable("var a:Namespace = new Namespace('foo');");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = new Array(['Hello', 'World'])");
+        assertOut("var /** @type {Namespace} */ a = new Namespace('foo')");
     }
     
-    @Ignore
+    @Test
     public void testNamespaceTwoArg()
     {
         IVariableNode node = getVariable("var a:Namespace = new Namespace('foo', 'bar');");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = new Array(['Hello', 'World'])");
+        assertOut("var /** @type {Namespace} */ a = new Namespace('foo', 'bar')");
     }
-    
-    @Ignore
-    public void testNamespaceThreeArg()
-    {
-        IVariableNode node = getVariable("var a:Namespace = new Namespace('foo', 'bar', 'baz');");
-        asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = new Array(['Hello', 'World'])");
-    }
-    
-    @Ignore
+        
+    @Test
     public void testQNameNoArg()
     {
         IVariableNode node = getVariable("var a:QName = new QName();");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = new Array(['Hello', 'World'])");
+        assertOut("var /** @type {QName} */ a = new QName()");
     }
     
-    @Ignore
+    @Test
     public void testQNameTwoArg()
     {
         IVariableNode node = getVariable("var a:QName = new QName(new Namespace('foo'), 'bar');");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = new Array(['Hello', 'World'])");
+        assertOut("var /** @type {QName} */ a = new QName(new Namespace('foo'), 'bar')");
     }
 
-    @Ignore
+    @Test
     public void testQNameOneArg()
     {
         IVariableNode node = getVariable("var a:QName = new QName(new QName(new Namespace('foo'),
'bar'));");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {Array} */ a = new Array(['Hello', 'World'])");
+        assertOut("var /** @type {QName} */ a = new QName(new QName(new Namespace('foo'),
'bar'))");
     }
     
     

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/92d2b983/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBlockWalker.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBlockWalker.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBlockWalker.java
index d31ea74..aa29f4d 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBlockWalker.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBlockWalker.java
@@ -201,6 +201,7 @@ public class ASBlockWalker implements IASBlockVisitor, IASBlockWalker
                     isAllowedAfterPackage = pnode instanceof IInterfaceNode
                         || pnode instanceof IClassNode
                         || pnode instanceof IFunctionNode
+                        || pnode instanceof INamespaceNode
                         || pnode instanceof IVariableNode;
                 }
                 if(isPackage || isAllowedAfterPackage)

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/92d2b983/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 de50ace..d4325a7 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
@@ -25,6 +25,7 @@ import java.util.List;
 
 import org.apache.flex.compiler.codegen.js.flexjs.IJSFlexJSEmitter;
 import org.apache.flex.compiler.codegen.js.goog.IJSGoogDocEmitter;
+import org.apache.flex.compiler.constants.IASLanguageConstants;
 import org.apache.flex.compiler.definitions.IClassDefinition;
 import org.apache.flex.compiler.definitions.IDefinition;
 import org.apache.flex.compiler.definitions.IPackageDefinition;
@@ -83,6 +84,7 @@ import org.apache.flex.compiler.tree.as.IInterfaceNode;
 import org.apache.flex.compiler.tree.as.ILiteralContainerNode;
 import org.apache.flex.compiler.tree.as.ILiteralNode;
 import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
+import org.apache.flex.compiler.tree.as.INamespaceNode;
 import org.apache.flex.compiler.tree.as.IPackageNode;
 import org.apache.flex.compiler.tree.as.IScopedNode;
 import org.apache.flex.compiler.tree.as.ISetterNode;
@@ -317,6 +319,20 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
             writeToken(ASEmitterTokens.VAR);
         }
     }
+    
+    @Override
+    public void emitNamespace(INamespaceNode node)
+    {
+        write(formatQualifiedName(node.getName()));
+        write(ASEmitterTokens.SPACE);
+        writeToken(ASEmitterTokens.EQUAL);
+        writeToken(ASEmitterTokens.NEW);
+        write(IASLanguageConstants.Namespace);
+        write(ASEmitterTokens.PAREN_OPEN);
+        getWalker().walk(node.getNamespaceURINode());
+        write(ASEmitterTokens.PAREN_CLOSE);
+        write(ASEmitterTokens.SEMICOLON);
+    }
 
     @Override
     public void emitMemberName(IDefinitionNode node)
@@ -397,6 +413,11 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
                 String className = ((IFunctionNode)pnode).getQualifiedName();
                 getModel().getInternalClasses().put(className, mainClassName + "." + className);
             }
+            else if (pnode instanceof INamespaceNode)
+            {
+                String className = ((INamespaceNode)pnode).getQualifiedName();
+                getModel().getInternalClasses().put(className, mainClassName + "." + className);
+            }
             else if (pnode instanceof IVariableNode)
             {
                 String className = ((IVariableNode)pnode).getQualifiedName();

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/92d2b983/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
index 2fcc160..305b2e9 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
@@ -21,6 +21,7 @@ package org.apache.flex.compiler.internal.codegen.js.jx;
 
 import org.apache.flex.compiler.codegen.ISubEmitter;
 import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.constants.IASLanguageConstants;
 import org.apache.flex.compiler.definitions.IDefinition;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
@@ -31,7 +32,9 @@ import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
 import org.apache.flex.compiler.internal.projects.FlexJSProject;
 import org.apache.flex.compiler.internal.tree.as.FunctionCallNode;
 import org.apache.flex.compiler.internal.tree.as.GetterNode;
+import org.apache.flex.compiler.internal.tree.as.IdentifierNode;
 import org.apache.flex.compiler.internal.tree.as.MemberAccessExpressionNode;
+import org.apache.flex.compiler.internal.tree.as.NamespaceAccessExpressionNode;
 import org.apache.flex.compiler.projects.ICompilerProject;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
@@ -61,6 +64,11 @@ public class MemberAccessEmitter extends JSSubEmitter implements
         IASNode leftNode = node.getLeftOperandNode();
         IASNode rightNode = node.getRightOperandNode();
 
+        String leftName = "";
+        if (leftNode instanceof IdentifierNode)
+        {
+        	leftName = ((IdentifierNode)leftNode).getName();
+        }
     	JSFlexJSEmitter fjs = (JSFlexJSEmitter)getEmitter();
         IDefinition def = node.resolve(getProject());
         if (def == null)
@@ -136,6 +144,31 @@ public class MemberAccessEmitter extends JSSubEmitter implements
 	        		return;
 	        	}
         	}
+        	else if (rightNode instanceof NamespaceAccessExpressionNode)
+        	{
+        		// if you define a local variable with the same URI as a
+        		// namespace that defines a namespaced property
+        		// it doesn't resolve above so we handle it here
+        		NamespaceAccessExpressionNode naen = (NamespaceAccessExpressionNode)rightNode;
+        		IDefinition d = naen.getLeftOperandNode().resolve(getProject());
+        		IdentifierNode r = (IdentifierNode)(naen.getRightOperandNode());
+        		// output bracket access with QName
+        		writeLeftSide(node, leftNode, rightNode);
+        		write(ASEmitterTokens.SQUARE_OPEN);
+        		write(ASEmitterTokens.NEW);
+        		write(ASEmitterTokens.SPACE);
+        		write(IASLanguageConstants.QName);
+        		write(ASEmitterTokens.PAREN_OPEN);
+        		write(d.getBaseName());
+        		write(ASEmitterTokens.COMMA);
+        		write(ASEmitterTokens.SPACE);
+        		write(ASEmitterTokens.SINGLE_QUOTE);
+        		write(r.getName());
+        		write(ASEmitterTokens.SINGLE_QUOTE);
+        		write(ASEmitterTokens.PAREN_CLOSE);
+        		write(ASEmitterTokens.SQUARE_CLOSE);
+        		return;
+        	}
         }
         else if (fjs.isDateProperty(node))
         {
@@ -167,6 +200,28 @@ public class MemberAccessEmitter extends JSSubEmitter implements
         		return;
         	}
         }
+    	else if (rightNode instanceof NamespaceAccessExpressionNode)
+    	{
+    		NamespaceAccessExpressionNode naen = (NamespaceAccessExpressionNode)rightNode;
+    		IDefinition d = naen.getLeftOperandNode().resolve(getProject());
+    		IdentifierNode r = (IdentifierNode)(naen.getRightOperandNode());
+    		// output bracket access with QName
+    		writeLeftSide(node, leftNode, rightNode);
+    		write(ASEmitterTokens.SQUARE_OPEN);
+    		write(ASEmitterTokens.NEW);
+    		write(ASEmitterTokens.SPACE);
+    		write(IASLanguageConstants.QName);
+    		write(ASEmitterTokens.PAREN_OPEN);
+    		write(fjs.formatQualifiedName(d.getBaseName()));
+    		write(ASEmitterTokens.COMMA);
+    		write(ASEmitterTokens.SPACE);
+    		write(ASEmitterTokens.SINGLE_QUOTE);
+    		write(r.getName());
+    		write(ASEmitterTokens.SINGLE_QUOTE);
+    		write(ASEmitterTokens.PAREN_CLOSE);
+    		write(ASEmitterTokens.SQUARE_CLOSE);
+    		return;
+    	}
         boolean isStatic = false;
         if (def != null && def.isStatic())
             isStatic = true;

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/92d2b983/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/PackageHeaderEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/PackageHeaderEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/PackageHeaderEmitter.java
index d026e9c..64b560a 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/PackageHeaderEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/PackageHeaderEmitter.java
@@ -205,7 +205,10 @@ public class PackageHeaderEmitter extends JSSubEmitter implements
                     continue;
 
                 if (NativeUtils.isNative(imp))
-                    continue;
+                {
+                	if (!(imp.equals("QName") || imp.equals("Namespace")))
+                		continue;                	
+                }
 
                 if (writtenRequires.indexOf(imp) == -1)
                 {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/92d2b983/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java
b/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java
index ff668c6..bcae9ef 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java
@@ -100,7 +100,7 @@ public class FlexJSProject extends FlexProject
                             reqs.put(qname, dt);
                     }
                 }
-                else if (!isExternalLinkage(to))
+                else if (!isExternalLinkage(to) || qname.equals("Namespace"))
                     reqs.put(qname, dt);
             }
         }
@@ -165,6 +165,16 @@ public class FlexJSProject extends FlexProject
             return false;
         }
 
+        List<String> qnames;
+		try {
+			qnames = cu.getQualifiedNames();
+	        String qname = qnames.get(0);
+	        if (qname.equals("QName"))
+	        	return false;
+		} catch (InterruptedException e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		}
         try
         {
             return linkageChecker.isExternal(cu);


Mime
View raw message