Project: JDT
Bug 167472 [quick fix] Suggest to add missing type for for-each variable
Reported: 2006-12-11 14:29:43 | Status: verified fixed

Given the code: ArrayList<T> list = new ArrayList<T>(); for (item : list) { // error } There is an error on "item", as it is undeclared. Quickfix asks if you want to create a class, interface or enum for "item", or add a type parameter "item" to the class. I would expect a suggestion of declaring an iterator variable "T item". (Also the compiler is confused because it says on "list" that "Cannot convert element type T to item", so it thinks item is a type.) This looks like a trivial content-assist but saves a lot of typing when iterating through complex generic containers-inside-containers.

Files changed in fix:
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedTypesQuickFixTest.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/ASTResolving.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/TypeMismatchSubProcessor.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsSubProcessor.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/proposals/NewVariableCorrectionProposal.java