Loading tools/aapt2/cmd/Link.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -1272,7 +1272,8 @@ class Linker { return false; } ClassDefinition::WriteJavaFile(manifest_class.get(), package_utf8, true, &fout); ClassDefinition::WriteJavaFile(manifest_class.get(), package_utf8, true, false /* strip_api_annotations */, &fout); fout.Flush(); if (fout.HadError()) { Loading tools/aapt2/java/AnnotationProcessor.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,7 @@ void AnnotationProcessor::AppendNewLine() { } } void AnnotationProcessor::Print(Printer* printer) const { void AnnotationProcessor::Print(Printer* printer, bool strip_api_annotations) const { if (has_comments_) { std::string result = comment_.str(); for (const StringPiece& line : util::Tokenize(result, '\n')) { Loading @@ -137,6 +137,9 @@ void AnnotationProcessor::Print(Printer* printer) const { printer->Println("@Deprecated"); } if (strip_api_annotations) { return; } for (const AnnotationRule& rule : sAnnotationRules) { const auto& it = annotation_parameter_map_.find(rule.bit_mask); if (it != annotation_parameter_map_.end()) { Loading tools/aapt2/java/AnnotationProcessor.h +1 −1 Original line number Diff line number Diff line Loading @@ -65,7 +65,7 @@ class AnnotationProcessor { void AppendNewLine(); // Writes the comments and annotations to the Printer. void Print(text::Printer* printer) const; void Print(text::Printer* printer, bool strip_api_annotations = false) const; private: std::stringstream comment_; Loading tools/aapt2/java/AnnotationProcessor_test.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,21 @@ TEST(AnnotationProcessorTest, EmitsTestApiAnnotationAndRemovesFromComment) { EXPECT_THAT(annotations, HasSubstr("This is a test API")); } TEST(AnnotationProcessorTest, NotEmitSystemApiAnnotation) { AnnotationProcessor processor; processor.AppendComment("@SystemApi This is a system API"); std::string annotations; StringOutputStream out(&annotations); Printer printer(&out); processor.Print(&printer, true /* strip_api_annotations */); out.Flush(); EXPECT_THAT(annotations, Not(HasSubstr("@android.annotation.SystemApi"))); EXPECT_THAT(annotations, Not(HasSubstr("@SystemApi"))); EXPECT_THAT(annotations, HasSubstr("This is a system API")); } TEST(AnnotationProcessor, ExtractsFirstSentence) { EXPECT_THAT(AnnotationProcessor::ExtractFirstSentence("This is the only sentence"), Eq("This is the only sentence")); Loading tools/aapt2/java/ClassDefinition.cpp +8 −8 Original line number Diff line number Diff line Loading @@ -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_) { Loading Loading @@ -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) { Loading @@ -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(); } } Loading @@ -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 Loading
tools/aapt2/cmd/Link.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -1272,7 +1272,8 @@ class Linker { return false; } ClassDefinition::WriteJavaFile(manifest_class.get(), package_utf8, true, &fout); ClassDefinition::WriteJavaFile(manifest_class.get(), package_utf8, true, false /* strip_api_annotations */, &fout); fout.Flush(); if (fout.HadError()) { Loading
tools/aapt2/java/AnnotationProcessor.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,7 @@ void AnnotationProcessor::AppendNewLine() { } } void AnnotationProcessor::Print(Printer* printer) const { void AnnotationProcessor::Print(Printer* printer, bool strip_api_annotations) const { if (has_comments_) { std::string result = comment_.str(); for (const StringPiece& line : util::Tokenize(result, '\n')) { Loading @@ -137,6 +137,9 @@ void AnnotationProcessor::Print(Printer* printer) const { printer->Println("@Deprecated"); } if (strip_api_annotations) { return; } for (const AnnotationRule& rule : sAnnotationRules) { const auto& it = annotation_parameter_map_.find(rule.bit_mask); if (it != annotation_parameter_map_.end()) { Loading
tools/aapt2/java/AnnotationProcessor.h +1 −1 Original line number Diff line number Diff line Loading @@ -65,7 +65,7 @@ class AnnotationProcessor { void AppendNewLine(); // Writes the comments and annotations to the Printer. void Print(text::Printer* printer) const; void Print(text::Printer* printer, bool strip_api_annotations = false) const; private: std::stringstream comment_; Loading
tools/aapt2/java/AnnotationProcessor_test.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,21 @@ TEST(AnnotationProcessorTest, EmitsTestApiAnnotationAndRemovesFromComment) { EXPECT_THAT(annotations, HasSubstr("This is a test API")); } TEST(AnnotationProcessorTest, NotEmitSystemApiAnnotation) { AnnotationProcessor processor; processor.AppendComment("@SystemApi This is a system API"); std::string annotations; StringOutputStream out(&annotations); Printer printer(&out); processor.Print(&printer, true /* strip_api_annotations */); out.Flush(); EXPECT_THAT(annotations, Not(HasSubstr("@android.annotation.SystemApi"))); EXPECT_THAT(annotations, Not(HasSubstr("@SystemApi"))); EXPECT_THAT(annotations, HasSubstr("This is a system API")); } TEST(AnnotationProcessor, ExtractsFirstSentence) { EXPECT_THAT(AnnotationProcessor::ExtractFirstSentence("This is the only sentence"), Eq("This is the only sentence")); Loading
tools/aapt2/java/ClassDefinition.cpp +8 −8 Original line number Diff line number Diff line Loading @@ -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_) { Loading Loading @@ -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) { Loading @@ -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(); } } Loading @@ -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