JavaPoet 增加JavaDoc注释

本文介绍了如何使用Javadoc为Java方法、参数和返回值添加详细描述,以及如何引用类型并自动导入。实例展示了如何在MethodSpec中创建带有标准注释的方法声明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Javadoc

可以用 Javadoc 记录字段、方法和类型:

MethodSpec dismiss = MethodSpec.methodBuilder("dismiss")
    .addJavadoc("Hides {@code message} from the caller's history. Other\n"
        + "participants in the conversation will continue to see the\n"
        + "message in their own history unless they also delete it.\n")
    .addJavadoc("\n")
    .addJavadoc("<p>Use {@link #delete($T)} to delete the entire\n"
        + "conversation for all participants.\n", Conversation.class)
    .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
    .addParameter(Message.class, "message")
    .build();
复制代码

将生成:

/**
  * Hides {@code message} from the caller's history. Other
  * participants in the conversation will continue to see the
  * message in their own history unless they also delete it.
  *
  * <p>Use {@link #delete(Conversation)} to delete the entire
  * conversation for all participants.
  */
 void dismiss(Message message);
复制代码

在引用 Javadoc 中的类型时使用 $T 来获得自动导入。

根据这个说明 修改一下 可以被项目使用

增加标准的代码注释

MethodSpec dismiss = MethodSpec.methodBuilder("dismiss")
        .addJavadoc("方法说明\n")
        .addJavadoc("\n")
        .addJavadoc("@param  $L $L\n", ParserTable.TestAcceptor2.class.getSimpleName(), "dto")
        .addJavadoc("@return $L $L\n", SwingUtilities2.AATextInfo.class.getSimpleName(), "result")
        .addJavadoc("@throws $L $L\n", Exception.class.getSimpleName(), "exception")
        .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
        .addParameter(Message.class, "message")
        .build();

转载:
作者:滑稽是我弟弟
链接:https://juejin.cn/post/6844904022600597517
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值