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] - use setAttribute for assigning attributes in XML
Date Tue, 05 Jan 2016 16:34:50 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop c9de796f9 -> 91ba91d74


use setAttribute for assigning attributes in XML


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

Branch: refs/heads/develop
Commit: 91ba91d7451e8c595149e65116cdc9cca37c3fdb
Parents: c9de796
Author: Alex Harui <aharui@apache.org>
Authored: Tue Jan 5 08:34:44 2016 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Tue Jan 5 08:34:44 2016 -0800

----------------------------------------------------------------------
 .../js/flexjs/TestFlexJSGlobalClasses.java       |  8 ++++++++
 .../codegen/js/jx/BinaryOperatorEmitter.java     | 19 +++++++++++++++----
 2 files changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/91ba91d7/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 3b130f5..815d997 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
@@ -344,6 +344,14 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
     }
     
     @Test
+    public void testXMLSetAttribute()
+    {
+        IBinaryOperatorNode node = getBinaryNode("var a:XML = new XML(\"<top attr1='cat'><child
attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");a.@bar
= 'foo'");
+        asBlockWalker.visitBinaryOperator(node);
+        assertOut("a.setAttribute('bar', 'foo')");
+    }
+    
+    @Test
     public void testXMLSetChild()
     {
         IBinaryOperatorNode node = getBinaryNode("var a:XML = new XML(\"<top attr1='cat'><child
attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");a.foo
= a.child");

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/91ba91d7/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
index 38935e2..5b200de 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
@@ -29,6 +29,7 @@ import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens
 import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
 import org.apache.flex.compiler.internal.projects.FlexJSProject;
 import org.apache.flex.compiler.internal.tree.as.MemberAccessExpressionNode;
+import org.apache.flex.compiler.internal.tree.as.UnaryOperatorAtNode;
 import org.apache.flex.compiler.projects.ICompilerProject;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
@@ -88,8 +89,9 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
             {
                 IASNode lnode = leftSide.getChild(0);
                 IASNode rnode = leftSide.getChild(1);
-                IDefinition rnodeDef = ((IIdentifierNode) rnode)
-                        .resolve(getWalker().getProject());
+                IDefinition rnodeDef = (rnode instanceof IIdentifierNode) ? 
+                		((IIdentifierNode) rnode).resolve(getWalker().getProject()) :
+                		null;
                 if (lnode.getNodeID() == ASTNodeID.SuperID
                         && rnodeDef instanceof AccessorDefinition)
                 {
@@ -149,8 +151,17 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
                 	if (node.getNodeID() == ASTNodeID.Op_AssignId)
                 	{
 	                    getWalker().walk(xmlNode.getLeftOperandNode());
-	                    write(".setChild('");
-	                    getWalker().walk(xmlNode.getRightOperandNode());
+	                    IExpressionNode rightSide = xmlNode.getRightOperandNode();
+	                    if (rightSide instanceof UnaryOperatorAtNode)
+	                    {
+		                    write(".setAttribute('");
+		                    getWalker().walk(((UnaryOperatorAtNode)rightSide).getChild(0));
+	                    }
+	                    else
+	                    {
+		                    write(".setChild('");
+		                    getWalker().walk(rightSide);
+	                    }
 	                    write("', ");
 	                    getWalker().walk(node.getRightOperandNode());
 	                    write(ASEmitterTokens.PAREN_CLOSE);


Mime
View raw message