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
Change-Id: I613e8611ddaf5f8e4761d351d4cd0142d59c7cc9
diff --git a/tools/aapt2/java/ClassDefinition.h b/tools/aapt2/java/ClassDefinition.h
index fb11266..1e4b681 100644
--- a/tools/aapt2/java/ClassDefinition.h
+++ b/tools/aapt2/java/ClassDefinition.h
@@ -50,7 +50,7 @@
// Writes the class member to the Printer. Subclasses should derive this method
// to write their own data. Call this base method from the subclass to write out
// this member's comments/annotations.
- virtual void Print(bool final, text::Printer* printer) const;
+ virtual void Print(bool final, text::Printer* printer, bool strip_api_annotations = false) const;
private:
AnnotationProcessor processor_;
@@ -70,10 +70,11 @@
return name_;
}
- void Print(bool final, text::Printer* printer) const override {
+ void Print(bool final, text::Printer* printer, bool strip_api_annotations = false)
+ const override {
using std::to_string;
- ClassMember::Print(final, printer);
+ ClassMember::Print(final, printer, strip_api_annotations);
printer->Print("public static ");
if (final) {
@@ -104,8 +105,9 @@
return name_;
}
- void Print(bool final, text::Printer* printer) const override {
- ClassMember::Print(final, printer);
+ void Print(bool final, text::Printer* printer, bool strip_api_annotations = false)
+ const override {
+ ClassMember::Print(final, printer, strip_api_annotations);
printer->Print("public static ");
if (final) {
@@ -142,8 +144,9 @@
return name_;
}
- void Print(bool final, text::Printer* printer) const override {
- ClassMember::Print(final, printer);
+ void Print(bool final, text::Printer* printer, bool strip_api_annotations = false)
+ const override {
+ ClassMember::Print(final, printer, strip_api_annotations);
printer->Print("public static final int[] ").Print(name_).Print("={");
printer->Indent();
@@ -195,7 +198,7 @@
return false;
}
- void Print(bool final, text::Printer* printer) const override;
+ void Print(bool final, text::Printer* printer, bool strip_api_annotations = false) const override;
private:
DISALLOW_COPY_AND_ASSIGN(MethodDefinition);
@@ -209,7 +212,7 @@
class ClassDefinition : public ClassMember {
public:
static void WriteJavaFile(const ClassDefinition* def, const android::StringPiece& package,
- bool final, io::OutputStream* out);
+ bool final, bool strip_api_annotations, io::OutputStream* out);
ClassDefinition(const android::StringPiece& name, ClassQualifier qualifier, bool createIfEmpty)
: name_(name.to_string()), qualifier_(qualifier), create_if_empty_(createIfEmpty) {}
@@ -227,7 +230,7 @@
return name_;
}
- void Print(bool final, text::Printer* printer) const override;
+ void Print(bool final, text::Printer* printer, bool strip_api_annotations = false) const override;
private:
DISALLOW_COPY_AND_ASSIGN(ClassDefinition);