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 2013/10/08 23:50:08 UTC

[08/14] git commit: [flex-falcon] [refs/heads/develop] - handle properties of type Vector or Array that don't have explicit fx:Vector or fx:Array subtags

handle properties of type Vector or Array that don't have explicit fx:Vector or fx:Array subtags


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

Branch: refs/heads/develop
Commit: c5ea8ecb8aea4e2b2097a35de9b8cb961c493499
Parents: 838cbbe
Author: Alex Harui <ah...@apache.org>
Authored: Wed Oct 2 20:52:57 2013 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Tue Oct 8 13:50:58 2013 -0700

----------------------------------------------------------------------
 .../tree/mxml/MXMLPropertySpecifierNode.java    | 91 +++++++++++++++++++-
 1 file changed, 89 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c5ea8ecb/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLPropertySpecifierNode.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLPropertySpecifierNode.java b/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLPropertySpecifierNode.java
index 3815d94..5ffd3aa 100644
--- a/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLPropertySpecifierNode.java
+++ b/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLPropertySpecifierNode.java
@@ -19,6 +19,7 @@
 
 package org.apache.flex.compiler.internal.tree.mxml;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.EnumSet;
 import java.util.List;
@@ -36,6 +37,7 @@ import org.apache.flex.compiler.internal.projects.FlexProject;
 import org.apache.flex.compiler.internal.scopes.ASScope;
 import org.apache.flex.compiler.internal.scopes.MXMLFileScope;
 import org.apache.flex.compiler.internal.tree.as.NodeBase;
+import org.apache.flex.compiler.internal.tree.mxml.MXMLNodeBase.MXMLNodeInfo;
 import org.apache.flex.compiler.mxml.IMXMLTagAttributeData;
 import org.apache.flex.compiler.mxml.IMXMLTagData;
 import org.apache.flex.compiler.mxml.IMXMLTextData;
@@ -257,6 +259,59 @@ class MXMLPropertySpecifierNode extends MXMLSpecifierNodeBase implements IMXMLPr
     }
 
     /**
+     * This override makes sure that array and vectors have a child tag
+     * of fx:Array or fx:Vector, or fakes that condition.
+     */
+    @Override
+    protected void initializeFromTag(MXMLTreeBuilder builder, IMXMLTagData tag)
+    {
+        MXMLNodeInfo info = createNodeInfo(builder);
+        
+        String propertyTypeName = getPropertyTypeName(builder);
+
+        if (propertyTypeName.contains(IASLanguageConstants.Vector + ".<") ||
+                propertyTypeName.equals(IASLanguageConstants.Array))
+        {
+            // Process each content unit.
+            for (IMXMLUnitData unit = tag.getFirstChildUnit(); unit != null; unit = unit.getNextSiblingUnit())
+            {
+                if (unit instanceof IMXMLTagData)
+                {
+                    IMXMLTagData unitTag = (IMXMLTagData)unit;
+                    IDefinition definition = builder.getFileScope().resolveTagToDefinition(unitTag);
+                    if (propertyTypeName.contains(IASLanguageConstants.Vector + ".<") &&
+                            !definition.getQualifiedName().contains(IASLanguageConstants.Vector + ".<"))
+                    {
+                        initializeDefaultProperty(builder, (IVariableDefinition)getDefinition(), 
+                                getListOfUnits(tag));
+                        return;
+                    }
+                    else if (propertyTypeName.equals(IASLanguageConstants.Array) &&
+                            !definition.getQualifiedName().equals(IASLanguageConstants.Array))
+                    {
+                        initializeDefaultProperty(builder, (IVariableDefinition)getDefinition(), 
+                                getListOfUnits(tag));
+                        return;                        
+                    }
+                }
+            }
+        }
+        super.initializeFromTag(builder, tag);
+    }
+    
+    List<IMXMLUnitData> getListOfUnits(IMXMLTagData tag)
+    {
+        ArrayList<IMXMLUnitData> list = new ArrayList<IMXMLUnitData>();
+        
+        // Process each content unit.
+        for (IMXMLUnitData unit = tag.getFirstChildUnit(); unit != null; unit = unit.getNextSiblingUnit())
+        {
+            list.add(unit);
+        }
+        return list;
+    }
+    
+    /**
      * This override handles text specifying a default property.
      */
     @Override
@@ -298,14 +353,16 @@ class MXMLPropertySpecifierNode extends MXMLSpecifierNodeBase implements IMXMLPr
             ((MXMLDeferredInstanceNode)instanceNode).initializeDefaultProperty(
                     builder, defaultPropertyDefinition, contentUnits);
         }
-        else if (propertyTypeName.equals(IASLanguageConstants.Array))
+        else if (propertyTypeName.equals(IASLanguageConstants.Array) && 
+                oneChildIsNotArray(builder, contentUnits))
         {
             // Create an implicit array node.
             instanceNode = new MXMLArrayNode(this);
             ((MXMLArrayNode)instanceNode).initializeDefaultProperty(
                     builder, defaultPropertyDefinition, contentUnits);
         }
-        else if (propertyTypeName.contains(IASLanguageConstants.Vector + ".<"))
+        else if (propertyTypeName.contains(IASLanguageConstants.Vector + ".<") && 
+                oneChildIsNotVector(builder, contentUnits))
         {
             // Create an implicit array node.
             instanceNode = new MXMLVectorNode(this);
@@ -325,6 +382,36 @@ class MXMLPropertySpecifierNode extends MXMLSpecifierNodeBase implements IMXMLPr
             }
         }
     }
+    
+    private boolean oneChildIsNotArray(MXMLTreeBuilder builder, List<IMXMLUnitData> contentUnits) 
+    {
+        if (contentUnits.size() != 1)
+            return true;
+        
+        if (contentUnits.get(0) instanceof IMXMLTagData)
+        {
+            IMXMLTagData tag = (IMXMLTagData)contentUnits.get(0);
+            IDefinition definition = builder.getFileScope().resolveTagToDefinition(tag);
+            if (definition.getQualifiedName().equals(IASLanguageConstants.Array))
+                return false;
+        }
+        return true;
+    }
+
+    private boolean oneChildIsNotVector(MXMLTreeBuilder builder, List<IMXMLUnitData> contentUnits) 
+    {
+        if (contentUnits.size() != 1)
+            return true;
+        
+        if (contentUnits.get(0) instanceof IMXMLTagData)
+        {
+            IMXMLTagData tag = (IMXMLTagData)contentUnits.get(0);
+            IDefinition definition = builder.getFileScope().resolveTagToDefinition(tag);
+            if (definition.getQualifiedName().contains(IASLanguageConstants.Vector + ".<"))
+                return false;
+        }
+        return true;
+    }
 
     /**
      * This override handles a child tag in a property tag, such as