Merge "Stop emitting javadoc for @removed attributes." into nyc-dev
am: c4033e7c66
* commit 'c4033e7c668abc1e671a130f70f58f885c63b176':
Stop emitting javadoc for @removed attributes.
Change-Id: If48d0299c6d4d7179a366d902f23ada17315e42c
This commit is contained in:
@@ -2255,6 +2255,9 @@ static status_t writeLayoutClasses(
|
|||||||
if (comment.size() <= 0) {
|
if (comment.size() <= 0) {
|
||||||
comment = getAttributeComment(assets, name8);
|
comment = getAttributeComment(assets, name8);
|
||||||
}
|
}
|
||||||
|
if (comment.contains(u"@removed")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (comment.size() > 0) {
|
if (comment.size() > 0) {
|
||||||
const char16_t* p = comment.string();
|
const char16_t* p = comment.string();
|
||||||
while (*p != 0 && *p != '.') {
|
while (*p != 0 && *p != '.') {
|
||||||
|
|||||||
@@ -284,6 +284,13 @@ void JavaClassGenerator::addMembersToStyleableClass(const StringPiece16& package
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringPiece16 attrCommentLine = entry.symbol->attribute->getComment();
|
||||||
|
if (attrCommentLine.contains(StringPiece16(u"@removed"))) {
|
||||||
|
// Removed attributes are public but hidden from the documentation, so don't emit
|
||||||
|
// them as part of the class documentation.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const ResourceName& attrName = entry.attrRef->name.value();
|
const ResourceName& attrName = entry.attrRef->name.value();
|
||||||
styleableComment << "<tr><td>";
|
styleableComment << "<tr><td>";
|
||||||
styleableComment << "<code>{@link #"
|
styleableComment << "<code>{@link #"
|
||||||
@@ -299,7 +306,6 @@ void JavaClassGenerator::addMembersToStyleableClass(const StringPiece16& package
|
|||||||
// Only use the comment up until the first '.'. This is to stay compatible with
|
// 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
|
// the way old AAPT did it (presumably to keep it short and to avoid including
|
||||||
// annotations like @hide which would affect this Styleable).
|
// annotations like @hide which would affect this Styleable).
|
||||||
StringPiece16 attrCommentLine = entry.symbol->attribute->getComment();
|
|
||||||
auto iter = std::find(attrCommentLine.begin(), attrCommentLine.end(), u'.');
|
auto iter = std::find(attrCommentLine.begin(), attrCommentLine.end(), u'.');
|
||||||
if (iter != attrCommentLine.end()) {
|
if (iter != attrCommentLine.end()) {
|
||||||
attrCommentLine = attrCommentLine.substr(
|
attrCommentLine = attrCommentLine.substr(
|
||||||
@@ -348,6 +354,17 @@ void JavaClassGenerator::addMembersToStyleableClass(const StringPiece16& package
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringPiece16 comment = styleableAttr.attrRef->getComment();
|
||||||
|
if (styleableAttr.symbol->attribute && comment.empty()) {
|
||||||
|
comment = styleableAttr.symbol->attribute->getComment();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comment.contains(StringPiece16(u"@removed"))) {
|
||||||
|
// Removed attributes are public but hidden from the documentation, so don't emit them
|
||||||
|
// as part of the class documentation.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const ResourceName& attrName = styleableAttr.attrRef->name.value();
|
const ResourceName& attrName = styleableAttr.attrRef->name.value();
|
||||||
|
|
||||||
StringPiece16 packageName = attrName.package;
|
StringPiece16 packageName = attrName.package;
|
||||||
@@ -360,11 +377,6 @@ void JavaClassGenerator::addMembersToStyleableClass(const StringPiece16& package
|
|||||||
|
|
||||||
AnnotationProcessor* attrProcessor = indexMember->getCommentBuilder();
|
AnnotationProcessor* attrProcessor = indexMember->getCommentBuilder();
|
||||||
|
|
||||||
StringPiece16 comment = styleableAttr.attrRef->getComment();
|
|
||||||
if (styleableAttr.symbol->attribute && comment.empty()) {
|
|
||||||
comment = styleableAttr.symbol->attribute->getComment();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!comment.empty()) {
|
if (!comment.empty()) {
|
||||||
attrProcessor->appendComment("<p>\n@attr description");
|
attrProcessor->appendComment("<p>\n@attr description");
|
||||||
attrProcessor->appendComment(comment);
|
attrProcessor->appendComment(comment);
|
||||||
|
|||||||
@@ -289,4 +289,37 @@ TEST(JavaClassGeneratorTest, CommentsForStyleablesAndNestedAttributesArePresent)
|
|||||||
EXPECT_NE(std::string::npos, actual.find(util::utf16ToUtf8(styleable.getComment())));
|
EXPECT_NE(std::string::npos, actual.find(util::utf16ToUtf8(styleable.getComment())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(JavaClassGeneratorTest, CommentsForRemovedAttributesAreNotPresentInClass) {
|
||||||
|
Attribute attr(false);
|
||||||
|
attr.setComment(StringPiece16(u"@removed"));
|
||||||
|
|
||||||
|
|
||||||
|
std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
|
||||||
|
.setPackageId(u"android", 0x01)
|
||||||
|
.addValue(u"@android:attr/one", util::make_unique<Attribute>(attr))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
std::unique_ptr<IAaptContext> context = test::ContextBuilder()
|
||||||
|
.addSymbolSource(util::make_unique<ResourceTableSymbolSource>(table.get()))
|
||||||
|
.setNameManglerPolicy(NameManglerPolicy{ u"android" })
|
||||||
|
.build();
|
||||||
|
JavaClassGeneratorOptions options;
|
||||||
|
options.useFinal = false;
|
||||||
|
JavaClassGenerator generator(context.get(), table.get(), options);
|
||||||
|
std::stringstream out;
|
||||||
|
ASSERT_TRUE(generator.generate(u"android", &out));
|
||||||
|
std::string actual = out.str();
|
||||||
|
|
||||||
|
std::cout << actual << std::endl;
|
||||||
|
|
||||||
|
EXPECT_EQ(std::string::npos, actual.find("@attr name android:one"));
|
||||||
|
EXPECT_EQ(std::string::npos, actual.find("@attr description"));
|
||||||
|
|
||||||
|
// We should find @removed only in the attribute javadoc and not anywhere else (i.e. the class
|
||||||
|
// javadoc).
|
||||||
|
const size_t pos = actual.find("@removed");
|
||||||
|
EXPECT_NE(std::string::npos, pos);
|
||||||
|
EXPECT_EQ(std::string::npos, actual.find("@removed", pos + 1));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aapt
|
} // namespace aapt
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ public:
|
|||||||
bool empty() const;
|
bool empty() const;
|
||||||
std::basic_string<TChar> toString() const;
|
std::basic_string<TChar> toString() const;
|
||||||
|
|
||||||
|
bool contains(const BasicStringPiece<TChar>& rhs) const;
|
||||||
int compare(const BasicStringPiece<TChar>& rhs) const;
|
int compare(const BasicStringPiece<TChar>& rhs) const;
|
||||||
bool operator<(const BasicStringPiece<TChar>& rhs) const;
|
bool operator<(const BasicStringPiece<TChar>& rhs) const;
|
||||||
bool operator>(const BasicStringPiece<TChar>& rhs) const;
|
bool operator>(const BasicStringPiece<TChar>& rhs) const;
|
||||||
@@ -163,6 +164,17 @@ inline std::basic_string<TChar> BasicStringPiece<TChar>::toString() const {
|
|||||||
return std::basic_string<TChar>(mData, mLength);
|
return std::basic_string<TChar>(mData, mLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline bool BasicStringPiece<char>::contains(const BasicStringPiece<char>& rhs) const {
|
||||||
|
if (!mData || !rhs.mData) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (rhs.mLength > mLength) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return strstr(mData, rhs.mData) != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline int BasicStringPiece<char>::compare(const BasicStringPiece<char>& rhs) const {
|
inline int BasicStringPiece<char>::compare(const BasicStringPiece<char>& rhs) const {
|
||||||
const char nullStr = '\0';
|
const char nullStr = '\0';
|
||||||
@@ -185,6 +197,16 @@ inline ::std::ostream& operator<<(::std::ostream& out, const BasicStringPiece<ch
|
|||||||
return out.write(utf8.string(), utf8.size());
|
return out.write(utf8.string(), utf8.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline bool BasicStringPiece<char16_t>::contains(const BasicStringPiece<char16_t>& rhs) const {
|
||||||
|
if (!mData || !rhs.mData) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (rhs.mLength > mLength) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return strstr16(mData, rhs.mData) != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline int BasicStringPiece<char16_t>::compare(const BasicStringPiece<char16_t>& rhs) const {
|
inline int BasicStringPiece<char16_t>::compare(const BasicStringPiece<char16_t>& rhs) const {
|
||||||
|
|||||||
@@ -59,4 +59,36 @@ TEST(StringPieceTest, PiecesHaveCorrectSortOrderUtf8) {
|
|||||||
EXPECT_TRUE(StringPiece(car) > banana);
|
EXPECT_TRUE(StringPiece(car) > banana);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(StringPieceTest, ContainsOtherStringPiece) {
|
||||||
|
StringPiece text("I am a leaf on the wind.");
|
||||||
|
StringPiece startNeedle("I am");
|
||||||
|
StringPiece endNeedle("wind.");
|
||||||
|
StringPiece middleNeedle("leaf");
|
||||||
|
StringPiece emptyNeedle("");
|
||||||
|
StringPiece missingNeedle("soar");
|
||||||
|
StringPiece longNeedle("This string is longer than the text.");
|
||||||
|
|
||||||
|
EXPECT_TRUE(text.contains(startNeedle));
|
||||||
|
EXPECT_TRUE(text.contains(endNeedle));
|
||||||
|
EXPECT_TRUE(text.contains(middleNeedle));
|
||||||
|
EXPECT_TRUE(text.contains(emptyNeedle));
|
||||||
|
EXPECT_FALSE(text.contains(missingNeedle));
|
||||||
|
EXPECT_FALSE(text.contains(longNeedle));
|
||||||
|
|
||||||
|
StringPiece16 text16(u"I am a leaf on the wind.");
|
||||||
|
StringPiece16 startNeedle16(u"I am");
|
||||||
|
StringPiece16 endNeedle16(u"wind.");
|
||||||
|
StringPiece16 middleNeedle16(u"leaf");
|
||||||
|
StringPiece16 emptyNeedle16(u"");
|
||||||
|
StringPiece16 missingNeedle16(u"soar");
|
||||||
|
StringPiece16 longNeedle16(u"This string is longer than the text.");
|
||||||
|
|
||||||
|
EXPECT_TRUE(text16.contains(startNeedle16));
|
||||||
|
EXPECT_TRUE(text16.contains(endNeedle16));
|
||||||
|
EXPECT_TRUE(text16.contains(middleNeedle16));
|
||||||
|
EXPECT_TRUE(text16.contains(emptyNeedle16));
|
||||||
|
EXPECT_FALSE(text16.contains(missingNeedle16));
|
||||||
|
EXPECT_FALSE(text16.contains(longNeedle16));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aapt
|
} // namespace aapt
|
||||||
|
|||||||
Reference in New Issue
Block a user