From cf623c32ee369efbced6f1558eb07d5979213228 Mon Sep 17 00:00:00 2001 From: apell Date: Wed, 24 May 2017 18:42:42 +0200 Subject: Fix bug with combining resource attributes. Attributes were reporting that they were over-writable in all cases instead of differentiating by attribute type. RELNOTES: None. PiperOrigin-RevId: 156999284 --- .../google/devtools/build/android/FullyQualifiedName.java | 12 ++++++++---- .../devtools/build/android/xml/ResourcesAttribute.java | 13 ++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java b/src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java index 836239d6be..938627afa5 100644 --- a/src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java +++ b/src/tools/android/java/com/google/devtools/build/android/FullyQualifiedName.java @@ -25,6 +25,7 @@ import com.google.common.collect.ImmutableList.Builder; import com.google.common.collect.Iterators; import com.google.common.collect.PeekingIterator; import com.google.devtools.build.android.proto.SerializeFormat; +import com.google.devtools.build.android.xml.ResourcesAttribute; import java.io.IOException; import java.io.OutputStream; import java.nio.file.Path; @@ -63,7 +64,7 @@ public class FullyQualifiedName implements DataKey { public String getName(); public ConcreteType getType(); - public boolean isOverwritable(); + public boolean isOverwritable(FullyQualifiedName fqn); public int compareTo(Type other); @Override public boolean equals(Object obj); @Override public int hashCode(); @@ -99,7 +100,7 @@ public class FullyQualifiedName implements DataKey { } @Override - public boolean isOverwritable() { + public boolean isOverwritable(FullyQualifiedName fqn) { return !(resourceType == ResourceType.ID || resourceType == ResourceType.PUBLIC || resourceType == ResourceType.STYLEABLE); @@ -182,7 +183,10 @@ public class FullyQualifiedName implements DataKey { } @Override - public boolean isOverwritable() { + public boolean isOverwritable(FullyQualifiedName fqn) { + if (this == RESOURCES_ATTRIBUTE) { + return !ResourcesAttribute.AttributeType.from(fqn.name()).isCombining(); + } return true; } @@ -531,7 +535,7 @@ public class FullyQualifiedName implements DataKey { } public boolean isOverwritable() { - return type.isOverwritable(); + return type.isOverwritable(this); } /** Creates a FullyQualifiedName from this one with a different package. */ diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/ResourcesAttribute.java b/src/tools/android/java/com/google/devtools/build/android/xml/ResourcesAttribute.java index 9202d599b5..a54667ecdb 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/ResourcesAttribute.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/ResourcesAttribute.java @@ -48,7 +48,11 @@ public class ResourcesAttribute implements XmlResourceValue { } }; - private static enum AttributeType { + /** + * Represents the semantic meaning of an xml attribute and how it is combined with other + * attributes of the same type. + */ + public static enum AttributeType { UNCOMBINABLE(null, null), TOOLS_IGNORE("{http://schemas.android.com/tools}ignore", COMMA_SEPARATED_COMBINER), TOOLS_MENU("{http://schemas.android.com/tools}menu", COMMA_SEPARATED_COMBINER), @@ -74,6 +78,10 @@ public class ResourcesAttribute implements XmlResourceValue { this.name = name; this.combiner = combiner; } + + public boolean isCombining() { + return this != UNCOMBINABLE; + } } public static ResourcesAttribute of(FullyQualifiedName fqn, String name, String value) { @@ -94,7 +102,6 @@ public class ResourcesAttribute implements XmlResourceValue { private final String value; private ResourcesAttribute(AttributeType type, String name, String value) { - this.type = type; this.name = name; this.value = value; @@ -148,7 +155,7 @@ public class ResourcesAttribute implements XmlResourceValue { } public boolean isCombining() { - return type != AttributeType.UNCOMBINABLE; + return type.isCombining(); } @Override -- cgit v1.2.3