@NotNull in autocomplete in Intelilj 12?


Is there an easy way to enable auto-complete to add @NotNull to all applicable variables/paramters/method returns when generating as it would greatly reduce the keystroke in my coding?



1 comment
Comment actions Permalink

There is not. There are two options as I see it...

1) You can periodically run the "Infer Nullability" action via the menu Analyze | Infer Nullability... It does not have a key mapping by default; but you can obviously add one. This will insert "detectable" Nullable and NotNull parameters and return types. You'll want to be sure you configure a few things first.. See http://www.jetbrains.com/idea/webhelp/inferring-nullity.html

2) You could approach it the other way. Create a Live template that enters the @NotNull annotation and then invokes Auto Complete. An example is shown below, which is mapped to nn[tab]. With the way the example is shown, the cursor will end flush to the selection you make in auto complete. If you want a space, you can modify the below so there is a space after the auto complete variable followed by the predefined $END$ variable. By the way (in case you are not familiar with Live Templates), the "Auto Complete" variable can be named anything. What matters is the expression definition is "complete()" (or completeSmart()" if desired).  And of course, you can make variations of this template (one for @Nullable for example).



Please sign in to leave a comment.