Add @hide support for styleable attributes

AAPT2 generates documentation for styleables. The documentation contains
references to the attributes of the styleable. If the attributes are
marked @hide, remove the references to the attributes in the generated
coments.

Bug: 120262117
Test: m -j offline-sdk-docs
Change-Id: I541002077b17771d89caead04df2f4ae66c623f0
This commit is contained in:
Ryan Mitchell
2018-12-03 11:28:42 -08:00
parent e8f76a3642
commit be8607dcd5
2 changed files with 54 additions and 15 deletions

View File

@@ -366,6 +366,46 @@ TEST(JavaClassGeneratorTest, CommentsForStyleablesAndNestedAttributesArePresent)
ASSERT_TRUE(generator.Generate("android", &out));
out.Flush();
EXPECT_THAT(output, HasSubstr("#Container_one android:one"));
EXPECT_THAT(output, HasSubstr("@see #Container_one"));
EXPECT_THAT(output, HasSubstr("attr name android:one"));
EXPECT_THAT(output, HasSubstr("attr description"));
EXPECT_THAT(output, HasSubstr(attr.GetComment()));
EXPECT_THAT(output, HasSubstr(styleable.GetComment()));
}
TEST(JavaClassGeneratorTest, CommentsForStyleableHiddenAttributesAreNotPresent) {
Attribute attr;
attr.SetComment(StringPiece("This is an attribute @hide"));
Styleable styleable;
styleable.entries.push_back(Reference(test::ParseNameOrDie("android:attr/one")));
styleable.SetComment(StringPiece("This is a styleable"));
std::unique_ptr<ResourceTable> table =
test::ResourceTableBuilder()
.SetPackageId("android", 0x01)
.AddValue("android:attr/one", util::make_unique<Attribute>(attr))
.AddValue("android:styleable/Container",
std::unique_ptr<Styleable>(styleable.Clone(nullptr)))
.Build();
std::unique_ptr<IAaptContext> context =
test::ContextBuilder()
.AddSymbolSource(util::make_unique<ResourceTableSymbolSource>(table.get()))
.SetNameManglerPolicy(NameManglerPolicy{"android"})
.Build();
JavaClassGeneratorOptions options;
options.use_final = false;
JavaClassGenerator generator(context.get(), table.get(), options);
std::string output;
StringOutputStream out(&output);
ASSERT_TRUE(generator.Generate("android", &out));
out.Flush();
EXPECT_THAT(output, Not(HasSubstr("#Container_one android:one")));
EXPECT_THAT(output, Not(HasSubstr("@see #Container_one")));
EXPECT_THAT(output, HasSubstr("attr name android:one"));
EXPECT_THAT(output, HasSubstr("attr description"));
EXPECT_THAT(output, HasSubstr(attr.GetComment()));