From e967d3f6ac2e1e1f612f99b9c76abcb9e13bb7a2 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Mon, 24 Jul 2017 18:19:36 -0700 Subject: AAPT2: Fix JavaDoc first sentence extraction. The old algorithm for detecting the first sentence of a JavaDoc comment looked for the first occurence of '.'. This does not work when code or a {@link android.R.styleable} link is encountered in the first sentence. Switch to checking for whitespace characters after the '.' character. Bug: 62900335 Test: make aapt2_tests Change-Id: I8238f6a6304c9c2f92e2e576ca8962a59c2b20ea --- tools/aapt2/java/JavaClassGenerator.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'tools/aapt2/java/JavaClassGenerator.cpp') diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp index 2a23aa9e5372..44fa0f19a0e5 100644 --- a/tools/aapt2/java/JavaClassGenerator.cpp +++ b/tools/aapt2/java/JavaClassGenerator.cpp @@ -299,24 +299,16 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res } const ResourceName& attr_name = entry.attr_ref->name.value(); - styleable_comment << ""; - styleable_comment << "{@link #" << entry.field_name << " " - << (!attr_name.package.empty() - ? attr_name.package - : context_->GetCompilationPackage()) - << ":" << attr_name.entry << "}"; - styleable_comment << ""; - - styleable_comment << ""; + styleable_comment << "{@link #" << entry.field_name << " " + << (!attr_name.package.empty() ? attr_name.package + : context_->GetCompilationPackage()) + << ":" << attr_name.entry << "}"; // Only use the comment up until the first '.'. This is to stay compatible with // the way old AAPT did it (presumably to keep it short and to avoid including // annotations like @hide which would affect this Styleable). - auto iter = std::find(attr_comment_line.begin(), attr_comment_line.end(), '.'); - if (iter != attr_comment_line.end()) { - attr_comment_line = attr_comment_line.substr(0, (iter - attr_comment_line.begin()) + 1); - } - styleable_comment << attr_comment_line << "\n"; + styleable_comment << "" << AnnotationProcessor::ExtractFirstSentence(attr_comment_line) + << "\n"; } styleable_comment << "\n"; -- cgit v1.2.3 From 1ef0fa9d7242b1926543bc49e35905d1be02a781 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Tue, 15 Aug 2017 21:32:49 -0700 Subject: AAPT2: Fixup namespace implementation A few pieces were missing in the namespace mangling implementation. Namespace aware libraries now work, along with R class generation. Bug: 64706588 Test: make AaptTestNamespace_App Change-Id: I12f78d6aa909e782c0faf7ceaa36058f2e6c864a --- tools/aapt2/java/JavaClassGenerator.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tools/aapt2/java/JavaClassGenerator.cpp') diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp index 44fa0f19a0e5..8da9106aa8d7 100644 --- a/tools/aapt2/java/JavaClassGenerator.cpp +++ b/tools/aapt2/java/JavaClassGenerator.cpp @@ -480,7 +480,7 @@ Maybe JavaClassGenerator::UnmangleResource(const StringPiece& packa if (NameMangler::Unmangle(&unmangled_name, &unmangled_package)) { // The entry name was mangled, and we successfully unmangled it. // Check that we want to emit this symbol. - if (package_name != unmangled_package) { + if (package_name_to_generate != unmangled_package) { // Skip the entry if it doesn't belong to the package we're writing. return {}; } @@ -579,8 +579,7 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, continue; } - // Stay consistent with AAPT and generate an empty type class if the R class - // is public. + // Stay consistent with AAPT and generate an empty type class if the R class is public. const bool force_creation_if_empty = (options_.types == JavaClassGeneratorOptions::SymbolTypes::kPublic); -- cgit v1.2.3 From dc21dea9b8b1157a4a9347b68301da4307c51168 Mon Sep 17 00:00:00 2001 From: Adam Koski Date: Fri, 21 Jul 2017 10:55:27 -0700 Subject: AAPT2: Produce Conditional Proguard Keep Rules Add the option to produce keep rules that conditional keep based on usage of R identifiers. This allows Proguard to potentially shrink more code if resources are not used. Currently only produces conditional rules for classes referenced in layout resources because they are the most common and has the easiest transitive usage chain to analyze. Bug: 63628451 Test: make aapt2_tests and manual testing Change-Id: I6c1af7affd64af40c80e004d8506a9463444b2c3 --- tools/aapt2/java/JavaClassGenerator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools/aapt2/java/JavaClassGenerator.cpp') diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp index 8da9106aa8d7..3ba4dd880607 100644 --- a/tools/aapt2/java/JavaClassGenerator.cpp +++ b/tools/aapt2/java/JavaClassGenerator.cpp @@ -61,7 +61,7 @@ static bool IsValidSymbol(const StringPiece& symbol) { // Java symbols can not contain . or -, but those are valid in a resource name. // Replace those with '_'. -static std::string TransformToFieldName(const StringPiece& symbol) { +std::string JavaClassGenerator::TransformToFieldName(const StringPiece& symbol) { std::string output = symbol.to_string(); for (char& c : output) { if (c == '.' || c == '-') { @@ -89,9 +89,9 @@ static std::string TransformNestedAttr(const ResourceNameRef& attr_name, // the package. if (!attr_name.package.empty() && package_name_to_generate != attr_name.package) { - output += "_" + TransformToFieldName(attr_name.package); + output += "_" + JavaClassGenerator::TransformToFieldName(attr_name.package); } - output += "_" + TransformToFieldName(attr_name.entry); + output += "_" + JavaClassGenerator::TransformToFieldName(attr_name.entry); return output; } -- cgit v1.2.3 From 93190b79d11d874199cfe7258526a48cfc8399fc Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Fri, 3 Nov 2017 15:20:17 -0700 Subject: AAPT2: Better debugging output Test: make aapt2_tests Change-Id: I7778b773201381538dc1f2e376abee4eb33e44c0 --- tools/aapt2/java/JavaClassGenerator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/aapt2/java/JavaClassGenerator.cpp') diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp index 3ba4dd880607..91cef642fc3f 100644 --- a/tools/aapt2/java/JavaClassGenerator.cpp +++ b/tools/aapt2/java/JavaClassGenerator.cpp @@ -461,7 +461,7 @@ void JavaClassGenerator::ProcessResource(const ResourceNameRef& name, const Reso } if (out_rewrite_method != nullptr) { - const StringPiece& type_str = ToString(name.type); + const StringPiece& type_str = to_string(name.type); out_rewrite_method->AppendStatement(StringPrintf("%s.%s = (%s.%s & 0x00ffffff) | (p << 24);", type_str.data(), field_name.data(), type_str.data(), field_name.data())); @@ -584,7 +584,7 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, (options_.types == JavaClassGeneratorOptions::SymbolTypes::kPublic); std::unique_ptr class_def = util::make_unique( - ToString(type->type), ClassQualifier::kStatic, force_creation_if_empty); + to_string(type->type), ClassQualifier::kStatic, force_creation_if_empty); if (!ProcessType(package_name_to_generate, *package, *type, class_def.get(), rewrite_method.get(), out_r_txt)) { return false; -- cgit v1.2.3 From a693c4a32ebed4e96dcc1cf6a706e8ebbb004db2 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Thu, 9 Nov 2017 11:29:39 -0800 Subject: AAPT2: Move all file output to FileOutputStream FileOutputStream is safe to use on Windows, as it opens files using our compatibility API. Bug: 68262818 Test: make aapt2_tests Change-Id: Ib0b27e93edd609b49b1327db7d9867a002198ebb --- tools/aapt2/java/JavaClassGenerator.cpp | 83 ++++++++++++++++----------------- 1 file changed, 41 insertions(+), 42 deletions(-) (limited to 'tools/aapt2/java/JavaClassGenerator.cpp') diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp index 91cef642fc3f..9861770083a2 100644 --- a/tools/aapt2/java/JavaClassGenerator.cpp +++ b/tools/aapt2/java/JavaClassGenerator.cpp @@ -37,8 +37,10 @@ #include "java/ClassDefinition.h" #include "process/SymbolTable.h" -using android::StringPiece; -using android::base::StringPrintf; +using ::aapt::io::OutputStream; +using ::aapt::text::Printer; +using ::android::StringPiece; +using ::android::base::StringPrintf; namespace aapt { @@ -230,7 +232,7 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res const StringPiece& package_name_to_generate, ClassDefinition* out_class_def, MethodDefinition* out_rewrite_method, - std::ostream* out_r_txt) { + Printer* r_txt_printer) { const std::string array_field_name = TransformToFieldName(name.entry); std::unique_ptr array_def = util::make_unique(array_field_name); @@ -323,8 +325,8 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res array_def->GetCommentBuilder()->AppendComment(styleable_comment.str()); } - if (out_r_txt != nullptr) { - *out_r_txt << "int[] styleable " << array_field_name << " {"; + if (r_txt_printer != nullptr) { + r_txt_printer->Print("int[] styleable ").Print(array_field_name).Print(" {"); } // Add the ResourceIds to the array member. @@ -332,16 +334,16 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res const ResourceId id = sorted_attributes[i].attr_ref->id.value_or_default(ResourceId(0)); array_def->AddElement(id); - if (out_r_txt != nullptr) { + if (r_txt_printer != nullptr) { if (i != 0) { - *out_r_txt << ","; + r_txt_printer->Print(","); } - *out_r_txt << " " << id; + r_txt_printer->Print(" ").Print(id.to_string()); } } - if (out_r_txt != nullptr) { - *out_r_txt << " }\n"; + if (r_txt_printer != nullptr) { + r_txt_printer->Println(" }"); } // Add the Styleable array to the Styleable class. @@ -396,9 +398,9 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res attr_processor->AppendComment( StringPrintf("@attr name %s:%s", package_name.data(), attr_name.entry.data())); - if (out_r_txt != nullptr) { - *out_r_txt << StringPrintf("int styleable %s %d\n", sorted_attributes[i].field_name.data(), - (int)i); + if (r_txt_printer != nullptr) { + r_txt_printer->Println( + StringPrintf("int styleable %s %zd", sorted_attributes[i].field_name.c_str(), i)); } out_class_def->AddMember(std::move(index_member)); @@ -422,10 +424,12 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res void JavaClassGenerator::ProcessResource(const ResourceNameRef& name, const ResourceId& id, const ResourceEntry& entry, ClassDefinition* out_class_def, MethodDefinition* out_rewrite_method, - std::ostream* out_r_txt) { + text::Printer* r_txt_printer) { ResourceId real_id = id; if (context_->GetMinSdkVersion() < SDK_O && name.type == ResourceType::kId && id.package_id() > kAppPackageId) { + // Workaround for feature splits using package IDs > 0x7F. + // See b/37498913. real_id = ResourceId(kAppPackageId, id.package_id(), id.entry_id()); } @@ -456,8 +460,13 @@ void JavaClassGenerator::ProcessResource(const ResourceNameRef& name, const Reso out_class_def->AddMember(std::move(resource_member)); - if (out_r_txt != nullptr) { - *out_r_txt << "int " << name.type << " " << field_name << " " << real_id << "\n"; + if (r_txt_printer != nullptr) { + r_txt_printer->Print("int ") + .Print(to_string(name.type)) + .Print(" ") + .Print(field_name) + .Print(" ") + .Println(real_id.to_string()); } if (out_rewrite_method != nullptr) { @@ -497,7 +506,7 @@ bool JavaClassGenerator::ProcessType(const StringPiece& package_name_to_generate const ResourceTableType& type, ClassDefinition* out_type_class_def, MethodDefinition* out_rewrite_method_def, - std::ostream* out_r_txt) { + Printer* r_txt_printer) { for (const auto& entry : type.entries) { const Maybe unmangled_name = UnmangleResource(package.name, package_name_to_generate, *entry); @@ -532,18 +541,18 @@ bool JavaClassGenerator::ProcessType(const StringPiece& package_name_to_generate static_cast(entry->values.front()->value.get()); ProcessStyleable(resource_name, id, *styleable, package_name_to_generate, out_type_class_def, - out_rewrite_method_def, out_r_txt); + out_rewrite_method_def, r_txt_printer); } else { ProcessResource(resource_name, id, *entry, out_type_class_def, out_rewrite_method_def, - out_r_txt); + r_txt_printer); } } return true; } -bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, std::ostream* out, - std::ostream* out_r_txt) { - return Generate(package_name_to_generate, package_name_to_generate, out); +bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, OutputStream* out, + OutputStream* out_r_txt) { + return Generate(package_name_to_generate, package_name_to_generate, out, out_r_txt); } static void AppendJavaDocAnnotations(const std::vector& annotations, @@ -556,11 +565,16 @@ static void AppendJavaDocAnnotations(const std::vector& annotations } bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, - const StringPiece& out_package_name, std::ostream* out, - std::ostream* out_r_txt) { + const StringPiece& out_package_name, OutputStream* out, + OutputStream* out_r_txt) { ClassDefinition r_class("R", ClassQualifier::kNone, true); std::unique_ptr rewrite_method; + std::unique_ptr r_txt_printer; + if (out_r_txt != nullptr) { + r_txt_printer = util::make_unique(out_r_txt); + } + // Generate an onResourcesLoaded() callback if requested. if (options_.rewrite_callback_options) { rewrite_method = @@ -586,7 +600,7 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, std::unique_ptr class_def = util::make_unique( to_string(type->type), ClassQualifier::kStatic, force_creation_if_empty); if (!ProcessType(package_name_to_generate, *package, *type, class_def.get(), - rewrite_method.get(), out_r_txt)) { + rewrite_method.get(), r_txt_printer.get())) { return false; } @@ -595,7 +609,7 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, const ResourceTableType* priv_type = package->FindType(ResourceType::kAttrPrivate); if (priv_type) { if (!ProcessType(package_name_to_generate, *package, *priv_type, class_def.get(), - rewrite_method.get(), out_r_txt)) { + rewrite_method.get(), r_txt_printer.get())) { return false; } } @@ -619,22 +633,7 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, } AppendJavaDocAnnotations(options_.javadoc_annotations, r_class.GetCommentBuilder()); - - if (!ClassDefinition::WriteJavaFile(&r_class, out_package_name, options_.use_final, out)) { - return false; - } - - out->flush(); - - if (out_r_txt != nullptr) { - out_r_txt->flush(); - - if (!*out_r_txt) { - error_ = android::base::SystemErrorCodeToString(errno); - return false; - } - } - + ClassDefinition::WriteJavaFile(&r_class, out_package_name, options_.use_final, out); return true; } -- cgit v1.2.3 From 23a6e1e3901e1ef1e2bd5ebb2aff08b767d19c49 Mon Sep 17 00:00:00 2001 From: Izabela Orlowska Date: Tue, 5 Dec 2017 14:52:07 +0000 Subject: AAPT2: allow to generate R.txt without R.java Bug: 69956357 Test: manual Change-Id: If2bc32bd4efb1ea17c6cba7a17f2b2300164ede0 --- tools/aapt2/java/JavaClassGenerator.cpp | 141 +++++++++++++++++--------------- 1 file changed, 76 insertions(+), 65 deletions(-) (limited to 'tools/aapt2/java/JavaClassGenerator.cpp') diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp index 9861770083a2..8c8c2549609a 100644 --- a/tools/aapt2/java/JavaClassGenerator.cpp +++ b/tools/aapt2/java/JavaClassGenerator.cpp @@ -272,7 +272,7 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res // Build the JavaDoc comment for the Styleable array. This has references to child attributes // and what possible values can be used for them. const size_t attr_count = sorted_attributes.size(); - if (attr_count > 0) { + if (out_class_def != nullptr && attr_count > 0) { std::stringstream styleable_comment; if (!styleable.GetComment().empty()) { styleable_comment << styleable.GetComment() << "\n"; @@ -356,54 +356,56 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res continue; } - StringPiece comment = styleable_attr.attr_ref->GetComment(); - if (styleable_attr.symbol.value().attribute && comment.empty()) { - comment = styleable_attr.symbol.value().attribute->GetComment(); - } + if (out_class_def != nullptr) { + StringPiece comment = styleable_attr.attr_ref->GetComment(); + if (styleable_attr.symbol.value().attribute && comment.empty()) { + comment = styleable_attr.symbol.value().attribute->GetComment(); + } - if (comment.contains("@removed")) { - // Removed attributes are public but hidden from the documentation, so - // don't emit them as part of the class documentation. - continue; - } + if (comment.contains("@removed")) { + // Removed attributes are public but hidden from the documentation, so + // don't emit them as part of the class documentation. + continue; + } - const ResourceName& attr_name = styleable_attr.attr_ref->name.value(); + const ResourceName& attr_name = styleable_attr.attr_ref->name.value(); - StringPiece package_name = attr_name.package; - if (package_name.empty()) { - package_name = context_->GetCompilationPackage(); - } + StringPiece package_name = attr_name.package; + if (package_name.empty()) { + package_name = context_->GetCompilationPackage(); + } - std::unique_ptr index_member = util::make_unique( - sorted_attributes[i].field_name, static_cast(i)); + std::unique_ptr index_member = + util::make_unique(sorted_attributes[i].field_name, static_cast(i)); + + AnnotationProcessor* attr_processor = index_member->GetCommentBuilder(); + + if (!comment.empty()) { + attr_processor->AppendComment("

\n@attr description"); + attr_processor->AppendComment(comment); + } else { + std::stringstream default_comment; + default_comment << "

This symbol is the offset where the " + << "{@link " << package_name << ".R.attr#" + << TransformToFieldName(attr_name.entry) << "}\n" + << "attribute's value can be found in the " + << "{@link #" << array_field_name << "} array."; + attr_processor->AppendComment(default_comment.str()); + } - AnnotationProcessor* attr_processor = index_member->GetCommentBuilder(); + attr_processor->AppendNewLine(); + AddAttributeFormatDoc(attr_processor, styleable_attr.symbol.value().attribute.get()); + attr_processor->AppendNewLine(); + attr_processor->AppendComment( + StringPrintf("@attr name %s:%s", package_name.data(), attr_name.entry.data())); - if (!comment.empty()) { - attr_processor->AppendComment("

\n@attr description"); - attr_processor->AppendComment(comment); - } else { - std::stringstream default_comment; - default_comment << "

This symbol is the offset where the " - << "{@link " << package_name << ".R.attr#" - << TransformToFieldName(attr_name.entry) << "}\n" - << "attribute's value can be found in the " - << "{@link #" << array_field_name << "} array."; - attr_processor->AppendComment(default_comment.str()); + out_class_def->AddMember(std::move(index_member)); } - attr_processor->AppendNewLine(); - AddAttributeFormatDoc(attr_processor, styleable_attr.symbol.value().attribute.get()); - attr_processor->AppendNewLine(); - attr_processor->AppendComment( - StringPrintf("@attr name %s:%s", package_name.data(), attr_name.entry.data())); - if (r_txt_printer != nullptr) { r_txt_printer->Println( StringPrintf("int styleable %s %zd", sorted_attributes[i].field_name.c_str(), i)); } - - out_class_def->AddMember(std::move(index_member)); } // If there is a rewrite method to generate, add the statements that rewrite package IDs @@ -434,31 +436,33 @@ void JavaClassGenerator::ProcessResource(const ResourceNameRef& name, const Reso } const std::string field_name = TransformToFieldName(name.entry); - std::unique_ptr resource_member = - util::make_unique(field_name, real_id); + if (out_class_def != nullptr) { + std::unique_ptr resource_member = + util::make_unique(field_name, real_id); - // Build the comments and annotations for this entry. - AnnotationProcessor* processor = resource_member->GetCommentBuilder(); + // Build the comments and annotations for this entry. + AnnotationProcessor* processor = resource_member->GetCommentBuilder(); - // Add the comments from any tags. - if (entry.symbol_status.state != SymbolState::kUndefined) { - processor->AppendComment(entry.symbol_status.comment); - } + // Add the comments from any tags. + if (entry.symbol_status.state != SymbolState::kUndefined) { + processor->AppendComment(entry.symbol_status.comment); + } - // Add the comments from all configurations of this entry. - for (const auto& config_value : entry.values) { - processor->AppendComment(config_value->value->GetComment()); - } + // Add the comments from all configurations of this entry. + for (const auto& config_value : entry.values) { + processor->AppendComment(config_value->value->GetComment()); + } - // If this is an Attribute, append the format Javadoc. - if (!entry.values.empty()) { - if (Attribute* attr = ValueCast(entry.values.front()->value.get())) { - // We list out the available values for the given attribute. - AddAttributeFormatDoc(processor, attr); + // If this is an Attribute, append the format Javadoc. + if (!entry.values.empty()) { + if (Attribute* attr = ValueCast(entry.values.front()->value.get())) { + // We list out the available values for the given attribute. + AddAttributeFormatDoc(processor, attr); + } } - } - out_class_def->AddMember(std::move(resource_member)); + out_class_def->AddMember(std::move(resource_member)); + } if (r_txt_printer != nullptr) { r_txt_printer->Print("int ") @@ -576,7 +580,7 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, } // Generate an onResourcesLoaded() callback if requested. - if (options_.rewrite_callback_options) { + if (out != nullptr && options_.rewrite_callback_options) { rewrite_method = util::make_unique("public static void onResourcesLoaded(int p)"); for (const std::string& package_to_callback : @@ -597,8 +601,12 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, const bool force_creation_if_empty = (options_.types == JavaClassGeneratorOptions::SymbolTypes::kPublic); - std::unique_ptr class_def = util::make_unique( - to_string(type->type), ClassQualifier::kStatic, force_creation_if_empty); + std::unique_ptr class_def; + if (out != nullptr) { + class_def = util::make_unique( + to_string(type->type), ClassQualifier::kStatic, force_creation_if_empty); + } + if (!ProcessType(package_name_to_generate, *package, *type, class_def.get(), rewrite_method.get(), r_txt_printer.get())) { return false; @@ -615,16 +623,17 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, } } - if (type->type == ResourceType::kStyleable && + if (out != nullptr && type->type == ResourceType::kStyleable && options_.types == JavaClassGeneratorOptions::SymbolTypes::kPublic) { // When generating a public R class, we don't want Styleable to be part // of the API. It is only emitted for documentation purposes. class_def->GetCommentBuilder()->AppendComment("@doconly"); } - AppendJavaDocAnnotations(options_.javadoc_annotations, class_def->GetCommentBuilder()); - - r_class.AddMember(std::move(class_def)); + if (out != nullptr) { + AppendJavaDocAnnotations(options_.javadoc_annotations, class_def->GetCommentBuilder()); + r_class.AddMember(std::move(class_def)); + } } } @@ -632,8 +641,10 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, r_class.AddMember(std::move(rewrite_method)); } - AppendJavaDocAnnotations(options_.javadoc_annotations, r_class.GetCommentBuilder()); - ClassDefinition::WriteJavaFile(&r_class, out_package_name, options_.use_final, out); + if (out != nullptr) { + AppendJavaDocAnnotations(options_.javadoc_annotations, r_class.GetCommentBuilder()); + ClassDefinition::WriteJavaFile(&r_class, out_package_name, options_.use_final, out); + } return true; } -- cgit v1.2.3 From 71be70507de9cb619b644e55eda1cc181e3f7e90 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Tue, 12 Dec 2017 16:48:07 -0800 Subject: AAPT2: Propagate SPEC_OVERLAYABLE flag to final APK Resources can be marked as overlayable, which means they can be overlaid by runtime resource overlays. This change propagates this state to the final resource table that is installed on device. Future work: - Have the idmap tool respect the overlayable state and ignore entries that overlay anything else. Bug: 64980941 Test: make aapt2_tests Change-Id: Id45b1e141a281be2ee32a4ac3096fcf1114d523b --- tools/aapt2/java/JavaClassGenerator.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tools/aapt2/java/JavaClassGenerator.cpp') diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp index 8c8c2549609a..6b07b1e96261 100644 --- a/tools/aapt2/java/JavaClassGenerator.cpp +++ b/tools/aapt2/java/JavaClassGenerator.cpp @@ -191,14 +191,14 @@ JavaClassGenerator::JavaClassGenerator(IAaptContext* context, const JavaClassGeneratorOptions& options) : context_(context), table_(table), options_(options) {} -bool JavaClassGenerator::SkipSymbol(SymbolState state) { +bool JavaClassGenerator::SkipSymbol(Visibility::Level level) { switch (options_.types) { case JavaClassGeneratorOptions::SymbolTypes::kAll: return false; case JavaClassGeneratorOptions::SymbolTypes::kPublicPrivate: - return state == SymbolState::kUndefined; + return level == Visibility::Level::kUndefined; case JavaClassGeneratorOptions::SymbolTypes::kPublic: - return state != SymbolState::kPublic; + return level != Visibility::Level::kPublic; } return true; } @@ -444,8 +444,8 @@ void JavaClassGenerator::ProcessResource(const ResourceNameRef& name, const Reso AnnotationProcessor* processor = resource_member->GetCommentBuilder(); // Add the comments from any tags. - if (entry.symbol_status.state != SymbolState::kUndefined) { - processor->AppendComment(entry.symbol_status.comment); + if (entry.visibility.level != Visibility::Level::kUndefined) { + processor->AppendComment(entry.visibility.comment); } // Add the comments from all configurations of this entry. @@ -484,7 +484,7 @@ void JavaClassGenerator::ProcessResource(const ResourceNameRef& name, const Reso Maybe JavaClassGenerator::UnmangleResource(const StringPiece& package_name, const StringPiece& package_name_to_generate, const ResourceEntry& entry) { - if (SkipSymbol(entry.symbol_status.state)) { + if (SkipSymbol(entry.visibility.level)) { return {}; } -- cgit v1.2.3