Create Field Template (Alt+Enter)

Hello, pretty simple question, is there a way for new fields, parameters etc. introduced using the alt+enter shortcut to automatically have the keyword final prepended to it? I use these shortcuts quite frequently and I love the final keyword; fewer keystrokes are always better.

If there isn't a way at present, just let me know and I'll file a feature request on youtrack.

P.S. Since I typically only post questions relating to what IntelliJ lacks, I just wanted to take a moment to mention how much I appreciate all the hard work and care that has gone into this product. I switched from eclipse nearly a year ago and I must say, every day I enjoy using IntelliJ more and more; truly a fantastic editor.

0

Settings | Code Style | Java | Code Generation

No such option is available for fields, because it's not clear whether it's appropriate to have this as default behavior.

0

I'm sure you've given this more thought than I have fram a syntactic perspective, but what about implementing one or both of the following options:

1) Optimistic, if able to add the keyword final without errors, do so
2) Regardless, always add the final keyword regardless of whether doing so would cause errors

Examples:

TheOnlyCtor.java

public TheOnlyCtor() {
     _someDesiredField // (alt+enter) -> [create field (right arrow ->) final field]
}

If create field is selected, since _someDesiredField isn't referenced anywhere else in the file, it can be made final, so go ahead and add the keyword for me when creating the new field (yay fewer keystrokes).

TwoCtors.java

public TwoCtors() {
    _someDesiredField // (alt+enter) -> [create field (right arrow ->) final field]
}

public TwoCtors(final String param) {
}

In this case, if I select create field, the best you can do is give me a non-final field, since you can't know if the field will be initialized properly from both ctors, but if I select create final field, then the keyword would be added regardless and underlined with a red squiggly stating that it may not have been initialized.

Thoughts?

I know this is a minor issue, but it's the little conveniences I love the most, e.g., ctrl+F12 is the best pop-up ever!

0

请先登录再写评论。