aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common
diff options
context:
space:
mode:
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java6
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java13
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/AttributeInfo.java11
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/AttrsXmlParser.java63
4 files changed, 62 insertions, 31 deletions
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<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) {
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<Format> 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<Format> 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<Format> 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<Format> 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<String, DeclareStyleableInfo> mStyleMap =
new HashMap<String, DeclareStyleableInfo>();
+ /** Map from format name (lower case) to the uppercase version */
+ private Map<String, Format> mFormatNames = new HashMap<String, Format>(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<String, Map<String,Integer>>(
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<AttributeInfo.Format> formats = new TreeSet<AttributeInfo.Format>();
+ EnumSet<Format> 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 <attr name=\"%s\">, 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 <attr> have <enum> 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 <attr> have <flag> 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;