You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2014/11/10 19:05:48 UTC

[2/7] git commit: [flex-falcon] [refs/heads/develop] - handle binding and object nodes

handle binding and object nodes


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

Branch: refs/heads/develop
Commit: 5d2765d6289042cb5f11555f612ee553c8ae3926
Parents: 36c9111
Author: Alex Harui <ah...@apache.org>
Authored: Wed Nov 5 08:31:19 2014 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Wed Nov 5 08:31:57 2014 -0800

----------------------------------------------------------------------
 .../compiler/codegen/mxml/IMXMLEmitter.java     |  3 +
 .../internal/codegen/mxml/MXMLBlockWalker.java  | 22 ++++++
 .../internal/codegen/mxml/MXMLEmitter.java      | 16 +++++
 .../mxml/flexjs/MXMLDescriptorSpecifier.java    |  6 ++
 .../codegen/mxml/flexjs/MXMLFlexJSEmitter.java  | 72 +++++++++++++++++---
 .../internal/visitor/mxml/MXMLNodeSwitch.java   | 11 ++-
 .../visitor/mxml/IMXMLBlockVisitor.java         |  9 +++
 7 files changed, 127 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/5d2765d6/compiler.jx/src/org/apache/flex/compiler/codegen/mxml/IMXMLEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/codegen/mxml/IMXMLEmitter.java b/compiler.jx/src/org/apache/flex/compiler/codegen/mxml/IMXMLEmitter.java
index fe4c771..3d6b288 100644
--- a/compiler.jx/src/org/apache/flex/compiler/codegen/mxml/IMXMLEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/codegen/mxml/IMXMLEmitter.java
@@ -37,6 +37,7 @@ import org.apache.flex.compiler.tree.mxml.IMXMLIntNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLLiteralNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLMetadataNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLNumberNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLObjectNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLPropertySpecifierNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLStringNode;
@@ -92,6 +93,8 @@ public interface IMXMLEmitter extends IEmitter
 
     void emitNumber(IMXMLNumberNode node);
 
+    void emitObject(IMXMLObjectNode node);
+
     void emitString(IMXMLStringNode node);
 
     void emitUint(IMXMLUintNode node);

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/5d2765d6/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java
index a6cbb95..ed518de 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java
@@ -31,6 +31,7 @@ import org.apache.flex.compiler.projects.IASProject;
 import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IFileNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLArrayNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLBindingNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLBooleanNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLClassDefinitionNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLComponentNode;
@@ -49,6 +50,7 @@ import org.apache.flex.compiler.tree.mxml.IMXMLLiteralNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLMetadataNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLNumberNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLObjectNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLPropertySpecifierNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLStringNode;
@@ -418,6 +420,26 @@ public class MXMLBlockWalker implements IMXMLBlockVisitor, IMXMLBlockWalker
     }
     
     //--------------------------------------------------------------------------
+    
+    @Override
+    public void visitBinding(IMXMLBindingNode node)
+    {
+        debug("visitBinding()");
+        
+        System.out.println("skipping fx:Binding in " + node.getSourcePath() + ". This node should be encoded in the binding data.");
+    }
+    
+    //--------------------------------------------------------------------------
+    
+    @Override
+    public void visitObject(IMXMLObjectNode node)
+    {
+        debug("visitObject()");
+        
+        mxmlEmitter.emitObject(node);
+    }
+    
+    //--------------------------------------------------------------------------
 
     protected void debug(String message)
     {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/5d2765d6/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLEmitter.java
index ea4f4d0..fcf2597 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLEmitter.java
@@ -46,6 +46,7 @@ import org.apache.flex.compiler.tree.mxml.IMXMLLiteralNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLMetadataNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLNumberNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLObjectNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLPropertySpecifierNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLStringNode;
@@ -240,6 +241,21 @@ public class MXMLEmitter extends Emitter implements IMXMLEmitter
     //--------------------------------------------------------------------------
 
     @Override
+    public void emitObject(IMXMLObjectNode node)
+    {
+        final int len = node.getChildCount();
+        for (int i = 0; i < len; i++)
+        {
+            IASNode child = node.getChild(i);
+
+            getMXMLWalker().walk(child);
+
+            if (child instanceof IMXMLInstanceNode && i < len - 1)
+                writeNewline();
+        }
+    }
+
+    @Override
     public void emitArray(IMXMLArrayNode node)
     {
         final int len = node.getChildCount();

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/5d2765d6/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java
index d70ac27..ca24ac9 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java
@@ -76,6 +76,12 @@ public class MXMLDescriptorSpecifier extends MXMLNodeSpecifier
     public boolean hasArray;
 
     //---------------------------------
+    //    hasObject
+    //---------------------------------
+
+    public boolean hasObject;
+
+    //---------------------------------
     //    id
     //---------------------------------
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/5d2765d6/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
index 5956a7b..e76e0c1 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
@@ -70,6 +70,7 @@ import org.apache.flex.compiler.tree.mxml.IMXMLFactoryNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLInstanceNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLLiteralNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLObjectNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLPropertySpecifierNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLSpecifierNode;
@@ -101,6 +102,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
 
     private boolean inMXMLContent;
     private boolean inStatesOverride;
+    private boolean makingSimpleArray;
     
     private StringBuilder subDocuments = new StringBuilder();
     private ArrayList<String> subDocumentNames = new ArrayList<String>();
@@ -462,7 +464,11 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
                 writeNewline(ASEmitterTokens.NULL.getToken() + ASEmitterTokens.COMMA.getToken());
             
             s = bi.getDestinationString();
-            if (s.contains("."))
+            if (s == null)
+            {
+                writeNewline(ASEmitterTokens.NULL.getToken() + ASEmitterTokens.COMMA.getToken());            	
+            }
+            else if (s.contains("."))
             {
                 String[] parts = s.split("\\.");
                 write(ASEmitterTokens.SQUARE_OPEN.getToken() + ASEmitterTokens.DOUBLE_QUOTE.getToken() + 
@@ -480,10 +486,13 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
                         ASEmitterTokens.DOUBLE_QUOTE.getToken() + ASEmitterTokens.COMMA.getToken());
         }
         Set<Entry<Object, WatcherInfoBase>> watcherChains = bindingDataBase.getWatcherChains();
-        for (Entry<Object, WatcherInfoBase> entry : watcherChains)
+        if (watcherChains != null)
         {
-            WatcherInfoBase watcherInfoBase = entry.getValue();
-            encodeWatcher(watcherInfoBase);
+            for (Entry<Object, WatcherInfoBase> entry : watcherChains)
+            {
+                WatcherInfoBase watcherInfoBase = entry.getValue();
+                encodeWatcher(watcherInfoBase);
+            }
         }
         // add a trailing null for now so I don't have to have logic where the watcher figures out not to add
         // a comma
@@ -1322,15 +1331,17 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
             propertiesTree.propertySpecifiers.add(currentPropertySpecifier);
         }
 
-        boolean bypass = cnode != null && cnode instanceof IMXMLArrayNode;
+        boolean valueIsArray = cnode != null && cnode instanceof IMXMLArrayNode;
+        boolean valueIsObject = cnode != null && cnode instanceof IMXMLObjectNode;
 
-        currentPropertySpecifier.hasArray = bypass;
+        currentPropertySpecifier.hasArray = valueIsArray;
+        currentPropertySpecifier.hasObject = valueIsObject;
 
-        moveDown(bypass, null, currentPropertySpecifier);
+        moveDown(valueIsArray || valueIsObject, null, currentPropertySpecifier);
 
         getMXMLWalker().walk(cnode); // Array or Instance
 
-        moveUp(bypass, false);
+        moveUp(valueIsArray || valueIsObject, false);
         
         inMXMLContent = oldInMXMLContent;
     }
@@ -1384,15 +1395,57 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
     //--------------------------------------------------------------------------
 
     @Override
+    public void emitObject(IMXMLObjectNode node)
+    {
+        final int len = node.getChildCount();
+    	if (!makingSimpleArray)
+    	{
+            for (int i = 0; i < len; i++)
+            {
+                getMXMLWalker().walk(node.getChild(i)); // props in object
+            }    		
+    	}
+    	else
+    	{
+            MXMLDescriptorSpecifier ps = getCurrentDescriptor("ps");
+            ps.value = "{";	
+            for (int i = 0; i < len; i++)
+            {
+                IMXMLPropertySpecifierNode propName = (IMXMLPropertySpecifierNode)node.getChild(i);
+                ps.value += propName.getName() + ": ";	                
+                getMXMLWalker().walk(propName.getChild(0));
+                if (i < len - 1)
+                    ps.value += ", ";	                                	
+            }    		
+            ps.value += "}";	
+    	}
+    }
+    
+    @Override
     public void emitArray(IMXMLArrayNode node)
     {
         moveDown(false, null, null);
 
+        boolean isSimple = true;
         final int len = node.getChildCount();
         for (int i = 0; i < len; i++)
         {
+            final IASNode child = node.getChild(i);
+            ASTNodeID nodeID = child.getNodeID();
+            if (nodeID == ASTNodeID.MXMLArrayID || nodeID == ASTNodeID.MXMLInstanceID)
+            {
+                isSimple = false;
+                break;
+            }
+        }
+        boolean oldMakingSimpleArray = makingSimpleArray;
+        if (isSimple)
+        	makingSimpleArray = true;
+        for (int i = 0; i < len; i++)
+        {
             getMXMLWalker().walk(node.getChild(i)); // Instance
         }
+        makingSimpleArray = oldMakingSimpleArray;
 
         moveUp(false, false);
     }
@@ -1411,7 +1464,8 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
     public void emitLiteral(IMXMLLiteralNode node)
     {
         MXMLDescriptorSpecifier ps = getCurrentDescriptor("ps");
-        ps.value = "";
+        if (ps.value == null) // might be non-null if makingSimpleArray
+        	ps.value = "";
 
         if (ps.valueNeedsQuotes)
             ps.value += ASEmitterTokens.SINGLE_QUOTE.getToken();

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/5d2765d6/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java b/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
index 1c17717..9576e24 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
@@ -21,6 +21,7 @@ package org.apache.flex.compiler.internal.visitor.mxml;
 
 import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLArrayNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLBindingNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLBooleanNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLComponentNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLDataBindingNode;
@@ -37,6 +38,7 @@ import org.apache.flex.compiler.tree.mxml.IMXMLIntNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLLiteralNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLMetadataNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLNumberNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLObjectNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLPropertySpecifierNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLStringNode;
@@ -141,9 +143,13 @@ public class MXMLNodeSwitch implements IASNodeStrategy
         case MXMLDataBindingID:
             visitor.visitDatabinding((IMXMLDataBindingNode) node);
             break;
-            
-        case MXMLApplicationID:
         case MXMLBindingID:
+            visitor.visitBinding((IMXMLBindingNode) node);
+        	break;
+        case MXMLObjectID:
+            visitor.visitObject((IMXMLObjectNode) node);
+        	break;
+        case MXMLApplicationID:
         case MXMLBindingAttributeID:
         case MXMLClassID:
         case MXMLClassDefinitionID:
@@ -160,7 +166,6 @@ public class MXMLNodeSwitch implements IASNodeStrategy
         case MXMLModelID:
         case MXMLModelPropertyID:
         case MXMLModelRootID:
-        case MXMLObjectID:
         case MXMLPrivateID:
         case MXMLRegExpID:
         case MXMLRemoteObjectID:

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/5d2765d6/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java b/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java
index ab2b537..d6c45a8 100644
--- a/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java
+++ b/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java
@@ -20,6 +20,7 @@
 package org.apache.flex.compiler.visitor.mxml;
 
 import org.apache.flex.compiler.tree.mxml.IMXMLArrayNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLBindingNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLBooleanNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLClassDefinitionNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLComponentNode;
@@ -37,6 +38,7 @@ import org.apache.flex.compiler.tree.mxml.IMXMLIntNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLLiteralNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLMetadataNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLNumberNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLObjectNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLPropertySpecifierNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLStringNode;
@@ -126,4 +128,11 @@ public interface IMXMLBlockVisitor extends IBlockVisitor
     
     void visitDatabinding(IMXMLDataBindingNode node);
     
+    //--------------------------------------------------------------------------
+    
+    void visitBinding(IMXMLBindingNode node);
+    
+    //--------------------------------------------------------------------------
+    
+    void visitObject(IMXMLObjectNode node);
 }