IntelliJ IDEA auto-completion for collection type declaration with generics
intellij-idea, java
Solution
Why don't you make a `Live Template` for yourself?
For example, go to Live Templates, add a new template under other, give it an abbreviation `list`, a description as you like, and enter the template text:
List<$TYPE$> $VAR$ = new $END$
Where it says No applicable contexts, define: `Java` -> `Statement`
Now click `Edit variables` and bind as follows
TYPE -> expectedType()
VAR -> suggestVariableName()
Et voila. The keypresses are now: list tab St enter enter (varname) enter
result, with cursor:
List<String> myvar = new |
And from here you can hit ctrl-shift-space to autocomplete like so:
List<String> myvar = new ArrayList<>(|);
Hope this helps :)
Problem
I'm trying to figure out how it would be more efficient to type a declaration of a collection type with a generic. Typing: ``` List< ``` Automatically expands to: ``` List<|> ``` (cursor position is marked with "|") Typing ``` List<St|> ``` using the autocomplete it gets to ``` List<String|> ``` notice the cursor position Now the question: how could it be possible to get to the following state without using the arrow keys: ``` List<String> | ``` Ideally, id like to use statement autocompletion for this, but it rather jumps to the new line which is not desired in this situation.