diff options
author | Tor Norbye <tnorbye@google.com> | 2012-03-21 18:04:18 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-03-22 14:47:16 -0700 |
commit | 61684adfd7345f1a0df24bcf9176e6f528295bbb (patch) | |
tree | 2b08ae518b0a0150ec610a85679501626b611c62 /eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java | |
parent | 6b09013b6cb0fdcb48350a60bb3ed924ac9f562d (diff) | |
download | sdk-61684adfd7345f1a0df24bcf9176e6f528295bbb.zip sdk-61684adfd7345f1a0df24bcf9176e6f528295bbb.tar.gz sdk-61684adfd7345f1a0df24bcf9176e6f528295bbb.tar.bz2 |
Change AttributeInfo.getFormats() to returning an EnumSet<Format>
This changeset changes the signature of AttributeInfo.getFormats()
from returning a Format[] to returning an EnumSet<Format>.
Furthermore, it defines a number of constants for the various common
format sets such that they can be reused.
Nearly all uses of the getFormats() method was really just trying to
see "is format X among the formats", so using enumsets is more natural
since it has a contains method. This also lets us replace some
attribute init code which was building up a set from the array for
this exact same purpose just reuse the format set directly.
In the attribute parser, rather than computing the uppercase version
of each format string ("dimension"=>"DIMENSION") and then doing a
Format.valueOf("DIMENSION"), we now compute a map for all the format
constants as lowercase to the corresponding format instance, and use
that map when parsing the attrs.xml file.
Note that there is a small semantic change from having an array of
formats to using an enumset: The format specified an
ordering. However, it does not look like any code depended on this,
and it's also not clear that the ordering in attrs.xml is
intentional. For example, it contains both "color|reference" and
"reference|color", and in both cases the intent is that the attribute
can specify an actual color or a reference to a color. Now with an
enum set, the order used when traversing the formats will always be in
their natural order, and for this purpose the REFERENCE type is moved
to the end since it's the least specific.
Change-Id: I1170cff48086f5cc13e4b70a35deea1f9979c883
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java')
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java index 17726d0..ddad36c 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java @@ -57,6 +57,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -317,7 +318,7 @@ public class BaseViewRule extends AbstractViewRule { oldValue = ensureValidString(oldValue); IAttributeInfo attributeInfo = node.getAttributeInfo(ANDROID_URI, attribute); if (attributeInfo != null - && IAttributeInfo.Format.REFERENCE.in(attributeInfo.getFormats())) { + && attributeInfo.getFormats().contains(Format.REFERENCE)) { return mRulesEngine.displayReferenceInput(oldValue); } else { // A single resource type? If so use a resource chooser initialized @@ -696,17 +697,17 @@ public class BaseViewRule extends AbstractViewRule { // Layout width/height are already handled at the root level continue; } - Format[] formats = attrInfo != null ? attrInfo.getFormats() : null; - if (formats == null) { + if (attrInfo == null) { continue; } + EnumSet<Format> formats = attrInfo.getFormats(); String title = getAttributeDisplayName(id); String definedBy = attrInfo != null ? attrInfo.getDefinedBy() : null; - if (IAttributeInfo.Format.BOOLEAN.in(formats)) { + if (formats.contains(IAttributeInfo.Format.BOOLEAN)) { props.put(id, new Prop(title, true, definedBy)); - } else if (IAttributeInfo.Format.ENUM.in(formats)) { + } else if (formats.contains(IAttributeInfo.Format.ENUM)) { // Convert each enum into a map id=>title Map<String, String> values = new HashMap<String, String>(); if (attrInfo != null) { @@ -716,7 +717,7 @@ public class BaseViewRule extends AbstractViewRule { } props.put(id, new Prop(title, false, false, values, definedBy)); - } else if (IAttributeInfo.Format.FLAG.in(formats)) { + } else if (formats.contains(IAttributeInfo.Format.FLAG)) { // Convert each flag into a map id=>title Map<String, String> values = new HashMap<String, String>(); if (attrInfo != null) { |