Emit comments as javadoc in the Java backend
While AIDL treats /** */ and /* */ alike, but Java tools don't.
So /* */ in AIDL should be formatted as Javadoc style (/** */) so that
Java tools recognize tags correctly.
Bug: 177276893
Test: aidl_unittests
Change-Id: I609660bf7f5e875ed99df7950d8b199613cdb7e1
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 7d8b1c8..6d67b7d 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -801,8 +801,7 @@
"}",
{
{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::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()\")))"}},
@@ -890,7 +889,7 @@
{Options::Language::JAVA, {"out/Foo.java", "@Deprecated"}},
{Options::Language::CPP, {"out/Foo.h", "__attribute__((deprecated"}},
{Options::Language::NDK, {"out/aidl/Foo.h", "__attribute__((deprecated"}},
- // TODO(b/174514415) support "deprecated"
+ // TODO(b/177860423) support "deprecated" in Rust enum
// {Options::Language::RUST, {"out/Foo.rs", "#[deprecated"}},
});
}
@@ -3666,6 +3665,43 @@
GetCapturedStderr());
}
+TEST_F(AidlTest, FormatCommentsForJava) {
+ using android::aidl::FormatCommentsForJava;
+
+ struct TestCase {
+ vector<Comment> comments;
+ string formatted;
+ };
+ vector<TestCase> testcases = {
+ {{}, ""},
+ {{{"// line comments\n"}}, "// line comments\n"},
+ {{{"// @hide \n"}}, "// @hide \n"},
+ // Transform the last block comment as Javadoc.
+ {{{"/*\n"
+ " * Hello, world!\n"
+ " */"}},
+ "/**\n"
+ " * Hello, world!\n"
+ " */"},
+ {{{"/* @hide */"}}, "/** @hide */"},
+ {{{"/**\n"
+ " @param foo ...\n"
+ "*/"}},
+ "/**\n"
+ " @param foo ...\n"
+ "*/"},
+ {{{"/* @hide */"}, {"/* @hide */"}}, "/* @hide *//** @hide */"},
+ {{{"/* @deprecated first */"}, {"/* @deprecated second */"}},
+ "/* @deprecated first *//** @deprecated second */"},
+ {{{"/* @deprecated */"}, {"/** @param foo */"}}, "/* @deprecated *//** @param foo */"},
+ // Line comments are printed as they are
+ {{{"/* @deprecated */"}, {"// line comments\n"}}, "/* @deprecated */// line comments\n"},
+ };
+ for (const auto& [input, formatted] : testcases) {
+ EXPECT_EQ(formatted, FormatCommentsForJava(input));
+ }
+}
+
TEST_F(AidlTest, HideIsNotForArgs) {
io_delegate_.SetFileContents("IFoo.aidl",
"interface IFoo {\n"