From 1d5264d28258f099b9c79387df46fdb223fd0861 Mon Sep 17 00:00:00 2001 From: zpp <865287328@qq.com> Date: Fri, 5 Jul 2024 14:51:47 +0800 Subject: [PATCH] fix: solve line break in annotation --- lib/generator.js | 50 ++++++++++++++++++++++++------- test/fixtures/comment/Client.java | 36 ++++++++++++++++++++++ test/fixtures/comment/main.dara | 33 ++++++++++++++++++++ 3 files changed, 108 insertions(+), 11 deletions(-) diff --git a/lib/generator.js b/lib/generator.js index 7d93280..50ead3b 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -593,11 +593,11 @@ class Visitor { return item.text.text.trimEnd(); }); - var descriptionText = description ? description.text.text : ''; - var summaryText = summary ? summary.text.text : ''; - var returnText = _return ? _return.text.text.trimEnd() : ''; let hasNextSection = false; this.emit(`/**\n`, level); + const descriptionText = description ? description.text.text : ''; + const summaryText = summary ? summary.text.text : ''; + const returnText = _return ? _return.text.text.trimEnd() : ''; if (descriptionText !== '') { this.emit(` * description :\n`, level); const descriptionTexts = md2Html(descriptionText).trimEnd(); @@ -621,11 +621,15 @@ class Visitor { if (hasNextSection) { this.emit(` * \n`, level); } - if (deprecated.text.text.trimEnd() === '') { - this.emit(` * @deprecated\n`, level); - } else { - this.emit(` * @deprecated ${deprecated.text.text.trimEnd()}\n`, level); - } + const deprecatedText = deprecated.text.text.trimEnd(); + this.emit(` * @deprecated `, level); + deprecatedText.split('\n').forEach((line, index) => { + if (index === 0) { + this.emit(`${line}\n`); + } else { + this.emit(` * ${line}\n`, level); + } + }); hasNextSection = true; } if (params.length > 0) { @@ -633,12 +637,28 @@ class Visitor { this.emit(` * \n`, level); } params.forEach((item) => { - this.emit(` * @param ${item.name} ${item.text}\n`, level); + this.emit(` * @param ${item.name} `, level); + const items = item.text.trimEnd().split('\n'); + items.forEach((line, index) => { + if (index === 0) { + this.emit(`${line}\n`); + } else { + this.emit(` * ${line}\n`, level); + } + }); }); hasNextSection = true; } if (returnText !== '') { - this.emit(` * @return ${returnText}\n`, level); + this.emit(` * @return `, level); + const returns = returnText.split('\n'); + returns.forEach((line, index) => { + if (index === 0) { + this.emit(`${line}\n`); + } else { + this.emit(` * ${line}\n`, level); + } + }); hasNextSection = true; } if (throws.length > 0) { @@ -646,7 +666,15 @@ class Visitor { this.emit(` * \n`, level); } throws.forEach((item) => { - this.emit(` * @throws ${item}\n`, level); + this.emit(` * @throws `, level); + const items = item.trimEnd().split('\n'); + items.forEach((line, index) => { + if (index === 0) { + this.emit(`${line}\n`); + } else { + this.emit(` * ${line}\n`, level); + } + }); }); } this.emit(` */`, level); diff --git a/test/fixtures/comment/Client.java b/test/fixtures/comment/Client.java index 10f44ec..0a508d9 100644 --- a/test/fixtures/comment/Client.java +++ b/test/fixtures/comment/Client.java @@ -204,4 +204,40 @@ public static void deprecatedFunc(String test, String _test) throws Exception { // empty comment1 // empty comment2 } + + /** + * summary : + *

annotation test summary + * summary description1 + * summary description2

+ * + * @deprecated test is deprecated, use xxx instead. + * deprecated description1 + * deprecated description2 + * + * @param test string param1 + * @param _test string param2 + * @return void + * + * @throws InternalError Server error. 500 服务器端出现未知异常。 + */ + @Deprecated + public static void multiLineAnnotation(String test, String _test) throws Exception { + } + + /** + * @deprecated deprecated test for line break. + * + * @param test string param1 + * param test for line break. + * @param _test string param2 + * @return void + * return test for line break. + * + * @throws InternalError Server error. 500 服务器端出现未知异常。 + * throws test for line break. + */ + @Deprecated + public static void lineBreakAnnotation(String test, String _test) throws Exception { + } } diff --git a/test/fixtures/comment/main.dara b/test/fixtures/comment/main.dara index c4bf114..20f68b4 100644 --- a/test/fixtures/comment/main.dara +++ b/test/fixtures/comment/main.dara @@ -165,4 +165,37 @@ static async function testFunc(): void { static async function deprecatedFunc(test: string, _test: string): void { // empty comment1 // empty comment2 +} + +/** + * @summary annotation test summary + * summary description1 + * summary description2 + * + * @deprecated test is deprecated, use xxx instead. + * deprecated description1 + * deprecated description2 + * + * @param test string param1 + * @param _test string param2 + * @return void + * @throws InternalError Server error. 500 服务器端出现未知异常。 +*/ +static async function multiLineAnnotation(test: string, _test: string): void { +} + + +/** + * @deprecated + * deprecated test for line break. + * + * @param test string param1 + * param test for line break. + * @param _test string param2 + * @return void + * return test for line break. + * @throws InternalError Server error. 500 服务器端出现未知异常。 + * throws test for line break. +*/ +static async function lineBreakAnnotation(test: string, _test: string): void { } \ No newline at end of file