From be8607dcd543b9dabcd9a2d950e3cfa1eb60ef60 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Mon, 3 Dec 2018 11:28:42 -0800 Subject: 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 --- tools/aapt2/java/JavaClassGenerator.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'tools/aapt2/java/JavaClassGenerator.cpp') diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp index d1a70a75a44e..31d205e1b9c9 100644 --- a/tools/aapt2/java/JavaClassGenerator.cpp +++ b/tools/aapt2/java/JavaClassGenerator.cpp @@ -298,19 +298,20 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res "\n" "AttributeDescription\n"; - // Build the table of attributes with their links and names. - for (const StyleableAttr& entry : sorted_attributes) { - if (SkipSymbol(entry.symbol)) { - continue; - } - + // Removed and hidden attributes are public but hidden from the documentation, so don't emit + // them as part of the class documentation. + std::vector documentation_attrs = sorted_attributes; + auto documentation_remove_iter = std::remove_if(documentation_attrs.begin(), + documentation_attrs.end(), + [&](StyleableAttr entry) -> bool { StringPiece attr_comment_line = entry.symbol.value().attribute->GetComment(); - if (attr_comment_line.contains("@removed")) { - // Removed attributes are public but hidden from the documentation, so - // don't emit them as part of the class documentation. - continue; - } + return SkipSymbol(entry.symbol) || attr_comment_line.contains("@removed") + || attr_comment_line.contains("@hide"); + }); + documentation_attrs.erase(documentation_remove_iter, documentation_attrs.end()); + // Build the table of attributes with their links and names. + for (const StyleableAttr& entry : documentation_attrs) { const ResourceName& attr_name = entry.attr_ref->name.value(); styleable_comment << "{@link #" << entry.field_name << " " << (!attr_name.package.empty() ? attr_name.package @@ -320,16 +321,14 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res // Only use the comment up until the first '.'. This is to stay compatible with // the way old AAPT did it (presumably to keep it short and to avoid including // annotations like @hide which would affect this Styleable). + StringPiece attr_comment_line = entry.symbol.value().attribute->GetComment(); styleable_comment << "" << AnnotationProcessor::ExtractFirstSentence(attr_comment_line) << "\n"; } styleable_comment << "\n"; // Generate the @see lines for each attribute. - for (const StyleableAttr& entry : sorted_attributes) { - if (SkipSymbol(entry.symbol)) { - continue; - } + for (const StyleableAttr& entry : documentation_attrs) { styleable_comment << "@see #" << entry.field_name << "\n"; } -- cgit v1.2.3