更改 IntelliJ 创建的默认方法参数
当我要求 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
进入设置并查看大部分内容的代码格式。
我不确定
@NotNull
或final
选择。更新:我认为如果您告诉 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
orfinal
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.