diff options
author | Makoto Onuki <omakoto@google.com> | 2020-06-22 10:17:02 -0700 |
---|---|---|
committer | Makoto Onuki <omakoto@google.com> | 2020-06-23 09:35:36 -0700 |
commit | eab9e7f8014fa67164fb9a14ccd9dd624c802c51 (patch) | |
tree | c64628fbc16a9fa621395d2451e789c99dafbc5d /tools/aapt2/java/AnnotationProcessor_test.cpp | |
parent | bdc57bef813d07a837202bae3040c98dd64506a0 (diff) |
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
Diffstat (limited to 'tools/aapt2/java/AnnotationProcessor_test.cpp')
-rw-r--r-- | tools/aapt2/java/AnnotationProcessor_test.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/aapt2/java/AnnotationProcessor_test.cpp b/tools/aapt2/java/AnnotationProcessor_test.cpp index 69f49c8b97c3..c4c8ff934348 100644 --- a/tools/aapt2/java/AnnotationProcessor_test.cpp +++ b/tools/aapt2/java/AnnotationProcessor_test.cpp @@ -76,6 +76,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")); |