Skip to content

Commit

Permalink
fix: solve line break in annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
PanPanZou authored and yndu13 committed Jul 5, 2024
1 parent 5469872 commit e7c21f5
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 11 deletions.
50 changes: 39 additions & 11 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(` * <b>description</b> :\n`, level);
const descriptionTexts = md2Html(descriptionText).trimEnd();
Expand All @@ -621,32 +621,60 @@ 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) {
if (hasNextSection) {
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) {
if (hasNextSection) {
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);
Expand Down
36 changes: 36 additions & 0 deletions test/fixtures/comment/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,40 @@ public static void deprecatedFunc(String test, String _test) throws Exception {
// empty comment1
// empty comment2
}

/**
* <b>summary</b> :
* <p>annotation test summary
* summary description1
* summary description2</p>
*
* @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 {
}
}
33 changes: 33 additions & 0 deletions test/fixtures/comment/main.dara
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}

0 comments on commit e7c21f5

Please sign in to comment.