Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: solve line break in annotation #100

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 39 additions & 11 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
'artifactId', 'version'
];
needParamsKeys.forEach(key => {
if (params[key] === undefined) {

Check warning on line 74 in lib/generator.js

View workflow job for this annotation

GitHub Actions / build (12.x)

Unexpected use of undefined

Check warning on line 74 in lib/generator.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected use of undefined

Check warning on line 74 in lib/generator.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected use of undefined

Check warning on line 74 in lib/generator.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected use of undefined

Check warning on line 74 in lib/generator.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected use of undefined
params[key] = '';
}
});
Expand Down Expand Up @@ -593,11 +593,11 @@
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 @@
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 {
}
Loading