aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-08-16 13:48:27 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2016-08-17 11:23:30 +0000
commit114c62b5808af78ed78722682351a2d34ff1d0b6 (patch)
treed3772e7b6c31c14f7ed93f15248f59bec50bfe45 /src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java
parent29e910b0a637275d33aca40ad620961d4f32a529 (diff)
Handle public tags in merger -> R.class writer
Developers do use public tags, and before this change it would assert in the AndroidResourceClassWriter as an unhandled ResourceType. We probably didn't want to write out a R.public.field anyway. Also, handle public tags with the same name, but different type. They get mapped to the same FQN, so use the combining mechanism to keep track of the different types and ids. -- MOS_MIGRATED_REVID=130395089
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java')
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java b/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java
index 1caaff264f..7bda269b58 100644
--- a/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java
+++ b/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java
@@ -13,7 +13,9 @@
// limitations under the License.
package com.google.devtools.build.android;
+import com.android.SdkConstants;
import com.android.resources.ResourceType;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.android.ParsedAndroidData.KeyValueConsumer;
@@ -22,6 +24,7 @@ import com.google.devtools.build.android.xml.AttrXmlResourceValue;
import com.google.devtools.build.android.xml.IdXmlResourceValue;
import com.google.devtools.build.android.xml.Namespaces;
import com.google.devtools.build.android.xml.PluralXmlResourceValue;
+import com.google.devtools.build.android.xml.PublicXmlResourceValue;
import com.google.devtools.build.android.xml.SimpleXmlResourceValue;
import com.google.devtools.build.android.xml.StyleXmlResourceValue;
import com.google.devtools.build.android.xml.StyleableXmlResourceValue;
@@ -206,6 +209,47 @@ public class XmlResourceValues {
contents);
}
+ static XmlResourceValue parsePublic(
+ XMLEventReader eventReader, StartElement start, Namespaces.Collector namespacesCollector)
+ throws XMLStreamException {
+ namespacesCollector.collectFrom(start);
+ // The tag should be unary.
+ if (!isEndTag(eventReader.peek(), start.getName())) {
+ throw new XMLStreamException(
+ String.format("<public> tag should be unary %s", start), start.getLocation());
+ }
+ // The tag should have a valid type attribute, and optionally an id attribute.
+ ImmutableMap<String, String> attributes = ImmutableMap.copyOf(parseTagAttributes(start));
+ String typeAttr = attributes.get(SdkConstants.ATTR_TYPE);
+ ResourceType type;
+ if (typeAttr != null) {
+ type = ResourceType.getEnum(typeAttr);
+ if (type == null || type == ResourceType.PUBLIC) {
+ throw new XMLStreamException(
+ String.format("<public> tag has invalid type attribute %s", start),
+ start.getLocation());
+ }
+ } else {
+ throw new XMLStreamException(
+ String.format("<public> tag missing type attribute %s", start), start.getLocation());
+ }
+ String idValueAttr = attributes.get(SdkConstants.ATTR_ID);
+ Optional<Integer> id = Optional.absent();
+ if (idValueAttr != null) {
+ try {
+ id = Optional.of(Integer.decode(idValueAttr));
+ } catch (NumberFormatException e) {
+ throw new XMLStreamException(
+ String.format("<public> has invalid id number %s", start), start.getLocation());
+ }
+ }
+ if (attributes.size() > 2) {
+ throw new XMLStreamException(
+ String.format("<public> has unexpected attributes %s", start), start.getLocation());
+ }
+ return PublicXmlResourceValue.create(type, id);
+ }
+
public static Map<String, String> parseTagAttributes(StartElement start) {
// Using a map to deduplicate xmlns declarations on the attributes.
Map<String, String> attributeMap = new LinkedHashMap<>();