I have a foreach loop in Java (simplified version here)
List<String> names = getNames(); for(String name:names) { doSomething(name); }
Is there an automated way to refactor this into a traditional for loop?
I know how to do it manually
List<String> names = getNames(); for(int i=0; i<names.size(); i++) { String name = names.get(i); doSomething(name); }
As you can see, in the for statement you need to enter a little text, and also enter the name variable and assign it the value names.get(i) . In general, manual editing is too error prone for me.
Why do I want to do this? I have to fix the error, and the correction should start from index 1 instead of index 0 and end with index n-1 instead of the end (unfortunately, I canβt fix the input right away, I need to wait for the library to update if it is recognized as an error).
What have i tried? I right-clicked the for keyword and clicked on "Refactor", but as far as I can get from the context menu entries, nothing would work for me.
Why do I think this could theoretically work? Since similar functionality exists in Resharper for Visual Studio (C #).
FYI: I am using Eclipse Luna SR 2 (4.4.2)
source share