From 61684adfd7345f1a0df24bcf9176e6f528295bbb Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Wed, 21 Mar 2012 18:04:18 -0700 Subject: Change AttributeInfo.getFormats() to returning an EnumSet This changeset changes the signature of AttributeInfo.getFormats() from returning a Format[] to returning an EnumSet. 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 --- .../android/ide/common/layout/BaseLayoutRule.java | 6 +-- .../android/ide/common/layout/BaseViewRule.java | 13 ++--- .../common/resources/platform/AttributeInfo.java | 11 ++-- .../common/resources/platform/AttrsXmlParser.java | 63 ++++++++++++++++------ .../adt/internal/editors/AndroidContentAssist.java | 11 ++-- .../editors/animator/AnimationContentAssist.java | 21 ++++---- .../internal/editors/color/ColorDescriptors.java | 2 +- .../editors/descriptors/DescriptorsUtils.java | 11 +--- .../descriptors/ReferenceAttributeDescriptor.java | 2 +- .../descriptors/TextAttributeDescriptor.java | 17 +++--- .../editors/drawable/DrawableDescriptors.java | 4 +- .../layout/descriptors/LayoutDescriptors.java | 17 +++--- .../descriptors/AndroidManifestDescriptors.java | 4 +- .../internal/editors/uimodel/UiElementNode.java | 2 +- .../values/descriptors/ValuesDescriptors.java | 10 ++-- .../ide/common/layout/LinearLayoutRuleTest.java | 6 +-- .../ide/common/layout/TestAttributeInfo.java | 8 +-- .../resources/platform/AttrsXmlParserTest.java | 6 +-- .../editors/layout/UiElementPullParserTest.java | 2 +- 19 files changed, 122 insertions(+), 94 deletions(-) (limited to 'eclipse') diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java index 47f3a58..76e515e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java @@ -56,7 +56,6 @@ import static com.android.ide.common.layout.LayoutConstants.VALUE_WRAP_CONTENT; import com.android.ide.common.api.DrawingStyle; import com.android.ide.common.api.DropFeedback; import com.android.ide.common.api.IAttributeInfo; -import com.android.ide.common.api.IAttributeInfo.Format; import com.android.ide.common.api.IClientRulesEngine; import com.android.ide.common.api.IDragElement; import com.android.ide.common.api.IDragElement.IDragAttribute; @@ -160,7 +159,7 @@ public class BaseLayoutRule extends BaseViewRule { IAttributeInfo info = first.getAttributeInfo(ANDROID_URI, attributeName); if (info != null) { // Generate list of possible gravity value constants - assert IAttributeInfo.Format.FLAG.in(info.getFormats()); + assert info.getFormats().contains(IAttributeInfo.Format.FLAG); for (String name : info.getFlagValues()) { titles.add(getAttributeDisplayName(name)); ids.add(name); @@ -524,8 +523,7 @@ public class BaseLayoutRule extends BaseViewRule { IAttributeInfo attrInfo = newNode.getAttributeInfo(uri, name); if (attrInfo != null) { - Format[] formats = attrInfo.getFormats(); - if (IAttributeInfo.Format.REFERENCE.in(formats)) { + if (attrInfo.getFormats().contains(IAttributeInfo.Format.REFERENCE)) { if (idMap.containsKey(value)) { value = idMap.get(value).getFirst(); } 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 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 values = new HashMap(); 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 values = new HashMap(); if (attrInfo != null) { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/AttributeInfo.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/AttributeInfo.java index b8d381f..ec3d8a4 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/AttributeInfo.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/AttributeInfo.java @@ -16,8 +16,11 @@ package com.android.ide.common.resources.platform; +import com.android.annotations.NonNull; import com.android.ide.common.api.IAttributeInfo; +import java.util.EnumSet; + /** * Information about an attribute as gathered from the attrs.xml file where @@ -29,7 +32,7 @@ public class AttributeInfo implements IAttributeInfo { private String mName; /** Formats of the attribute. Cannot be null. Should have at least one format. */ - private Format[] mFormats; + private EnumSet mFormats; /** Values for enum. null for other types. */ private String[] mEnumValues; /** Values for flag. null for other types. */ @@ -46,7 +49,7 @@ public class AttributeInfo implements IAttributeInfo { * @param formats The formats of the attribute. Cannot be null. * Should have at least one format. */ - public AttributeInfo(String name, Format[] formats) { + public AttributeInfo(@NonNull String name, @NonNull EnumSet formats) { mName = name; mFormats = formats; } @@ -57,7 +60,7 @@ public class AttributeInfo implements IAttributeInfo { * Should have at least one format. * @param javadoc Short javadoc (i.e. the first sentence). */ - public AttributeInfo(String name, Format[] formats, String javadoc) { + public AttributeInfo(@NonNull String name, @NonNull EnumSet formats, String javadoc) { mName = name; mFormats = formats; mJavaDoc = javadoc; @@ -80,7 +83,7 @@ public class AttributeInfo implements IAttributeInfo { /** Returns the formats of the attribute. Cannot be null. * Should have at least one format. */ @Override - public Format[] getFormats() { + public EnumSet getFormats() { return mFormats; } /** Returns the values for enums. null for other types. */ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/AttrsXmlParser.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/AttrsXmlParser.java index abe56d8..52b0e15 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/AttrsXmlParser.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/AttrsXmlParser.java @@ -30,11 +30,11 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; +import java.util.EnumSet; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; -import java.util.TreeSet; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -58,6 +58,9 @@ public final class AttrsXmlParser { private final Map mStyleMap = new HashMap(); + /** Map from format name (lower case) to the uppercase version */ + private Map mFormatNames = new HashMap(10); + /** * Map of all (constant, value) pairs for attributes of format enum or flag. * E.g. for attribute name=gravity, this tells us there's an enum/flag called "center" @@ -117,6 +120,12 @@ public final class AttrsXmlParser { mEnumFlagValues = new HashMap>( inheritableAttributes.mEnumFlagValues); } + + // Pre-compute the set of format names such that we don't have to compute the uppercase + // version of the same format string names again and again + for (Format f : Format.values()) { + mFormatNames.put(f.name().toLowerCase(Locale.US), f); + } } /** @@ -396,7 +405,7 @@ public final class AttrsXmlParser { info = mAttributeMap.get(name); // If the attribute is unknown yet, parse it. // If the attribute is know but its format is unknown, parse it too. - if (info == null || info.getFormats().length == 0) { + if (info == null || info.getFormats().size() == 0) { info = parseAttributeTypes(attrNode, name); if (info != null) { mAttributeMap.put(name, info); @@ -468,25 +477,28 @@ public final class AttrsXmlParser { * When reusing a node, it is duplicated and its javadoc reassigned. */ private AttributeInfo parseAttributeTypes(Node attrNode, String name) { - TreeSet formats = new TreeSet(); + EnumSet formats = null; String[] enumValues = null; String[] flagValues = null; Node attrFormat = attrNode.getAttributes().getNamedItem("format"); //$NON-NLS-1$ if (attrFormat != null) { for (String f : attrFormat.getNodeValue().split("\\|")) { //$NON-NLS-1$ - try { - Format format = AttributeInfo.Format.valueOf(f.toUpperCase(Locale.US)); - // enum and flags are handled differently right below - if (format != null && - format != AttributeInfo.Format.ENUM && - format != AttributeInfo.Format.FLAG) { - formats.add(format); - } - } catch (IllegalArgumentException e) { - mLog.error(e, + Format format = mFormatNames.get(f); + if (format == null) { + mLog.printf( "Unknown format name '%s' in , file '%s'.", //$NON-NLS-1$ f, name, getOsAttrsXmlPath()); + } else if (format != AttributeInfo.Format.ENUM && + format != AttributeInfo.Format.FLAG) { + if (formats == null) { + formats = format.asSet(); + } else { + if (formats.size() == 1) { + formats = EnumSet.copyOf(formats); + } + formats.add(format); + } } } } @@ -494,17 +506,34 @@ public final class AttrsXmlParser { // does this have children? enumValues = parseEnumFlagValues(attrNode, "enum", name); //$NON-NLS-1$ if (enumValues != null) { - formats.add(AttributeInfo.Format.ENUM); + if (formats == null) { + formats = Format.ENUM_SET; + } else { + if (formats.size() == 1) { + formats = EnumSet.copyOf(formats); + } + formats.add(Format.ENUM); + } } // does this have children? flagValues = parseEnumFlagValues(attrNode, "flag", name); //$NON-NLS-1$ if (flagValues != null) { - formats.add(AttributeInfo.Format.FLAG); + if (formats == null) { + formats = Format.FLAG_SET; + } else { + if (formats.size() == 1) { + formats = EnumSet.copyOf(formats); + } + formats.add(Format.FLAG); + } + } + + if (formats == null) { + formats = Format.NONE; } - AttributeInfo info = new AttributeInfo(name, - formats.toArray(new AttributeInfo.Format[formats.size()])); + AttributeInfo info = new AttributeInfo(name, formats); info.setEnumValues(enumValues); info.setFlagValues(flagValues); return info; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java index 14e479e..7c4cba8 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java @@ -59,6 +59,7 @@ import org.w3c.dom.Node; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; +import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -496,7 +497,7 @@ public abstract class AndroidContentAssist implements IContentAssistProcessor { AttributeDescriptor attributeDescriptor = currAttrNode.getDescriptor(); IAttributeInfo attributeInfo = attributeDescriptor.getAttributeInfo(); if (value.startsWith(PREFIX_RESOURCE_REF) - && !Format.REFERENCE.in(attributeInfo.getFormats())) { + && !attributeInfo.getFormats().contains(Format.REFERENCE)) { // Special case: If the attribute value looks like a reference to a // resource, offer to complete it, since in many cases our metadata // does not correctly state whether a resource value is allowed. We don't @@ -1224,12 +1225,12 @@ public abstract class AndroidContentAssist implements IContentAssistProcessor { */ private Object[] completeSuffix(Object[] choices, String value, UiAttributeNode currAttrNode) { IAttributeInfo attributeInfo = currAttrNode.getDescriptor().getAttributeInfo(); - Format[] formats = attributeInfo.getFormats(); + EnumSet formats = attributeInfo.getFormats(); List suffixes = new ArrayList(); if (value.length() > 0 && Character.isDigit(value.charAt(0))) { - boolean hasDimension = Format.DIMENSION.in(formats); - boolean hasFraction = Format.FRACTION.in(formats); + boolean hasDimension = formats.contains(Format.DIMENSION); + boolean hasFraction = formats.contains(Format.FRACTION); if (hasDimension || hasFraction) { // Split up the value into a numeric part (the prefix) and the @@ -1273,7 +1274,7 @@ public abstract class AndroidContentAssist implements IContentAssistProcessor { } } - boolean hasFlag = Format.FLAG.in(formats); + boolean hasFlag = formats.contains(Format.FLAG); if (hasFlag) { boolean isDone = false; String[] flagValues = attributeInfo.getFlagValues(); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationContentAssist.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationContentAssist.java index 476fbd9..6b584b1 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationContentAssist.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/animator/AnimationContentAssist.java @@ -39,6 +39,7 @@ import org.w3c.dom.Node; import java.util.ArrayList; import java.util.Collections; +import java.util.EnumSet; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -125,17 +126,15 @@ public final class AnimationContentAssist extends AndroidContentAssist { } String name = desc.getXmlLocalName(); if (startsWith(name, attributePrefix)) { - for (Format f : desc.getAttributeInfo().getFormats()) { - if (f == Format.INTEGER || f == Format.FLOAT) { - // TODO: Filter out some common properties - // that the user probably isn't trying to - // animate: - // num*, min*, max*, *Index, *Threshold, - // *Duration, *Id, *Limit - - matches.put(name, desc); - break; - } + EnumSet formats = desc.getAttributeInfo().getFormats(); + if (formats.contains(Format.INTEGER) + || formats.contains(Format.FLOAT)) { + // TODO: Filter out some common properties + // that the user probably isn't trying to + // animate: + // num*, min*, max*, *Index, *Threshold, + // *Duration, *Id, *Limit + matches.put(name, desc); } } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/color/ColorDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/color/ColorDescriptors.java index 2c1923e..8db3e0f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/color/ColorDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/color/ColorDescriptors.java @@ -78,7 +78,7 @@ public class ColorDescriptors implements IDescriptorProvider { new ReferenceAttributeDescriptor( ResourceType.COLOR, ATTR_COLOR, SdkConstants.NS_RESOURCES, - new AttributeInfo(ATTR_COLOR, new Format[] { Format.COLOR })).setTooltip( + new AttributeInfo(ATTR_COLOR, Format.COLOR_SET)).setTooltip( "Hexadeximal color. Required. The color is specified with an RGB value and " + "optional alpha channel.\n" + "The value always begins with a pound (#) character and then " diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtils.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtils.java index ce8e3b1..20096f4 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtils.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/DescriptorsUtils.java @@ -140,16 +140,9 @@ public final class DescriptorsUtils { String xmlLocalName = info.getName(); // Add the known types to the tooltip - Format[] formats_list = info.getFormats(); - int flen = formats_list.length; + EnumSet formats_set = info.getFormats(); + int flen = formats_set.size(); if (flen > 0) { - // Fill the formats in a set for faster access - EnumSet formats_set = EnumSet.noneOf(Format.class); - for (int i = 0; i < flen; i++) { - Format f = formats_list[i]; - formats_set.add(f); - } - // Create a specialized attribute if we can if (overrides != null) { for (Entry entry: overrides.entrySet()) { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/ReferenceAttributeDescriptor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/ReferenceAttributeDescriptor.java index 9f1f501..0d5e209 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/ReferenceAttributeDescriptor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/ReferenceAttributeDescriptor.java @@ -51,7 +51,7 @@ public final class ReferenceAttributeDescriptor extends TextAttributeDescriptor return new ReferenceAttributeDescriptor( ResourceType.DRAWABLE, xmlLocalName, nsUri, - new AttributeInfo(xmlLocalName, new Format[] { Format.REFERENCE })); + new AttributeInfo(xmlLocalName, Format.REFERENCE_SET)); } }; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/TextAttributeDescriptor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/TextAttributeDescriptor.java index dece813..032363d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/TextAttributeDescriptor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/TextAttributeDescriptor.java @@ -32,6 +32,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.views.properties.IPropertyDescriptor; +import java.util.EnumSet; import java.util.Locale; @@ -177,8 +178,8 @@ public class TextAttributeDescriptor extends AttributeDescriptor implements IPro } // Add the known types to the tooltip - Format[] formats_list = info.getFormats(); - int flen = formats_list.length; + EnumSet formats_list = info.getFormats(); + int flen = formats_list.size(); if (flen > 0) { StringBuilder sb = new StringBuilder(); if (rawTooltip != null && rawTooltip.length() > 0) { @@ -189,12 +190,14 @@ public class TextAttributeDescriptor extends AttributeDescriptor implements IPro sb.append("@@"); //$NON-NLS-1$ @@ inserts a break before the types } sb.append("["); //$NON-NLS-1$ - for (int i = 0; i < flen; i++) { - Format f = formats_list[i]; - sb.append(f.toString().toLowerCase(Locale.US)); - if (i < flen - 1) { - sb.append(", "); //$NON-NLS-1$ + boolean isFirst = true; + for (Format f : formats_list) { + if (isFirst) { + isFirst = false; + } else { + sb.append(", "); } + sb.append(f.toString().toLowerCase(Locale.US)); } // The extra space at the end makes the tooltip more readable on Windows. sb.append("]"); //$NON-NLS-1$ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/drawable/DrawableDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/drawable/DrawableDescriptors.java index ca9710b..5603322 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/drawable/DrawableDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/drawable/DrawableDescriptors.java @@ -85,8 +85,6 @@ public class DrawableDescriptors implements IDescriptorProvider { public synchronized void updateDescriptors(Map styleMap) { XmlnsAttributeDescriptor xmlns = new XmlnsAttributeDescriptor(ANDROID_NS_NAME, SdkConstants.NS_RESOURCES); - Format[] referenceFormat = new Format[] { Format.REFERENCE }; - List descriptors = new ArrayList(); AnimatorDescriptors.addElement(descriptors, styleMap, @@ -214,7 +212,7 @@ public class DrawableDescriptors implements IDescriptorProvider { SDK_URL_BASE + "drawable-resource.html#StateList", //$NON-NLS-1$ new ReferenceAttributeDescriptor( ResourceType.DRAWABLE, "drawable", SdkConstants.NS_RESOURCES, //$NON-NLS-1$ - new AttributeInfo("drawable", referenceFormat)) + new AttributeInfo("drawable", Format.REFERENCE_SET)) .setTooltip("Reference to a drawable resource."), null, /* This is wrong -- we can now embed any above drawable (but without xmlns as extra) */ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/LayoutDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/LayoutDescriptors.java index 1eab291..10e1a4d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/LayoutDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/LayoutDescriptors.java @@ -104,14 +104,13 @@ public final class LayoutDescriptors implements IDescriptorProvider { new DocumentDescriptor("layout_doc", null); //$NON-NLS-1$ /** The list of all known ViewLayout descriptors. */ - private List mLayoutDescriptors = - new ArrayList(); + private List mLayoutDescriptors = Collections.emptyList(); /** Read-Only list of View Descriptors. */ private List mROLayoutDescriptors; /** The list of all known View (not ViewLayout) descriptors. */ - private List mViewDescriptors = new ArrayList(); + private List mViewDescriptors = Collections.emptyList(); /** Read-Only list of View Descriptors. */ private List mROViewDescriptors; @@ -277,7 +276,7 @@ public final class LayoutDescriptors implements IDescriptorProvider { // All views and groups have an implicit "style" attribute which is a reference. AttributeInfo styleInfo = new AttributeInfo( "style", //$NON-NLS-1$ xmlLocalName - new Format[] { Format.REFERENCE }); + Format.REFERENCE_SET); styleInfo.setJavaDoc("A reference to a custom style"); //tooltip DescriptorsUtils.appendAttribute(attributes, "style", //$NON-NLS-1$ @@ -386,7 +385,7 @@ public final class LayoutDescriptors implements IDescriptorProvider { null, //nsUri new AttributeInfo( ATTR_LAYOUT, - new Format[] { Format.REFERENCE } ), + Format.REFERENCE_SET ), true, //required null); //overrides @@ -395,7 +394,7 @@ public final class LayoutDescriptors implements IDescriptorProvider { SdkConstants.NS_RESOURCES, //nsUri new AttributeInfo( "id", //$NON-NLS-1$ - new Format[] { Format.REFERENCE } ), + Format.REFERENCE_SET ), true, //required null); //overrides @@ -458,7 +457,7 @@ public final class LayoutDescriptors implements IDescriptorProvider { // Should accept both CLASS_V4_FRAGMENT and CLASS_FRAGMENT null /*superClassName*/, ATTR_CLASS, null /* namespace */, - new AttributeInfo(ATTR_CLASS, new Format[] { Format.STRING}), + new AttributeInfo(ATTR_CLASS, Format.STRING_SET), true /*mandatory*/) .setTooltip("Supply the name of the fragment class to instantiate"); @@ -495,14 +494,14 @@ public final class LayoutDescriptors implements IDescriptorProvider { new ClassAttributeDescriptor( null /*superClassName*/, ATTR_NAME, ANDROID_URI, - new AttributeInfo(ATTR_NAME, new Format[] { Format.STRING}), + new AttributeInfo(ATTR_NAME, Format.STRING_SET), true /*mandatory*/) .setTooltip("Supply the name of the fragment class to instantiate"), classAttribute, new ClassAttributeDescriptor( null /*superClassName*/, ATTR_TAG, ANDROID_URI, - new AttributeInfo(ATTR_TAG, new Format[] { Format.STRING}), + new AttributeInfo(ATTR_TAG, Format.STRING_SET), true /*mandatory*/) .setTooltip("Supply a tag for the top-level view containing a String"), }, // attributes diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/AndroidManifestDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/AndroidManifestDescriptors.java index 02f68ba..e3b3aa6 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/AndroidManifestDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/descriptors/AndroidManifestDescriptors.java @@ -117,7 +117,7 @@ public final class AndroidManifestDescriptors implements IDescriptorProvider { // Android XML namespace. PACKAGE_ATTR_DESC = new PackageAttributeDescriptor(PACKAGE_ATTR, null /* nsUri */, - new AttributeInfo(PACKAGE_ATTR, new Format[] { Format.REFERENCE })).setTooltip( + new AttributeInfo(PACKAGE_ATTR, Format.REFERENCE_SET)).setTooltip( "This attribute gives a unique name for the package, using a Java-style " + "naming convention to avoid name collisions.\nFor example, applications " + "published by Google could have names of the form com.google.app.appname"); @@ -253,7 +253,7 @@ public final class AndroidManifestDescriptors implements IDescriptorProvider { public TextAttributeDescriptor create(String xmlName, String nsUri, IAttributeInfo attrInfo) { if (attrInfo == null) { - attrInfo = new AttributeInfo(xmlName, new Format[] { Format.STRING } ); + attrInfo = new AttributeInfo(xmlName, Format.STRING_SET ); } if (SdkConstants.CLASS_ACTIVITY.equals(className)) { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java index 706aa66..e5fe678 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java @@ -1483,7 +1483,7 @@ public class UiElementNode implements IPropertySource { TextAttributeDescriptor desc = new TextAttributeDescriptor( xmlAttrLocalName, // xml name xmlNsUri, // ui name - new AttributeInfo(xmlAttrLocalName, new Format[] { Format.STRING } ) + new AttributeInfo(xmlAttrLocalName, Format.STRING_SET) ); UiAttributeNode uiAttr = desc.createUiNode(this); mUnknownUiAttributes.add(uiAttr); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/values/descriptors/ValuesDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/values/descriptors/ValuesDescriptors.java index c450597..e50c541 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/values/descriptors/ValuesDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/values/descriptors/ValuesDescriptors.java @@ -27,6 +27,8 @@ import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDes import com.android.ide.eclipse.adt.internal.editors.descriptors.TextValueDescriptor; import com.android.resources.ResourceType; +import java.util.EnumSet; + /** * Complete description of the structure for resources XML files (under res/values/) @@ -81,7 +83,7 @@ public final class ValuesDescriptors implements IDescriptorProvider { // Elements - AttributeInfo nameAttrInfo = new AttributeInfo(NAME_ATTR, new Format[] { Format.STRING } ); + AttributeInfo nameAttrInfo = new AttributeInfo(NAME_ATTR, Format.STRING_SET); ElementDescriptor color_element = new ElementDescriptor( COLOR_ELEMENT, @@ -130,13 +132,13 @@ public final class ValuesDescriptors implements IDescriptorProvider { new ListAttributeDescriptor(TYPE_ATTR, null /* nsUri */, new AttributeInfo(TYPE_ATTR, - new Format[] { Format.STRING, Format.ENUM } + EnumSet.of(Format.STRING, Format.ENUM) ).setEnumValues(ResourceType.getNames()) ).setTooltip("The mandatory type of this resource."), new FlagAttributeDescriptor("format", //$NON-NLS-1$ null /* nsUri */, new AttributeInfo("format", - new Format[] { Format.STRING, Format.FLAG } + EnumSet.of(Format.STRING, Format.FLAG) ).setFlagValues( new String[] { "boolean", //$NON-NLS-1$ @@ -203,7 +205,7 @@ public final class ValuesDescriptors implements IDescriptorProvider { new TextAttributeDescriptor("parent", //$NON-NLS-1$ null /* nsUri */, new AttributeInfo("parent", //$NON-NLS-1$ - new Format[] { Format.STRING })) + Format.STRING_SET)) .setTooltip("An optional parent theme. All values from the specified theme will be inherited into this theme. Any values with identical names that you specify will override inherited values."), }, new ElementDescriptor[] { diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/LinearLayoutRuleTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/LinearLayoutRuleTest.java index a703a6f..cec3a9b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/LinearLayoutRuleTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/LinearLayoutRuleTest.java @@ -175,7 +175,7 @@ public class LinearLayoutRuleTest extends LayoutTestBase { initialize(rule, "android.widget.LinearLayout"); TestNode node = TestNode.create("android.widget.LinearLayout").id("@+id/LinearLayout012"); node.putAttributeInfo(ANDROID_URI, "orientation", - new TestAttributeInfo(ATTR_ORIENTATION, new Format[] { Format.ENUM }, + new TestAttributeInfo(ATTR_ORIENTATION, Format.ENUM_SET, "android.widget.LinearLayout", new String[] {"horizontal", "vertical"}, null, null)); @@ -209,13 +209,13 @@ public class LinearLayoutRuleTest extends LayoutTestBase { initialize(rule, "android.widget.LinearLayout"); TestNode node = TestNode.create("android.widget.LinearLayout").id("@+id/LinearLayout012"); node.putAttributeInfo(ANDROID_URI, "orientation", - new TestAttributeInfo(ATTR_ORIENTATION, new Format[] { Format.ENUM }, + new TestAttributeInfo(ATTR_ORIENTATION, Format.ENUM_SET, "android.widget.LinearLayout", new String[] {"horizontal", "vertical"}, null, null)); node.setAttributeSources(Arrays.asList("android.widget.LinearLayout", "android.view.ViewGroup", "android.view.View")); node.putAttributeInfo(ANDROID_URI, "gravity", - new TestAttributeInfo("gravity", new Format[] { Format.INTEGER }, + new TestAttributeInfo("gravity", Format.INTEGER_SET, "android.widget.LinearLayout", null, null, null)); diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestAttributeInfo.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestAttributeInfo.java index ee04260..f4f83c1 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestAttributeInfo.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestAttributeInfo.java @@ -17,10 +17,12 @@ package com.android.ide.common.layout; import com.android.ide.common.api.IAttributeInfo; +import java.util.EnumSet; + /** Test/mock implementation of {@link IAttributeInfo} */ public class TestAttributeInfo implements IAttributeInfo { private final String mName; - private final Format[] mFormats; + private final EnumSet mFormats; private final String mDefinedBy; private final String[] mEnumValues; private final String[] mFlagValues; @@ -30,7 +32,7 @@ public class TestAttributeInfo implements IAttributeInfo { this(name, null, null, null, null, null); } - public TestAttributeInfo(String name, Format[] formats, String definedBy, + public TestAttributeInfo(String name, EnumSet formats, String definedBy, String[] enumValues, String[] flagValues, String javadoc) { super(); this.mName = name; @@ -57,7 +59,7 @@ public class TestAttributeInfo implements IAttributeInfo { } @Override - public Format[] getFormats() { + public EnumSet getFormats() { return mFormats; } diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/resources/platform/AttrsXmlParserTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/resources/platform/AttrsXmlParserTest.java index 6b0ddd3..e57e5cd 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/resources/platform/AttrsXmlParserTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/resources/platform/AttrsXmlParserTest.java @@ -35,7 +35,7 @@ public class AttrsXmlParserTest extends TestCase { @Override public void setUp() throws Exception { - mFilePath = AdtTestData.getInstance().getTestFilePath(MOCK_DATA_PATH); //$NON-NLS-1$ + mFilePath = AdtTestData.getInstance().getTestFilePath(MOCK_DATA_PATH); mParser = new AttrsXmlParser(mFilePath, new TestLogger()); } @@ -65,8 +65,8 @@ public class AttrsXmlParserTest extends TestCase { AttributeInfo[] attrs = info.getAttributes(); assertEquals(1, attrs.length); assertEquals("scrollbarSize", info.getAttributes()[0].getName()); - assertEquals(1, info.getAttributes()[0].getFormats().length); - assertEquals(Format.DIMENSION, info.getAttributes()[0].getFormats()[0]); + assertEquals(1, info.getAttributes()[0].getFormats().size()); + assertEquals(Format.DIMENSION, info.getAttributes()[0].getFormats().iterator().next()); } public final void testEnumFlagValues() throws Exception { diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParserTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParserTest.java index e3df52d..5f01766 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParserTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParserTest.java @@ -45,7 +45,7 @@ public class UiElementPullParserTest extends TestCase { return new TextAttributeDescriptor( xmlName, // xmlLocalName SdkConstants.NS_RESOURCES, - new AttributeInfo(xmlName, new Format[] { Format.STRING }) + new AttributeInfo(xmlName, Format.STRING_SET) ); } -- cgit v1.1