From 925fd546efd612bdaab7187404f15a2771fff46d Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 9 May 2016 15:52:27 +0000 Subject: 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 --- .../android/xml/StyleableXmlResourceValue.java | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/tools/android/java/com/google/devtools/build/android/xml/StyleableXmlResourceValue.java') 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.builder().addAll(attrs).addAll(styleable.attrs).build())); + } } -- cgit v1.2.3