summaryrefslogtreecommitdiff
path: root/tools/aapt2/java/JavaClassGenerator.cpp
diff options
context:
space:
mode:
authorRyan Mitchell <rtmitchell@google.com>2018-07-20 15:18:05 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-07-20 15:18:05 +0000
commit848585e1a41c52fb723d17fe5e9eb98956c614d6 (patch)
treef053b51de3834bc85f89e0b189a0191cbf837ff1 /tools/aapt2/java/JavaClassGenerator.cpp
parentbc458577c9e7f6a65aeccbe2c1a7a4d224ff399b (diff)
parent23cc5d5dbecf34c205af40761ca762f3258f341f (diff)
Merge "AAPT2: Fix R.java for styleable in different package"
Diffstat (limited to 'tools/aapt2/java/JavaClassGenerator.cpp')
-rw-r--r--tools/aapt2/java/JavaClassGenerator.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp
index db1561e17f16..d1a70a75a44e 100644
--- a/tools/aapt2/java/JavaClassGenerator.cpp
+++ b/tools/aapt2/java/JavaClassGenerator.cpp
@@ -256,9 +256,20 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res
styleable_attr.field_name =
TransformNestedAttr(attr.name.value(), array_field_name, package_name_to_generate);
+ Reference ref = attr;
+ if (attr.name.value().package.empty()) {
+
+ // If the resource does not have a package name, set the package to the unmangled package name
+ // of the styleable declaration because attributes without package names would have been
+ // declared in the same package as the styleable.
+ ref.name = ResourceName(package_name_to_generate, ref.name.value().type,
+ ref.name.value().entry);
+ }
+
// Look up the symbol so that we can write out in the comments what are possible legal values
// for this attribute.
- const SymbolTable::Symbol* symbol = context_->GetExternalSymbols()->FindByReference(attr);
+ const SymbolTable::Symbol* symbol = context_->GetExternalSymbols()->FindByReference(ref);
+
if (symbol && symbol->attribute) {
// Copy the symbol data structure because the returned instance can be destroyed.
styleable_attr.symbol = *symbol;
@@ -303,7 +314,7 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res
const ResourceName& attr_name = entry.attr_ref->name.value();
styleable_comment << "<tr><td><code>{@link #" << entry.field_name << " "
<< (!attr_name.package.empty() ? attr_name.package
- : context_->GetCompilationPackage())
+ : package_name_to_generate)
<< ":" << attr_name.entry << "}</code></td>";
// Only use the comment up until the first '.'. This is to stay compatible with
@@ -374,7 +385,7 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res
StringPiece package_name = attr_name.package;
if (package_name.empty()) {
- package_name = context_->GetCompilationPackage();
+ package_name = package_name_to_generate;
}
std::unique_ptr<IntMember> index_member =