Bug 357408 - [5.0][templates] Template for "while - iterate with iterator" adds unnecessary cast
Summary: [5.0][templates] Template for "while - iterate with iterator" adds unnecessar...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on: 95787
Blocks:
  Show dependency tree
 
Reported: 2011-09-12 15:03 EDT by Darin Wright CLA
Modified: 2023-12-19 18:18 EST (History)
3 users (show)

See Also:


Attachments
Example source file attached (599 bytes, text/plain)
2011-09-13 14:02 EDT, Darin Wright CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Wright CLA 2011-09-12 15:03:20 EDT
When using a collection with generics, the code assist template for "while - iterate with iterator" seems to add an unnecessary cast as well as fully qualified type names.

For example, I have a map defined as follows:

Map<JavaScriptError, Integer> errors;

When I use the code assist template to generate a while statement (iterator), it ends up with this code:

while (iterator.hasNext()) {
	Map.Entry<com.nr.aggregator.JavaScriptError, java.lang.Integer> entry = (Map.Entry<com.nr.aggregator.JavaScriptError, java.lang.Integer>) iterator.next();		
}

But, only the following is required (based on imports in the type), and is simpler to read:

while (iterator.hasNext()) {
	Map.Entry<JavaScriptError, Integer> entry = iterator.next();
}
Comment 1 Dani Megert CLA 2011-09-13 01:24:12 EDT
Can you provide more detailed steps/example, e.g. what imports are already in the source? Where do you insert the template? Also, please use types in your example that are available in the SDK.
Comment 2 Markus Keller CLA 2011-09-13 13:19:18 EDT
It's pretty much the same problem as bug 102747. Needs bug 95787 for a 1.4-compatible fix. But since 1.4 has been deprecated for so long now, I guess we can also just remove the cast now.


import java.util.Iterator;
import java.util.List;

public class E {
	public void m(List<Number> nums) {
		Iterator<Number> it= nums.iterator()
		while
	}
}
Comment 3 Darin Wright CLA 2011-09-13 14:02:38 EDT
Created attachment 203271 [details]
Example source file attached
Comment 4 Darin Wright CLA 2011-09-13 14:04:03 EDT
In the attached example, I invoked the "while - iterate with iterator" code assist template on line 16 - typed "whi" and then CTRL-space. The code filled in as shown in the source file. All required imports were already present.
Comment 5 Dani Megert CLA 2011-09-16 07:46:13 EDT
*** Bug 357910 has been marked as a duplicate of this bug. ***
Comment 6 Eclipse Genie CLA 2020-01-06 04:34:04 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 7 Eclipse Genie CLA 2021-12-28 16:21:12 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 8 Eclipse Genie CLA 2023-12-19 18:18:41 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.