Can eclipse autocomplete on the left side of assignment operator?
Asked Answered
S

2

5

If I have typed out an expression that returns a known type, is there a way for eclipse to content-assist the creation of that type, potentially with templated variable names?

The screenshot below is an example of where this would be useful. You'll notice that if I hover my mouse over the getModel() method, it clearly states that it can only return a single type of Map<String, Object>. But if I then type Ctrl-Space with my cursor to the left of the =, nothing happens. Preferably, it would create the whole Map<String, Object> model that you see commented out, with model being templated so you could tab to it, and quickly enter your variable name.

I suppose it's even possible that it could infer the default variable name based on the getter method name...

Example of where left side autocomplete would be useful.

Sari answered 23/11, 2014 at 0:49 Comment(0)
T
9

You could probably use the extract variable refactoring for this use case.

First type

mv.getModel()

Then go to Refactor/Extract Local Variable or just hit SHIFT+ALT+L.

It will then prompt you for variable name and after you hit enter you should get:

Map<String, Object> variableName = mv.getModel();

I know that the question is about content assist, but as far as I know it isn't possible to do this that way. Hopefully this is an acceptable alternative. If someone knows a better solution feel free to correct me.

Tartary answered 23/11, 2014 at 0:56 Comment(1)
While not technically content-assist, I think it does essentially solve the problem. :)Sari
A
2

The shortcut for Mac: 2 + l (lowercase L key) See: https://mcmap.net/q/793791/-generate-local-variable-to-receive-the-return-value-of-a-method-eclipse

Aureole answered 27/2, 2018 at 7:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.