Bug 103686 - [quick fix] Convert to enhanced for loop does not convert loop with Enumeration
Summary: [quick fix] Convert to enhanced for loop does not convert loop with Enumeration
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1.1   Edit
Assignee: Tobias Widmer CLA Friend
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-13 13:29 EDT by Markus Keller CLA Friend
Modified: 2005-09-02 10:51 EDT (History)
1 user (show)

See Also:


Attachments
patch to handle java.util.Enumeration as well (2.12 KB, application/x-zip-compressed)
2005-08-08 06:59 EDT, Tobias Widmer CLA Friend
no flags Details
simplified patch (1.96 KB, application/x-zip-compressed)
2005-08-08 10:47 EDT, Tobias Widmer CLA Friend
no flags Details
improved patch (1.97 KB, patch)
2005-08-10 11:51 EDT, Tobias Widmer CLA Friend
no flags Details | Diff
patch (1.96 KB, patch)
2005-08-10 13:16 EDT, Tobias Widmer CLA Friend
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA Friend 2005-07-13 13:29:34 EDT
3.1

I wanted to convert this for loop to an enhanced for loop, but the quick fix did
not appear:

private synchronized Vector<TestListener> cloneListeners() {
	return (Vector<TestListener>)fListeners.clone();
}

public void endTest(Test test) {
	for (Enumeration<TestListener> e= cloneListeners().elements();
			e.hasMoreElements(); ) {
		TestListener nextElement = e.nextElement();
		nextElement.endTest(test);
	}
}
Comment 1 Dirk Baeumer CLA Friend 2005-07-13 17:53:02 EDT
Tobias, is looks like we missed this. How hard would it be to fix this for 3.1.1?
Comment 2 Tobias Widmer CLA Friend 2005-07-14 04:34:16 EDT
Its quite the same as the iterator case. I can quickly fix this
Comment 3 Dirk Baeumer CLA Friend 2005-07-14 12:21:59 EDT
Can you please investigate a fix for 3.1.1
Comment 4 Tobias Widmer CLA Friend 2005-08-08 06:59:53 EDT
Created attachment 25826 [details]
patch to handle java.util.Enumeration as well

Dirk, Markus, can you approve this patch?
Comment 5 Dirk Baeumer CLA Friend 2005-08-08 10:20:26 EDT
Tobias, a question:

ConvertIterableLoopProposal#isApplicable

- why is the type binding inspected for the enumeration case
  final ITypeBinding type= binding.getReturnType();

  whereas the for the iterable case it is 

  final ITypeBinding type= qualifier.resolveTypeBinding();

- some of the code between the iterable and enumeration case in isApplicable 
  could be shared (all inside iterable != null).

Rest of the patch looks fine for me.
Comment 6 Tobias Widmer CLA Friend 2005-08-08 10:47:01 EDT
Created attachment 25835 [details]
simplified patch

Simplified the patch, doing code sharing
Comment 7 Tobias Widmer CLA Friend 2005-08-10 09:11:31 EDT
Dirk, Markus, can you please cast your vote?
Comment 8 Dirk Baeumer CLA Friend 2005-08-10 11:26:24 EDT
Looks good for me, except of: shouldn't we test for java.util.Enumeration< and
java.util.Iterator< to make sure that we don't get tricked by a class
java.util.Enumeration2
Comment 9 Tobias Widmer CLA Friend 2005-08-10 11:51:01 EDT
Created attachment 25978 [details]
improved patch
Comment 10 Markus Keller CLA Friend 2005-08-10 13:01:00 EDT
No-go for the improved patch.

First and last changes:
"if (binding != null ..." comes after "binding.getName();"

This causes an NPE when applied to e.g. this for loop:
	void m(Vector<String> vec) {
		for (Iterator iter = vec.iterator(); iter.hasNext();) {
			String string = (String) iter.negst();
		}
	}

The rest looks fine.
Comment 11 Tobias Widmer CLA Friend 2005-08-10 13:16:56 EDT
Created attachment 25986 [details]
patch
Comment 12 Markus Keller CLA Friend 2005-08-10 13:55:36 EDT
Attachment 25986 [details] looks good. +1 for 3.1.1.

Tobias: The last two patches had mime-type text/plain, which is wrong for zip
files and makes handling more tedious. Please select auto-detect as content type.
Comment 13 Tobias Widmer CLA Friend 2005-08-11 04:32:04 EDT
Fixed in 3.1.1 maintenance stream > 20050811
Comment 14 Markus Keller CLA Friend 2005-08-11 06:44:30 EDT
Tobias, you released the test to HEAD, not R3_1_Maintenance.
Comment 15 Tobias Widmer CLA Friend 2005-08-11 06:54:10 EDT
Released test to 3.1.1 maintenance stream
Comment 16 Tobias Widmer CLA Friend 2005-08-15 04:34:37 EDT
Fixed in HEAD > 20050815
Comment 17 Dirk Baeumer CLA Friend 2005-09-02 09:50:22 EDT
Start verification...
Comment 18 Dirk Baeumer CLA Friend 2005-09-02 10:51:41 EDT
Verified that converting enumeration for loops works and the iterator and array
still works. Opened bug 108672 to track an exception with converting the
enumeration case.