Loading tools/aapt2/cmd/Link.cpp +20 −23 Original line number Diff line number Diff line Loading @@ -1069,26 +1069,30 @@ class LinkCommand { bool WriteJavaFile(ResourceTable* table, const StringPiece& package_name_to_generate, const StringPiece& out_package, const JavaClassGeneratorOptions& java_options, const Maybe<std::string>& out_text_symbols_path = {}) { if (!options_.generate_java_class_path) { if (!options_.generate_java_class_path && !out_text_symbols_path) { return true; } std::string out_path = options_.generate_java_class_path.value(); std::string out_path; std::unique_ptr<io::FileOutputStream> fout; if (options_.generate_java_class_path) { out_path = options_.generate_java_class_path.value(); file::AppendPath(&out_path, file::PackageToPath(out_package)); if (!file::mkdirs(out_path)) { context_->GetDiagnostics()->Error(DiagMessage() << "failed to create directory '" << out_path << "'"); context_->GetDiagnostics()->Error(DiagMessage() << "failed to create directory '" << out_path << "'"); return false; } file::AppendPath(&out_path, "R.java"); io::FileOutputStream fout(out_path); if (fout.HadError()) { fout = util::make_unique<io::FileOutputStream>(out_path); if (fout->HadError()) { context_->GetDiagnostics()->Error(DiagMessage() << "failed writing to '" << out_path << "': " << fout.GetError()); << "': " << fout->GetError()); return false; } } std::unique_ptr<io::FileOutputStream> fout_text; if (out_text_symbols_path) { Loading @@ -1102,18 +1106,11 @@ class LinkCommand { } JavaClassGenerator generator(context_, table, java_options); if (!generator.Generate(package_name_to_generate, out_package, &fout, fout_text.get())) { if (!generator.Generate(package_name_to_generate, out_package, fout.get(), fout_text.get())) { context_->GetDiagnostics()->Error(DiagMessage(out_path) << generator.GetError()); return false; } fout.Flush(); if (fout.HadError()) { context_->GetDiagnostics()->Error(DiagMessage() << "failed writing to '" << out_path << "': " << fout.GetError()); return false; } return true; } Loading Loading @@ -1934,7 +1931,7 @@ class LinkCommand { return 1; } if (options_.generate_java_class_path) { if (options_.generate_java_class_path || options_.generate_text_symbols_path) { if (!GenerateJavaClasses()) { return 1; } Loading tools/aapt2/java/JavaClassGenerator.cpp +76 −65 Original line number Diff line number Diff line Loading @@ -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"; Loading Loading @@ -356,6 +356,7 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res continue; } 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(); Loading @@ -374,8 +375,8 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res package_name = context_->GetCompilationPackage(); } std::unique_ptr<IntMember> index_member = util::make_unique<IntMember>( sorted_attributes[i].field_name, static_cast<uint32_t>(i)); std::unique_ptr<IntMember> index_member = util::make_unique<IntMember>(sorted_attributes[i].field_name, static_cast<uint32_t>(i)); AnnotationProcessor* attr_processor = index_member->GetCommentBuilder(); Loading @@ -398,12 +399,13 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res attr_processor->AppendComment( StringPrintf("@attr name %s:%s", package_name.data(), attr_name.entry.data())); out_class_def->AddMember(std::move(index_member)); } 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 Loading Loading @@ -434,6 +436,7 @@ void JavaClassGenerator::ProcessResource(const ResourceNameRef& name, const Reso } const std::string field_name = TransformToFieldName(name.entry); if (out_class_def != nullptr) { std::unique_ptr<ResourceMember> resource_member = util::make_unique<ResourceMember>(field_name, real_id); Loading @@ -459,6 +462,7 @@ void JavaClassGenerator::ProcessResource(const ResourceNameRef& name, const Reso } out_class_def->AddMember(std::move(resource_member)); } if (r_txt_printer != nullptr) { r_txt_printer->Print("int ") Loading Loading @@ -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<MethodDefinition>("public static void onResourcesLoaded(int p)"); for (const std::string& package_to_callback : Loading @@ -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<ClassDefinition> class_def = util::make_unique<ClassDefinition>( std::unique_ptr<ClassDefinition> class_def; if (out != nullptr) { class_def = util::make_unique<ClassDefinition>( 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; Loading @@ -615,25 +623,28 @@ 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"); } if (out != nullptr) { AppendJavaDocAnnotations(options_.javadoc_annotations, class_def->GetCommentBuilder()); r_class.AddMember(std::move(class_def)); } } } if (rewrite_method != nullptr) { r_class.AddMember(std::move(rewrite_method)); } if (out != nullptr) { AppendJavaDocAnnotations(options_.javadoc_annotations, r_class.GetCommentBuilder()); ClassDefinition::WriteJavaFile(&r_class, out_package_name, options_.use_final, out); } return true; } Loading Loading
tools/aapt2/cmd/Link.cpp +20 −23 Original line number Diff line number Diff line Loading @@ -1069,26 +1069,30 @@ class LinkCommand { bool WriteJavaFile(ResourceTable* table, const StringPiece& package_name_to_generate, const StringPiece& out_package, const JavaClassGeneratorOptions& java_options, const Maybe<std::string>& out_text_symbols_path = {}) { if (!options_.generate_java_class_path) { if (!options_.generate_java_class_path && !out_text_symbols_path) { return true; } std::string out_path = options_.generate_java_class_path.value(); std::string out_path; std::unique_ptr<io::FileOutputStream> fout; if (options_.generate_java_class_path) { out_path = options_.generate_java_class_path.value(); file::AppendPath(&out_path, file::PackageToPath(out_package)); if (!file::mkdirs(out_path)) { context_->GetDiagnostics()->Error(DiagMessage() << "failed to create directory '" << out_path << "'"); context_->GetDiagnostics()->Error(DiagMessage() << "failed to create directory '" << out_path << "'"); return false; } file::AppendPath(&out_path, "R.java"); io::FileOutputStream fout(out_path); if (fout.HadError()) { fout = util::make_unique<io::FileOutputStream>(out_path); if (fout->HadError()) { context_->GetDiagnostics()->Error(DiagMessage() << "failed writing to '" << out_path << "': " << fout.GetError()); << "': " << fout->GetError()); return false; } } std::unique_ptr<io::FileOutputStream> fout_text; if (out_text_symbols_path) { Loading @@ -1102,18 +1106,11 @@ class LinkCommand { } JavaClassGenerator generator(context_, table, java_options); if (!generator.Generate(package_name_to_generate, out_package, &fout, fout_text.get())) { if (!generator.Generate(package_name_to_generate, out_package, fout.get(), fout_text.get())) { context_->GetDiagnostics()->Error(DiagMessage(out_path) << generator.GetError()); return false; } fout.Flush(); if (fout.HadError()) { context_->GetDiagnostics()->Error(DiagMessage() << "failed writing to '" << out_path << "': " << fout.GetError()); return false; } return true; } Loading Loading @@ -1934,7 +1931,7 @@ class LinkCommand { return 1; } if (options_.generate_java_class_path) { if (options_.generate_java_class_path || options_.generate_text_symbols_path) { if (!GenerateJavaClasses()) { return 1; } Loading
tools/aapt2/java/JavaClassGenerator.cpp +76 −65 Original line number Diff line number Diff line Loading @@ -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"; Loading Loading @@ -356,6 +356,7 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res continue; } 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(); Loading @@ -374,8 +375,8 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res package_name = context_->GetCompilationPackage(); } std::unique_ptr<IntMember> index_member = util::make_unique<IntMember>( sorted_attributes[i].field_name, static_cast<uint32_t>(i)); std::unique_ptr<IntMember> index_member = util::make_unique<IntMember>(sorted_attributes[i].field_name, static_cast<uint32_t>(i)); AnnotationProcessor* attr_processor = index_member->GetCommentBuilder(); Loading @@ -398,12 +399,13 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res attr_processor->AppendComment( StringPrintf("@attr name %s:%s", package_name.data(), attr_name.entry.data())); out_class_def->AddMember(std::move(index_member)); } 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 Loading Loading @@ -434,6 +436,7 @@ void JavaClassGenerator::ProcessResource(const ResourceNameRef& name, const Reso } const std::string field_name = TransformToFieldName(name.entry); if (out_class_def != nullptr) { std::unique_ptr<ResourceMember> resource_member = util::make_unique<ResourceMember>(field_name, real_id); Loading @@ -459,6 +462,7 @@ void JavaClassGenerator::ProcessResource(const ResourceNameRef& name, const Reso } out_class_def->AddMember(std::move(resource_member)); } if (r_txt_printer != nullptr) { r_txt_printer->Print("int ") Loading Loading @@ -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<MethodDefinition>("public static void onResourcesLoaded(int p)"); for (const std::string& package_to_callback : Loading @@ -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<ClassDefinition> class_def = util::make_unique<ClassDefinition>( std::unique_ptr<ClassDefinition> class_def; if (out != nullptr) { class_def = util::make_unique<ClassDefinition>( 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; Loading @@ -615,25 +623,28 @@ 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"); } if (out != nullptr) { AppendJavaDocAnnotations(options_.javadoc_annotations, class_def->GetCommentBuilder()); r_class.AddMember(std::move(class_def)); } } } if (rewrite_method != nullptr) { r_class.AddMember(std::move(rewrite_method)); } if (out != nullptr) { AppendJavaDocAnnotations(options_.javadoc_annotations, r_class.GetCommentBuilder()); ClassDefinition::WriteJavaFile(&r_class, out_package_name, options_.use_final, out); } return true; } Loading