Community
Participate
Working Groups
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:
Created attachment 56840 [details] screenshot of the problem A screenshot exhibiting the problem
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.
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
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.
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.