diff options
author | Googler <noreply@google.com> | 2016-05-09 15:52:27 +0000 |
---|---|---|
committer | Klaus Aehlig <aehlig@google.com> | 2016-05-10 07:55:57 +0000 |
commit | 925fd546efd612bdaab7187404f15a2771fff46d (patch) | |
tree | a58f3ba20c39b4268a027ace6f8d0b1598c29035 /src/tools/android/java/com/google/devtools/build/android/xml | |
parent | ec2657fbbc0a360ef52cef2496e25cdf967aaf92 (diff) |
4.99 of 5: Fix styleable combining.
Changes non-overwriting resources (id and styleable) to combine on duplication. This change ignores the issue of multiple sources, which will be addressed in a later cl.
--
MOS_MIGRATED_REVID=121840285
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/xml')
7 files changed, 59 insertions, 0 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java index 4e26ec9993..0a07a5daad 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java @@ -169,6 +169,11 @@ public class ArrayXmlResourceValue implements XmlResourceValue { .toString(); } + @Override + public XmlResourceValue combineWith(XmlResourceValue value) { + throw new IllegalArgumentException(this + " is not a combinable resource."); + } + public static XmlResourceValue parseArray(XMLEventReader eventReader, StartElement start) throws XMLStreamException { List<String> values = new ArrayList<>(); diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/AttrXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/AttrXmlResourceValue.java index ab2e314af0..07b8855f4b 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/AttrXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/AttrXmlResourceValue.java @@ -322,6 +322,11 @@ public class AttrXmlResourceValue implements XmlResourceValue { return XmlResourceValues.serializeProtoDataValue(output, builder); } + @Override + public XmlResourceValue combineWith(XmlResourceValue value) { + throw new IllegalArgumentException(this + " is not a combinable resource."); + } + @CheckReturnValue interface ResourceXmlAttrValue { FluentIterable<String> appendTo(FluentIterable<String> iterable); diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/IdXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/IdXmlResourceValue.java index 05fe8729c0..65e31619ee 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/IdXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/IdXmlResourceValue.java @@ -73,4 +73,12 @@ public class IdXmlResourceValue implements XmlResourceValue { public String toString() { return MoreObjects.toStringHelper(getClass()).toString(); } + + @Override + public XmlResourceValue combineWith(XmlResourceValue value) { + if (value != SINGLETON) { + throw new IllegalArgumentException(value + "is not combinable with " + this); + } + return this; + } } diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/PluralXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/PluralXmlResourceValue.java index 4a814138e8..1c8eee88fb 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/PluralXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/PluralXmlResourceValue.java @@ -122,4 +122,9 @@ public class PluralXmlResourceValue implements XmlResourceValue { return CodedOutputStream.computeUInt32SizeNoTag(value.getSerializedSize()) + value.getSerializedSize(); } + + @Override + public XmlResourceValue combineWith(XmlResourceValue value) { + throw new IllegalArgumentException(this + " is not a combinable resource."); + } } diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java index f618eb5004..9169401c21 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java @@ -272,4 +272,9 @@ public class SimpleXmlResourceValue implements XmlResourceValue { .add("value", value) .toString(); } + + @Override + public XmlResourceValue combineWith(XmlResourceValue value) { + throw new IllegalArgumentException(this + " is not a combinable resource."); + } } diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/StyleXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/StyleXmlResourceValue.java index a7e07d6b56..008696d86e 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/StyleXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/StyleXmlResourceValue.java @@ -139,4 +139,9 @@ public class StyleXmlResourceValue implements XmlResourceValue { .add("values", values) .toString(); } + + @Override + public XmlResourceValue combineWith(XmlResourceValue value) { + throw new IllegalArgumentException(this + " is not a combinable resource."); + } } diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/StyleableXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/StyleableXmlResourceValue.java index bed3536c80..47da07fc26 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/StyleableXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/StyleableXmlResourceValue.java @@ -18,6 +18,7 @@ import com.google.common.base.Function; import com.google.common.base.MoreObjects; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Ordering; import com.google.devtools.build.android.AndroidDataWritingVisitor; import com.google.devtools.build.android.FullyQualifiedName; @@ -131,4 +132,29 @@ public class StyleableXmlResourceValue implements XmlResourceValue { public String toString() { return MoreObjects.toStringHelper(getClass()).add("attrs", attrs).toString(); } + + /** + * Combines this instance with another {@link StyleableXmlResourceValue}. + * + * Defining two Styleables (undocumented in the official Android Docs) with the same + * {@link FullyQualifiedName} results in a single Styleable containing a union of all the + * attribute references. + * + * @param value Another {@link StyleableXmlResourceValue} with the same {@link FullyQualifiedName} + * . + * @return {@link StyleableXmlResourceValue} containing a sorted union of the attribute + * references. + * @throws IllegalArgumentException if value is not an {@link StyleableXmlResourceValue}. + */ + @Override + public XmlResourceValue combineWith(XmlResourceValue value) { + if (!(value instanceof StyleableXmlResourceValue)) { + throw new IllegalArgumentException(value + "is not combinable with " + this); + } + StyleableXmlResourceValue styleable = (StyleableXmlResourceValue) value; + return of( + Ordering.natural() + .sortedCopy( + ImmutableSet.<String>builder().addAll(attrs).addAll(styleable.attrs).build())); + } } |