Bug 170336 - [5.0][content asssit] foreach template misses last > in nested generics
Summary: [5.0][content asssit] foreach template misses last > in nested generics
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.2.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: bugday
Depends on:
Blocks:
 
Reported: 2007-01-12 12:35 EST by Hendrik Maryns CLA
Modified: 2018-11-24 09:07 EST (History)
3 users (show)

See Also:


Attachments
screenshot of the problem (2.62 KB, image/png)
2007-01-12 12:38 EST, Hendrik Maryns CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hendrik Maryns CLA 2007-01-12 12:35:41 EST
Build ID: M20060921-0945

Steps To Reproduce:
1. Declare a generic Map which has as value argument a class which itself has a generic argument, e.g. Map<Object, Set<Integer>>, then assign its entryset to a variable.
2. type ‘fore’ then hit Ctrl-Space
3. The foreach template appears.  However, in the suggested type of the element, only Entry<Object, Set<Integer> is selected to be replaced.  The second > is missed.


More information:
Comment 1 Hendrik Maryns CLA 2007-01-12 12:38:57 EST
Created attachment 56840 [details]
screenshot of the problem

A screenshot exhibiting the problem
Comment 2 Missing name CLA 2012-11-19 18:39:08 EST
Build id: 20121004-1855

In addition to missing the last ">": if the generic type contains two generic types as the arguments, then the last two characters are missing. For examples, in the case of "Triple<Set<Double>, ArrayList<Double>, Double>", the last two characters "e>" are missing.
Comment 3 Robert Roth CLA 2015-03-27 17:31:49 EDT
OK, I've found the reason for this, but I can't find the solution for it, so I'm putting down my findings here, maybe someone more experienced can use these:
The problem comes from TemplateProposal.java[1] where the TemplateProposal class tries to find the selection bounds of the first variable to be highlighted for editing, which happens to be the iterable type (e.g. Entry<Object, Set<Integer>> in the case given in the description).
To find this it queries the variable length, which is the length of "Entry<Object,Set<Integer>>", without formatting, but the code generated based on the template is already formatted after generation, thus the selection bound will be off by one (or more, depending on the number of spaces added by formatting the type - e.g. in comment 2 the formatted type has 2 spaces, thus the last two characters will be cut off).

[1] http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/tree/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/TemplateProposal.java#n236
Comment 4 Robert Roth CLA 2015-03-27 17:37:55 EDT
My theory can easily be checked by adjusting the formatter to not use " " after comma in parametrized type references (Code formatter settings-> white space-> Parametrized types->type reference->after comma must be unchecked).
After this change, foreach with template is correctly generated and the iterable type is correctly selected after generating it.
Comment 5 Eclipse Genie CLA 2018-11-24 09:07:40 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.