Project: JDT
Bug 37913 Suggest creating field instead of local variable if naming matches preferences for field [quick fix]
Reported: 2003-05-21 08:22:03 | Status: verified fixed

Eclipse has a defined list of prefixes (or suffixes) for fields when generating code. I have defined, for example, that local fields begin with _ but of course other naming conventions (e.g. f) are also possible. When I write an assignment such as: public void setThing(Object arg) { _arg = arg; } then it provides with a list of suggestions, including (a) rename to arg, (b) create local variable _arg, (c) create field _arg, and (d) create parameter _arg. Ideally, if variable name _arg matches the naming conventions for the local field as defined in the code generation window, then it should bump the priority up of (c) to first place, rather than having it down the bottom. Also, I don't think that the suggestion of renaming to 'arg' is helpful when the assignment is of the form _arg = arg, and should probably be pruned for that instance (which probably occurs a lot of the time); I'm not sure if that is worth filing as a separate suggestion or may fall out from the bugfix for this enhancement.

Files changed in fix:
org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsSubProcessor.java