更改 IntelliJ 创建的默认方法参数

发布于 2024-12-23 02:53:12 字数 698 浏览 2 评论 0原文

当我要求 IntelliJ 自动创建方法时,我想更改 IntelliJ 生成的默认参数。

例如,如果我在方法 generate()< 之前编写以下内容(这只是一个示例,这个问题不是关于使用 List 而不是 ArrayList) /em> 被创建:

generate( new ArrayList<String>{}, 42 );

并要求 IntelliJ 创建该方法,它创建了这个:

private void generate( ArrayList<String> strings, int i ) {
}

但我想要这个:换句话说,

private void generate(
    @NotNull final ArrayList<String> strings,
    final int i
) {
}

我想要:

  • 每个基元前面都有 final 关键字
  • 每个非原语前面都有final 关键字
  • 每个非基元前面都有 @NotNull 注释
  • (理想情况下)每个参数都单独一行

我该怎么做?

I'd like to change the default generated parameters by IntelliJ when I ask it to automatically create a method.

For example if I write the following (it's just an example, this question isn't about using List instead of ArrayList), before the method generate() is created:

generate( new ArrayList<String>{}, 42 );

and ask IntelliJ to create the method, it creates this:

private void generate( ArrayList<String> strings, int i ) {
}

But I'd like to have this instead:

private void generate(
    @NotNull final ArrayList<String> strings,
    final int i
) {
}

In other words I'd like:

  • every primitive to be preceded by the final keyword
  • every non primitive to be preceded by the final keyword
  • every non primitive to be preceded by the @NotNull annotation
  • (ideally) every parameter to go on its own line

How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤芳又自赏 2024-12-30 02:53:12

进入设置并查看大部分内容的代码格式。

我不确定 @NotNullfinal 选择。

更新:我认为如果您告诉 IntelliJ 您想要 JDK 6 或更高版本的语言功能,@NotNull 注释将会显示。当然,这意味着您必须使用 JDK 6 或更高版本进行编译。

其余的应该在代码样式设置下。或者文件或方法模板。

Go into the settings and have a look at the code formatting for most of this.

I'm not sure about the @NotNull or final choices.

UPDATE: I think @NotNull annotation will show up if you tell IntelliJ that you want JDK 6 or higher language features. This means that you have to compile with JDK 6 or higher, of course.

The rest should be under code style settings. Or file or method templates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文