带有 Gradle(io.freefair.lombok 插件)的 Lombok 创建了大量的 JavaDoc 警告
Lombok with Gradle (io.freefair.lombok plugin) creates tons of JavaDoc warnings
我正在使用 Gradle 来包含 Lombok,并且我正在按照推荐使用免费的 lombok 插件;
plugins {
id "io.freefair.lombok" version "6.0.0-m2"
// ...
}
给出以下 class:
/**
* Request to add a task to an existing todo list.
*
* @author b_muth
*
*/
@Value
public class AddTaskRequest{
/**
* Identifier of the list.
*/
@NonNull UUID todoListId;
/**
* Name of the task to be added.
*/
@NonNull String taskName;
}
我收到以下警告:
C:\...\generated\sources\delombok\...\AddTaskRequest.java:23: warning: no comment
public AddTaskRequest(@NonNull final UUID todoListId, @NonNull final String taskName)
C:\...\generated\sources\delombok\...\AddTaskRequest.java:38: warning: no @return
public UUID getTodoListId() {
还有更多。据我所知,freefair 使用 delombok,但没有在生成的源代码中创建足够的 JavaDoc。这是生成的 class:
的摘录
/**
* Request to add a task to an existing todo list.
*
* @author b_muth
*/
public final class AddTaskRequest {
/**
* Identifier of the list.
*/
@NonNull
private final UUID todoListId;
/**
* Name of the task to be added.
*/
@NonNull
private final String taskName;
public AddTaskRequest(@NonNull final UUID todoListId, @NonNull final String taskName) {
if (todoListId == null) {
throw new NullPointerException("todoListId is marked non-null but is null");
}
if (taskName == null) {
throw new NullPointerException("taskName is marked non-null but is null");
}
this.todoListId = todoListId;
this.taskName = taskName;
}
/**
* Identifier of the list.
*/
@NonNull
public UUID getTodoListId() {
return this.todoListId;
}
...
}
是否可以阻止这些警告的发生?
请在此处查看 (de)lombok 文档,其中解释了如何处理 javadoc 注释:https://projectlombok.org/features/GetterSetter
NEW in lombok v1.12.0: javadoc on the field will now be copied to generated getters and setters. Normally, all text is copied, and @return
is moved to the getter, whilst @param
lines are moved to the setter. Moved means: Deleted from the field's javadoc. It is also possible to define unique text for each getter/setter. To do that, you create a 'section' named GETTER
and/or SETTER
. A section is a line in your javadoc containing 2 or more dashes, then the text 'GETTER' or 'SETTER', followed by 2 or more dashes, and nothing else on the line. If you use sections, @return
and @param
stripping for that section is no longer done (move the @return
or @param
line into the section).
编辑:
除了修复 javadoc 注释本身,您还可以通过向 javadoc 任务添加 -Xdoclint:-missing
选项来消除警告:
tasks.withType(Javadoc) {
options.addBooleanOption("Xdoclint:-missing", true)
}
我正在使用 Gradle 来包含 Lombok,并且我正在按照推荐使用免费的 lombok 插件;
plugins {
id "io.freefair.lombok" version "6.0.0-m2"
// ...
}
给出以下 class:
/**
* Request to add a task to an existing todo list.
*
* @author b_muth
*
*/
@Value
public class AddTaskRequest{
/**
* Identifier of the list.
*/
@NonNull UUID todoListId;
/**
* Name of the task to be added.
*/
@NonNull String taskName;
}
我收到以下警告:
C:\...\generated\sources\delombok\...\AddTaskRequest.java:23: warning: no comment
public AddTaskRequest(@NonNull final UUID todoListId, @NonNull final String taskName)
C:\...\generated\sources\delombok\...\AddTaskRequest.java:38: warning: no @return
public UUID getTodoListId() {
还有更多。据我所知,freefair 使用 delombok,但没有在生成的源代码中创建足够的 JavaDoc。这是生成的 class:
的摘录/**
* Request to add a task to an existing todo list.
*
* @author b_muth
*/
public final class AddTaskRequest {
/**
* Identifier of the list.
*/
@NonNull
private final UUID todoListId;
/**
* Name of the task to be added.
*/
@NonNull
private final String taskName;
public AddTaskRequest(@NonNull final UUID todoListId, @NonNull final String taskName) {
if (todoListId == null) {
throw new NullPointerException("todoListId is marked non-null but is null");
}
if (taskName == null) {
throw new NullPointerException("taskName is marked non-null but is null");
}
this.todoListId = todoListId;
this.taskName = taskName;
}
/**
* Identifier of the list.
*/
@NonNull
public UUID getTodoListId() {
return this.todoListId;
}
...
}
是否可以阻止这些警告的发生?
请在此处查看 (de)lombok 文档,其中解释了如何处理 javadoc 注释:https://projectlombok.org/features/GetterSetter
NEW in lombok v1.12.0: javadoc on the field will now be copied to generated getters and setters. Normally, all text is copied, and
@return
is moved to the getter, whilst@param
lines are moved to the setter. Moved means: Deleted from the field's javadoc. It is also possible to define unique text for each getter/setter. To do that, you create a 'section' namedGETTER
and/orSETTER
. A section is a line in your javadoc containing 2 or more dashes, then the text 'GETTER' or 'SETTER', followed by 2 or more dashes, and nothing else on the line. If you use sections,@return
and@param
stripping for that section is no longer done (move the@return
or@param
line into the section).
编辑:
除了修复 javadoc 注释本身,您还可以通过向 javadoc 任务添加 -Xdoclint:-missing
选项来消除警告:
tasks.withType(Javadoc) {
options.addBooleanOption("Xdoclint:-missing", true)
}