Emit deprecation note
@deprecated tag in comments can have optional note to explain the
rationale for deprecation and/or to suggest a replacing entity.
/** @deprecated use bar() */
void foo();
In this change, the deprecation note is emitted when specified.
For example, in C++, deprecation note is emitted as following:
void foo() __attribute__((deprecated("use bar()")) ...
Bug: 174514415
Test: aidl_unittests
Merged-In: I271af4d636e755a4d97f60d2daa6528acbe76a4e
Change-Id: I271af4d636e755a4d97f60d2daa6528acbe76a4e
(cherry picked from commit 6ec07c5482939803229445726044457383dbdaa9)
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 8e72173..da4f035 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -740,14 +740,14 @@
};
auto CheckDeprecated = [&](const std::string& filename, const std::string& contents,
- std::map<Options::Language, TestCase> expectation) {
+ std::vector<std::pair<Options::Language, TestCase>> expectations) {
io_delegate_.SetFileContents(filename, contents);
auto options = Options::From("aidl --lang=" + to_string(GetLanguage()) + " " + filename +
" --out=out --header_out=out");
EXPECT_EQ(0, ::android::aidl::compile_aidl(options, io_delegate_));
- if (auto it = expectation.find(GetLanguage()); it != expectation.end()) {
- const auto& test_case = it->second;
+ for (const auto& [lang, test_case] : expectations) {
+ if (lang != GetLanguage()) continue;
string output;
EXPECT_TRUE(io_delegate_.GetWrittenContents(test_case.output_file, &output))
<< base::Join(io_delegate_.ListOutputFiles(), ",");
@@ -755,17 +755,48 @@
}
};
- CheckDeprecated("IFoo.aidl",
- "interface IFoo {\n"
- " /** @deprecated use bar() */\n"
- " List<String> foo();\n"
- "}",
- {
- {Options::Language::JAVA, {"out/IFoo.java", "@Deprecated"}},
- {Options::Language::CPP, {"out/IFoo.h", "__attribute__((deprecated"}},
- {Options::Language::NDK, {"out/aidl/IFoo.h", "__attribute__((deprecated"}},
- {Options::Language::RUST, {"out/IFoo.rs", "#[deprecated"}},
- });
+ // Emit escaped string for notes
+ CheckDeprecated(
+ "IFoo.aidl",
+ R"(interface IFoo {
+ /**
+ * @note asdf
+ * @deprecated a really long deprecation message
+ *
+ * which is really long
+ * @param foo bar
+ */
+ List<String> foo();
+ })",
+ {
+ {Options::Language::JAVA, {"out/IFoo.java", "@Deprecated"}},
+ {Options::Language::CPP,
+ {"out/IFoo.h",
+ R"(__attribute__((deprecated("a really long deprecation message which is really long"))))"}},
+ {Options::Language::NDK,
+ {"out/aidl/IFoo.h",
+ R"(__attribute__((deprecated("a really long deprecation message which is really long"))))"}},
+ {Options::Language::RUST,
+ {"out/IFoo.rs",
+ R"(#[deprecated = "a really long deprecation message which is really long"])"}},
+ });
+
+ // In AIDL @deprecated can be in any style of comments
+ CheckDeprecated(
+ "IFoo.aidl",
+ "interface IFoo {\n"
+ " // @deprecated use bar()\n"
+ " List<String> foo();\n"
+ "}",
+ {
+ {Options::Language::JAVA, {"out/IFoo.java", "@Deprecated"}},
+ // TODO(b/177276893) @deprecated should be in javadoc style comments
+ // {Options::Language::JAVA, {"out/IFoo.java", "/** @deprecated use bar() */"}},
+ {Options::Language::CPP, {"out/IFoo.h", "__attribute__((deprecated(\"use bar()\")))"}},
+ {Options::Language::NDK,
+ {"out/aidl/IFoo.h", "__attribute__((deprecated(\"use bar()\")))"}},
+ {Options::Language::RUST, {"out/IFoo.rs", "#[deprecated = \"use bar()\"]"}},
+ });
CheckDeprecated("Foo.aidl",
"parcelable Foo {\n"