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
This commit is contained in:
@@ -18,25 +18,27 @@
|
||||
|
||||
#include "androidfw/StringPiece.h"
|
||||
|
||||
using ::aapt::text::Printer;
|
||||
using ::android::StringPiece;
|
||||
|
||||
namespace aapt {
|
||||
|
||||
void ClassMember::WriteToStream(const StringPiece& prefix, bool final, std::ostream* out) const {
|
||||
processor_.WriteToStream(prefix, out);
|
||||
void ClassMember::Print(bool /*final*/, Printer* printer) const {
|
||||
processor_.Print(printer);
|
||||
}
|
||||
|
||||
void MethodDefinition::AppendStatement(const StringPiece& statement) {
|
||||
statements_.push_back(statement.to_string());
|
||||
}
|
||||
|
||||
void MethodDefinition::WriteToStream(const StringPiece& prefix, bool final,
|
||||
std::ostream* out) const {
|
||||
*out << prefix << signature_ << " {\n";
|
||||
void MethodDefinition::Print(bool final, Printer* printer) const {
|
||||
printer->Print(signature_).Println(" {");
|
||||
printer->Indent();
|
||||
for (const auto& statement : statements_) {
|
||||
*out << prefix << " " << statement << "\n";
|
||||
printer->Println(statement);
|
||||
}
|
||||
*out << prefix << "}";
|
||||
printer->Undent();
|
||||
printer->Print("}");
|
||||
}
|
||||
|
||||
ClassDefinition::Result ClassDefinition::AddMember(std::unique_ptr<ClassMember> member) {
|
||||
@@ -62,34 +64,32 @@ bool ClassDefinition::empty() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClassDefinition::WriteToStream(const StringPiece& prefix, bool final,
|
||||
std::ostream* out) const {
|
||||
void ClassDefinition::Print(bool final, Printer* printer) const {
|
||||
if (empty() && !create_if_empty_) {
|
||||
return;
|
||||
}
|
||||
|
||||
ClassMember::WriteToStream(prefix, final, out);
|
||||
ClassMember::Print(final, printer);
|
||||
|
||||
*out << prefix << "public ";
|
||||
printer->Print("public ");
|
||||
if (qualifier_ == ClassQualifier::kStatic) {
|
||||
*out << "static ";
|
||||
printer->Print("static ");
|
||||
}
|
||||
*out << "final class " << name_ << " {\n";
|
||||
|
||||
std::string new_prefix = prefix.to_string();
|
||||
new_prefix.append(kIndent);
|
||||
printer->Print("final class ").Print(name_).Println(" {");
|
||||
printer->Indent();
|
||||
|
||||
for (const std::unique_ptr<ClassMember>& member : ordered_members_) {
|
||||
// There can be nullptr members when a member is added to the ClassDefinition
|
||||
// and takes precedence over a previous member with the same name. The overridden member is
|
||||
// set to nullptr.
|
||||
if (member != nullptr) {
|
||||
member->WriteToStream(new_prefix, final, out);
|
||||
*out << "\n";
|
||||
member->Print(final, printer);
|
||||
printer->Println();
|
||||
}
|
||||
}
|
||||
|
||||
*out << prefix << "}";
|
||||
printer->Undent();
|
||||
printer->Print("}");
|
||||
}
|
||||
|
||||
constexpr static const char* sWarningHeader =
|
||||
@@ -100,11 +100,12 @@ constexpr static const char* sWarningHeader =
|
||||
" * should not be modified by hand.\n"
|
||||
" */\n\n";
|
||||
|
||||
bool ClassDefinition::WriteJavaFile(const ClassDefinition* def, const StringPiece& package,
|
||||
bool final, std::ostream* out) {
|
||||
*out << sWarningHeader << "package " << package << ";\n\n";
|
||||
def->WriteToStream("", final, out);
|
||||
return bool(*out);
|
||||
void ClassDefinition::WriteJavaFile(const ClassDefinition* def, const StringPiece& package,
|
||||
bool final, io::OutputStream* out) {
|
||||
Printer printer(out);
|
||||
printer.Print(sWarningHeader).Print("package ").Print(package).Println(";");
|
||||
printer.Println();
|
||||
def->Print(final, &printer);
|
||||
}
|
||||
|
||||
} // namespace aapt
|
||||
|
||||
Reference in New Issue
Block a user