In Eclipse, after a line like this:
List list = new ArrayList();
Typing “for” just beneath, and followed by “ctrl-space” (by default), will bring several options that can help completing this “for loop”:

But if the variable “list” is declared far from here (e.g. as a class field) which may not be directly inferred from this context, or there are many Lists declared,then the assistance doesn’t work well:

@@ split line —

In some cases, Eclipse can assist, but just don’t work for member variable. E.g. manually type “another” and ENTER after the “:” didn’t persuade Eclipse to guess about it….
(P.S. workable case:
Auto guessed

Entered wanted name, and ENTER, works great
)
Does anyone have any tip to make this assistance work under such scenarios?
What I usually do to solve the content assist with for loop is the following:
create a local variable by typing collection variable that is declared far above and a semicolon:
press Ctrl+2 L
Eclipse generates a new local variable declaration which looks like this:
type my foreach and autocomplete with Ctrl+space getting the following:
place cursor on list2 in the for loop declaration and press Alt+Shift+I which stands for inline variable.
this results in what you want to achieve. The effort is minimal after some practicing: