Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 357408

Summary: [5.0][templates] Template for "while - iterate with iterator" adds unnecessary cast
Product: [Eclipse Project] JDT Reporter: Darin Wright <darin.eclipse>
Component: TextAssignee: JDT-Text-Inbox <jdt-text-inbox>
Status: ASSIGNED --- QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, hniederhausen, markus.kell.r
Version: 3.7   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug
Bug Depends on: 95787    
Bug Blocks:    
Attachments:
Description Flags
Example source file attached none

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.