From eab9e7f8014fa67164fb9a14ccd9dd624c802c51 Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Mon, 22 Jun 2020 10:17:02 -0700 Subject: Don't add API annotations in the internal R.java I'm trying to enable a check for the following structure: ``` /** @hide */ public class Class1 { /** @hide */ @SystemApi // Invalid because the class is hidden. public void method1() { } } ``` The internal R.java file violates this, which this change is going to fix. Bug: 159162473 Test: build (treehugger) Test: atest aapt2_tests Merged-in: I613e8611ddaf5f8e4761d351d4cd0142d59c7cc9 Change-Id: I613e8611ddaf5f8e4761d351d4cd0142d59c7cc9 --- tools/aapt2/java/ClassDefinition.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tools/aapt2/java/ClassDefinition.cpp') diff --git a/tools/aapt2/java/ClassDefinition.cpp b/tools/aapt2/java/ClassDefinition.cpp index f5f5b05491bb..3163497f0da6 100644 --- a/tools/aapt2/java/ClassDefinition.cpp +++ b/tools/aapt2/java/ClassDefinition.cpp @@ -23,15 +23,15 @@ using ::android::StringPiece; namespace aapt { -void ClassMember::Print(bool /*final*/, Printer* printer) const { - processor_.Print(printer); +void ClassMember::Print(bool /*final*/, Printer* printer, bool strip_api_annotations) const { + processor_.Print(printer, strip_api_annotations); } void MethodDefinition::AppendStatement(const StringPiece& statement) { statements_.push_back(statement.to_string()); } -void MethodDefinition::Print(bool final, Printer* printer) const { +void MethodDefinition::Print(bool final, Printer* printer, bool) const { printer->Print(signature_).Println(" {"); printer->Indent(); for (const auto& statement : statements_) { @@ -74,12 +74,12 @@ bool ClassDefinition::empty() const { return true; } -void ClassDefinition::Print(bool final, Printer* printer) const { +void ClassDefinition::Print(bool final, Printer* printer, bool strip_api_annotations) const { if (empty() && !create_if_empty_) { return; } - ClassMember::Print(final, printer); + ClassMember::Print(final, printer, strip_api_annotations); printer->Print("public "); if (qualifier_ == ClassQualifier::kStatic) { @@ -93,7 +93,7 @@ void ClassDefinition::Print(bool final, Printer* printer) const { // and takes precedence over a previous member with the same name. The overridden member is // set to nullptr. if (member != nullptr) { - member->Print(final, printer); + member->Print(final, printer, strip_api_annotations); printer->Println(); } } @@ -111,11 +111,11 @@ constexpr static const char* sWarningHeader = " */\n\n"; void ClassDefinition::WriteJavaFile(const ClassDefinition* def, const StringPiece& package, - bool final, io::OutputStream* out) { + bool final, bool strip_api_annotations, io::OutputStream* out) { Printer printer(out); printer.Print(sWarningHeader).Print("package ").Print(package).Println(";"); printer.Println(); - def->Print(final, &printer); + def->Print(final, &printer, strip_api_annotations); } } // namespace aapt -- cgit v1.2.3