aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources
diff options
context:
space:
mode:
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources')
-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
2 files changed, 53 insertions, 21 deletions
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;