Bug 518619

Summary: [quick assist] Enhanced for loop's loop variable name should take getters into account
Product: [Eclipse Project] JDT Reporter: Andreas Sewe <sewe>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert
Version: 4.7   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Andreas Sewe CLA 2017-06-22 05:25:51 EDT
The "Create enhanced 'for' loop" quick fix is ATM less smart than its "Assign statement to local variable" cousin.

A real life example:

  classHierarchy.getUnresolvedClasses();

    - Assign statement to local variable ->

  Set<TypeReference> unresolvedClasses = classHierarchy.getUnresolvedClasses();

This is great. But this could be better:

  classHierarchy.getUnresolvedClasses();

    - Create enhanced 'for' loop ->

  for (TypeReference typeReference : classHierarchy.getUnresolvedClasses()) {
  }

I realize, of course, that the latter requires some heuristics to convert the plural "UnresolvedClasses" into the singular "unresolvedClass", but covering 95% of the cases in English should be possible (just a gut feeling, though).