summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceValues.h
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2017-05-30 15:15:58 -0700
committerAdam Lesinski <adamlesinski@google.com>2017-05-31 10:09:06 -0700
commit5924d8c9ab7bd8614e8bd99864903ce9d50f3bf7 (patch)
treef094afb0142ab4a81faff62f37be306ca0587c33 /tools/aapt2/ResourceValues.h
parentbacaffa497de1877657f9cb3f59a82e3955f0f75 (diff)
AAPT2: Allow merging of Style attributes from overlays
Previously style overlays would completely override an existing style. To be compatible with AAPT, styles now merge with the overlay, allowing the overlay's attributes and parent to take precedence. Bug: 38355988 Test: make aapt2_tests Change-Id: Id25c7240050a43e6a4a177c6e3d51e048d0cceb5
Diffstat (limited to 'tools/aapt2/ResourceValues.h')
-rw-r--r--tools/aapt2/ResourceValues.h32
1 files changed, 19 insertions, 13 deletions
diff --git a/tools/aapt2/ResourceValues.h b/tools/aapt2/ResourceValues.h
index 06f949f9555c..ac5795fb9774 100644
--- a/tools/aapt2/ResourceValues.h
+++ b/tools/aapt2/ResourceValues.h
@@ -40,7 +40,8 @@ struct RawValueVisitor;
// type specific operations is to check the Value's type() and
// cast it to the appropriate subclass. This isn't super clean,
// but it is the simplest strategy.
-struct Value {
+class Value {
+ public:
virtual ~Value() = default;
// Whether this value is weak and can be overridden without warning or error. Default is false.
@@ -82,6 +83,8 @@ struct Value {
// Human readable printout of this value.
virtual void Print(std::ostream* out) const = 0;
+ friend std::ostream& operator<<(std::ostream& out, const Value& value);
+
protected:
Source source_;
std::string comment_;
@@ -245,6 +248,8 @@ struct Attribute : public BaseValue<Attribute> {
struct Symbol {
Reference symbol;
uint32_t value;
+
+ friend std::ostream& operator<<(std::ostream& out, const Symbol& symbol);
};
uint32_t type_mask;
@@ -266,6 +271,8 @@ struct Style : public BaseValue<Style> {
struct Entry {
Reference key;
std::unique_ptr<Item> value;
+
+ friend std::ostream& operator<<(std::ostream& out, const Entry& entry);
};
Maybe<Reference> parent;
@@ -278,6 +285,10 @@ struct Style : public BaseValue<Style> {
bool Equals(const Value* value) const override;
Style* Clone(StringPool* new_pool) const override;
void Print(std::ostream* out) const override;
+
+ // Merges `style` into this Style. All identical attributes of `style` take precedence, including
+ // the parent, if there is one.
+ void MergeWith(Style* style, StringPool* pool);
};
struct Array : public BaseValue<Array> {
@@ -307,20 +318,15 @@ struct Styleable : public BaseValue<Styleable> {
void MergeWith(Styleable* styleable);
};
-// Stream operator for printing Value objects.
-inline ::std::ostream& operator<<(::std::ostream& out, const Value& value) {
- value.Print(&out);
- return out;
-}
-
-inline ::std::ostream& operator<<(::std::ostream& out,
- const Attribute::Symbol& s) {
- if (s.symbol.name) {
- out << s.symbol.name.value().entry;
+template <typename T>
+typename std::enable_if<std::is_base_of<Value, T>::value, std::ostream&>::type operator<<(
+ std::ostream& out, const std::unique_ptr<T>& value) {
+ if (value == nullptr) {
+ out << "NULL";
} else {
- out << "???";
+ value->Print(&out);
}
- return out << "=" << s.value;
+ return out;
}
} // namespace aapt