flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gordonsm...@apache.org
Subject git commit: [flex-falcon] [refs/heads/develop] - Cleaned up MXMLTagAttributeData
Date Tue, 07 May 2013 23:19:01 GMT
Updated Branches:
  refs/heads/develop 310c37669 -> 3d1b6ca25


Cleaned up MXMLTagAttributeData


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

Branch: refs/heads/develop
Commit: 3d1b6ca25ac074b955bb808b11c0e40f9069566a
Parents: 310c376
Author: Gordon Smith <gordonsmith@apache.org>
Authored: Tue May 7 16:18:50 2013 -0700
Committer: Gordon Smith <gordonsmith@apache.org>
Committed: Tue May 7 16:18:50 2013 -0700

----------------------------------------------------------------------
 .../internal/mxml/MXMLTagAttributeData.java        |  445 ++++++++-------
 1 files changed, 223 insertions(+), 222 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3d1b6ca2/compiler/src/org/apache/flex/compiler/internal/mxml/MXMLTagAttributeData.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/internal/mxml/MXMLTagAttributeData.java
b/compiler/src/org/apache/flex/compiler/internal/mxml/MXMLTagAttributeData.java
index 4a6cd07..5fe7b92 100644
--- a/compiler/src/org/apache/flex/compiler/internal/mxml/MXMLTagAttributeData.java
+++ b/compiler/src/org/apache/flex/compiler/internal/mxml/MXMLTagAttributeData.java
@@ -36,15 +36,19 @@ import org.apache.flex.compiler.problems.ICompilerProblem;
 import org.apache.flex.compiler.problems.SyntaxProblem;
 
 /**
- * Encapsulation of a tag attribute in MXML
+ * Represents a tag attribute in MXML.
  */
-public class MXMLTagAttributeData extends SourceLocation implements
-        IMXMLTagAttributeData
+public class MXMLTagAttributeData extends SourceLocation implements IMXMLTagAttributeData
 {
     /**
      * Constructor.
+     * <p>
+     * Each attribute consumes three tokens:
+     * {@code TOKEN_NAME}, {@code TOKEN_EQUALS}, and {@code TOKEN_STRING}.
      */
-    MXMLTagAttributeData(MXMLToken nameToken, ListIterator<MXMLToken> tokenIterator,
MXMLDialect mxmlDialect, IFileSpecification spec, Collection<ICompilerProblem> problems)
+    MXMLTagAttributeData(MXMLToken nameToken, ListIterator<MXMLToken> tokenIterator,
+                         MXMLDialect mxmlDialect, IFileSpecification spec,
+                         Collection<ICompilerProblem> problems)
     {
         setStart(nameToken.getStart());
         setLine(nameToken.getLine());
@@ -62,7 +66,7 @@ public class MXMLTagAttributeData extends SourceLocation implements
 
         MXMLToken token = null;
 
-        // Look for "=" token
+        // Look for "=" token.
         if (tokenIterator.hasNext())
         {
             token = tokenIterator.next();
@@ -70,19 +74,17 @@ public class MXMLTagAttributeData extends SourceLocation implements
             if (token.getType() != MXMLTokenTypes.TOKEN_EQUALS)
             {
                 problems.add(new SyntaxProblem(token));
-                // need to restore the token position in the error
-                // case to handle error recovery otherwise the any
-                // trees after this won't be created
+                // Restore the token position for error recovery.
                 tokenIterator.previous();
                 return;
             }
 
-            valueStart = token.getEnd() + 1; //set the attributes start to right after the
equals until we have a value
+            valueStart = token.getEnd() + 1; // set the value's start to right after the
equals until we have a value
             valueLine = token.getLine();
             valueColumn = token.getColumn();
         }
 
-        // Look for value token
+        // Look for value token.
         while (tokenIterator.hasNext())
         {
             token = tokenIterator.next();
@@ -93,23 +95,16 @@ public class MXMLTagAttributeData extends SourceLocation implements
             else
             {
                 if (!MXMLToken.isTagEnd(token.getType()) && token.getType() != MXMLTokenTypes.TOKEN_NAME)
-                {
-                    // if we error out early, push back token - it may be start of next tag
-                    // this is "pre-falcon" repair that was lost
-                    tokenIterator.previous();
                     problems.add(new SyntaxProblem(token));
-                }
-                else
-                {
-                    tokenIterator.previous();
-                }
-                break;
+                // Restore the token position for error recovery.
+                tokenIterator.previous();
+                return;
             }
         }
     }
 
     /**
-     * The MXML tag that contains this attribute
+     * The MXML tag that contains this attribute.
      */
     protected IMXMLTagData parent;
 
@@ -124,6 +119,11 @@ public class MXMLTagAttributeData extends SourceLocation implements
     protected String attributeName;
 
     /**
+     * The name of this state, if it exists.
+     */
+    protected String stateName;
+
+    /**
      * The offset at which the optional state starts.
      */
     protected int stateStart;
@@ -134,25 +134,20 @@ public class MXMLTagAttributeData extends SourceLocation implements
     protected String valueIncludingDelimiters;
 
     /**
-     * The offset at which the attribute value starts
+     * The offset at which the attribute value starts.
      */
     protected int valueStart;
 
     /**
-     * The line on which the attribute value starts
+     * The line on which the attribute value starts.
      */
     protected int valueLine;
 
     /**
-     * The column at which the attribute value starts
+     * The column at which the attribute value starts.
      */
     protected int valueColumn;
 
-    /**
-     * The name of this state, if it exists
-     */
-    protected String stateName;
-
     //
     // Object overrides.
     //
@@ -166,75 +161,78 @@ public class MXMLTagAttributeData extends SourceLocation implements
         return sb.toString();
     }
 
-    /**
-     * For unit tests only.
-     * 
-     * @return name value and offsets in string form
-     */
-    public String buildAttributeString(boolean skipSrcPath)
-    {
-        StringBuilder sb = new StringBuilder();
-        sb.append(getName());
-        sb.append('=');
-        sb.append('"');
-        sb.append(getRawValue());
-        sb.append('"');
-
-        sb.append(' ');
-
-        // Display line, column, start, and end as "17:5 160-188".
-        if (skipSrcPath)
-            sb.append(getOffsetsString());
-        else
-            sb.append(super.toString());
-        return sb.toString();
-    }
-
     //
-    // Other methods
+    // IMXMLTagAttributeData implementations
     //
 
     @Override
+    public MXMLDialect getMXMLDialect()
+    {
+        return getParent().getParent().getMXMLDialect();
+    }
+
+    @Override
     public IMXMLTagData getParent()
     {
         return parent;
     }
+    
+    @Override
+    public String getName()
+    {
+        return attributeName;
+    }
 
-    /**
-     * Sets this attribute's tag.
-     * 
-     * @param parent MXML tag containing this attribute
-     */
-    public void setParent(IMXMLTagData parent)
+    @Override
+    public String getPrefix()
     {
-        this.parent = parent;
-        setSourcePath(parent.getSourcePath());
+        String name = getName();
+        int i = name.indexOf(':');
+        return i != -1 ? name.substring(0, i) : null;
     }
 
-    /**
-     * Adjust all associated offsets by the adjustment amount
-     * 
-     * @param offsetAdjustment amount to add to offsets
-     */
-    public void adjustOffsets(int offsetAdjustment)
+    @Override
+    public String getURI()
     {
-        if (attributeName != null)
+        if (uri == null)
         {
-            setStart(getAbsoluteStart() + offsetAdjustment);
-            setEnd(getAbsoluteEnd() + offsetAdjustment);
+            //walk up our chain to find the correct uri for our namespace.  first one wins
+            String prefix = getPrefix();
+            if (prefix == null)
+                return null;
+
+            IMXMLTagData lookingAt = parent;
+
+            // For attributes with prefix, parent's parent can be null if
+            // parent is the root tag 
+            while (lookingAt != null && lookingAt.getParent() != null)
+            {
+                PrefixMap depth = lookingAt.getParent().getPrefixMapForData(lookingAt);
+                if (depth != null && depth.containsPrefix(prefix))
+                {
+                    uri = depth.getNamespaceForPrefix(prefix);
+                    break;
+                }
+
+                lookingAt = lookingAt.getParentTag();
+            }
         }
 
-        if (hasValue())
-            valueStart += offsetAdjustment;
+        return uri;
+    }
 
-        if (stateName != null)
-            stateStart += offsetAdjustment;
+    @Override
+    public String getShortName()
+    {
+        String name = getName();
+        int i = name.indexOf(':');
+        return i != -1 ? name.substring(i + 1) : name;
     }
 
     @Override
-    public String getName()
+    public XMLName getXMLName()
     {
-        return attributeName;
+        return new XMLName(getURI(), getShortName());
     }
 
     @Override
@@ -243,14 +241,12 @@ public class MXMLTagAttributeData extends SourceLocation implements
         return stateName != null ? stateName : "";
     }
 
-    /**
-     * Checks whether this attribute is associated with a state.
-     * 
-     * @return True if a state association exists.
-     */
-    public boolean hasState()
+    @Override
+    public boolean isSpecialAttribute(String name)
     {
-        return stateName != null;
+        String languageURI = getMXMLDialect().getLanguageNamespace();
+
+        return getName().equals(name) && (getPrefix() == null || getURI() == languageURI);
     }
 
     @Override
@@ -259,16 +255,6 @@ public class MXMLTagAttributeData extends SourceLocation implements
         return getRawValue() != null;
     }
 
-    /**
-     * Get the attribute value as a String (with quotes)
-     * 
-     * @return attribute value (with quotes)
-     */
-    public String getValueWithQuotes()
-    {
-        return valueIncludingDelimiters;
-    }
-
     @Override
     public String getRawValue()
     {
@@ -297,46 +283,6 @@ public class MXMLTagAttributeData extends SourceLocation implements
         return EntityProcessor.parse(value, location, mxmlDialect, problems);
     }
 
-    public IFileSpecification getSource()
-    {
-        return getParent().getSource();
-    }
-
-    /**
-     * Get this unit's line number.
-     * 
-     * @return end offset
-     */
-    public final int getNameLine()
-    {
-        return getLine();
-    }
-
-    /**
-     * Get this unit's column number.
-     * 
-     * @return end offset
-     */
-    public final int getNameColumn()
-    {
-        return getColumn();
-    }
-
-    public int getNameStart()
-    {
-        return getAbsoluteStart();
-    }
-
-    /**
-     * Get this attribute's name's end offset
-     * 
-     * @return name end offset
-     */
-    public int getNameEnd()
-    {
-        return getAbsoluteStart() + attributeName.length();
-    }
-
     @Override
     public int getValueStart()
     {
@@ -372,46 +318,44 @@ public class MXMLTagAttributeData extends SourceLocation implements
         return new SourceLocation(getSourcePath(), getValueStart(), getValueEnd(), getValueLine(),
getValueColumn());
     }
 
-    /**
-     * Get this attribute's state start offset if a state token is present other
-     * wise zero.
-     * 
-     * @return state start offset or zero
-     */
-    public int getStateStart()
+    //
+    // Other methods
+    //
+
+    public IFileSpecification getSource()
     {
-        return stateName != null ? stateStart : 0;
+        return getParent().getSource();
     }
 
     /**
-     * Get this attribute's state tokens end offset if a state token is present
-     * other wise zero.
+     * Sets this attribute's tag.
      * 
-     * @return state start offset or zero
+     * @param parent MXML tag containing this attribute
      */
-    public int getStateEnd()
+    public void setParent(IMXMLTagData parent)
     {
-        return stateName != null ? stateStart + stateName.length() : 0;
+        this.parent = parent;
+        setSourcePath(parent.getSourcePath());
     }
 
     /**
-     * Does this value have a closing quote character?
+     * Adjust all associated offsets by the adjustment amount
      * 
-     * @return true if this value has a closing quote character
+     * @param offsetAdjustment amount to add to offsets
      */
-    protected boolean valueIsWellFormed()
+    public void adjustOffsets(int offsetAdjustment)
     {
-        // If there is a value, it came from a string token.  We know (from the
-        // RawTagTokenizer) that this means it starts with a quote character.  If
-        // it ends with the same quote character, it's well formed.
-        if (hasValue())
+        if (attributeName != null)
         {
-            char firstChar = valueIncludingDelimiters.charAt(0);
-            char lastChar = valueIncludingDelimiters.charAt(valueIncludingDelimiters.length()
- 1);
-            return (firstChar == '"' || firstChar == '\'') && firstChar == lastChar;
+            setStart(getAbsoluteStart() + offsetAdjustment);
+            setEnd(getAbsoluteEnd() + offsetAdjustment);
         }
 
-        return false;
+        if (hasValue())
+            valueStart += offsetAdjustment;
+
+        if (stateName != null)
+            stateStart += offsetAdjustment;
     }
 
     /**
@@ -428,6 +372,47 @@ public class MXMLTagAttributeData extends SourceLocation implements
         return parent.getCompositePrefixMap();
     }
 
+    void invalidateURI()
+    {
+        uri = null;
+    }
+
+    /**
+     * Gets the starting offset for this attribute's name.
+     */
+    public int getNameStart()
+    {
+        return getAbsoluteStart();
+    }
+
+    /**
+     * Gets the ending offset for this attribute's name.
+     */
+    public int getNameEnd()
+    {
+        return getAbsoluteStart() + attributeName.length();
+    }
+
+    /**
+     * Gets the line number for this attribute's name.
+     * 
+     * @return end offset
+     */
+    public final int getNameLine()
+    {
+        return getLine();
+    }
+
+    /**
+     * Get the column number for this attribute's name.
+     * 
+     * @return end offset
+     */
+    public final int getNameColumn()
+    {
+        return getColumn();
+    }
+
     /**
      * Does the offset fall inside the bounds of the attribute name?
      * 
@@ -442,101 +427,117 @@ public class MXMLTagAttributeData extends SourceLocation implements
         return false;
     }
 
-    public boolean isInsideStateName(int offset)
+    /**
+     * Checks whether this attribute is associated with a state.
+     * 
+     * @return True if a state association exists.
+     */
+    public boolean hasState()
     {
-        if (stateName != null)
-            return MXMLData.contains(getStateStart(), getStateEnd(), offset);
-
-        return false;
+        return stateName != null;
     }
 
     /**
-     * Does the offset fall inside the bounds of the attribute value?
+     * Get this attribute's state start offset if a state token is present other
+     * wise zero.
      * 
-     * @param offset test offset
-     * @return true if the offset falls within the attribute value
+     * @return state start offset or zero
      */
-    public boolean isInsideValue(int offset)
+    public int getStateStart()
     {
-        if (hasValue())
-            return MXMLData.contains(getValueStart() - 1, getValueEnd(), offset);
-
-        return false;
+        return stateName != null ? stateStart : 0;
     }
 
-    @Override
-    public String getPrefix()
+    /**
+     * Get this attribute's state tokens end offset if a state token is present
+     * other wise zero.
+     * 
+     * @return state start offset or zero
+     */
+    public int getStateEnd()
     {
-        String name = getName();
-        int i = name.indexOf(':');
-        return i != -1 ? name.substring(0, i) : null;
+        return stateName != null ? stateStart + stateName.length() : 0;
     }
-
-    @Override
-    public String getShortName()
+    
+    public boolean isInsideStateName(int offset)
     {
-        String name = getName();
-        int i = name.indexOf(':');
-        return i != -1 ? name.substring(i + 1) : name;
+        if (stateName != null)
+            return MXMLData.contains(getStateStart(), getStateEnd(), offset);
+
+        return false;
     }
 
-    @Override
-    public XMLName getXMLName()
+    /**
+     * Gets the attribute value as a String (with quotes).
+     * 
+     * @return attribute value (with quotes)
+     */
+    public String getValueWithQuotes()
     {
-        return new XMLName(getURI(), getShortName());
+        return valueIncludingDelimiters;
     }
 
-    @Override
-    public String getURI()
+    /**
+     * Does this value have a closing quote character?
+     * 
+     * @return true if this value has a closing quote character
+     */
+    protected boolean valueIsWellFormed()
     {
-        if (uri == null)
+        // If there is a value, it came from a string token.  We know (from the
+        // RawTagTokenizer) that this means it starts with a quote character.  If
+        // it ends with the same quote character, it's well formed.
+        if (hasValue())
         {
-            //walk up our chain to find the correct uri for our namespace.  first one wins
-            String prefix = getPrefix();
-            if (prefix == null)
-                return null;
-
-            IMXMLTagData lookingAt = parent;
-
-            // For attributes with prefix, parent's parent can be null if
-            // parent is the root tag 
-            while (lookingAt != null && lookingAt.getParent() != null)
-            {
-                PrefixMap depth = lookingAt.getParent().getPrefixMapForData(lookingAt);
-                if (depth != null && depth.containsPrefix(prefix))
-                {
-                    uri = depth.getNamespaceForPrefix(prefix);
-                    break;
-                }
-
-                lookingAt = lookingAt.getParentTag();
-            }
+            char firstChar = valueIncludingDelimiters.charAt(0);
+            char lastChar = valueIncludingDelimiters.charAt(valueIncludingDelimiters.length()
- 1);
+            return (firstChar == '"' || firstChar == '\'') && firstChar == lastChar;
         }
 
-        return uri;
+        return false;
     }
 
-    void invalidateURI()
+    /**
+     * Does the offset fall inside the bounds of the attribute value?
+     * 
+     * @param offset test offset
+     * @return true if the offset falls within the attribute value
+     */
+    public boolean isInsideValue(int offset)
     {
-        uri = null;
-    }
+        if (hasValue())
+            return MXMLData.contains(getValueStart() - 1, getValueEnd(), offset);
 
-    @Override
-    public MXMLDialect getMXMLDialect()
-    {
-        return getParent().getParent().getMXMLDialect();
+        return false;
     }
-
-    @Override
-    public boolean isSpecialAttribute(String name)
+    
+    /**
+     * For unit tests only.
+     * 
+     * @return name value and offsets in string form
+     */
+    public String buildAttributeString(boolean skipSrcPath)
     {
-        String languageURI = getMXMLDialect().getLanguageNamespace();
+        StringBuilder sb = new StringBuilder();
+        sb.append(getName());
+        sb.append('=');
+        sb.append('"');
+        sb.append(getRawValue());
+        sb.append('"');
 
-        return getName().equals(name) && (getPrefix() == null || getURI() == languageURI);
+        sb.append(' ');
+
+        // Display line, column, start, and end as "17:5 160-188".
+        if (skipSrcPath)
+            sb.append(getOffsetsString());
+        else
+            sb.append(super.toString());
+        
+        return sb.toString();
     }
 
     /**
-     * Verifies that this attrobite has its source location information set.
+     * Verifies that this attribute has its source location information set.
      * <p>
      * This is used only in asserts.
      */


Mime
View raw message