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
This commit is contained in:
@@ -604,6 +604,8 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate,
|
||||
rewrite_method->AppendStatement("final int packageIdBits = p << 24;");
|
||||
}
|
||||
|
||||
const bool is_public = (options_.types == JavaClassGeneratorOptions::SymbolTypes::kPublic);
|
||||
|
||||
for (const auto& package : table_->packages) {
|
||||
for (const auto& type : package->types) {
|
||||
if (type->type == ResourceType::kAttrPrivate) {
|
||||
@@ -612,8 +614,7 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate,
|
||||
}
|
||||
|
||||
// Stay consistent with AAPT and generate an empty type class if the R class is public.
|
||||
const bool force_creation_if_empty =
|
||||
(options_.types == JavaClassGeneratorOptions::SymbolTypes::kPublic);
|
||||
const bool force_creation_if_empty = is_public;
|
||||
|
||||
std::unique_ptr<ClassDefinition> class_def;
|
||||
if (out != nullptr) {
|
||||
@@ -637,8 +638,7 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate,
|
||||
}
|
||||
}
|
||||
|
||||
if (out != nullptr && type->type == ResourceType::kStyleable &&
|
||||
options_.types == JavaClassGeneratorOptions::SymbolTypes::kPublic) {
|
||||
if (out != nullptr && type->type == ResourceType::kStyleable && is_public) {
|
||||
// When generating a public R class, we don't want Styleable to be part
|
||||
// of the API. It is only emitted for documentation purposes.
|
||||
class_def->GetCommentBuilder()->AppendComment("@doconly");
|
||||
@@ -657,7 +657,7 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate,
|
||||
|
||||
if (out != nullptr) {
|
||||
AppendJavaDocAnnotations(options_.javadoc_annotations, r_class.GetCommentBuilder());
|
||||
ClassDefinition::WriteJavaFile(&r_class, out_package_name, options_.use_final, out);
|
||||
ClassDefinition::WriteJavaFile(&r_class, out_package_name, options_.use_final, !is_public, out);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user