| Summary: | [introduce factory] Introduce Factory ignores a type parameter | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Milos Gligoric <milos.gligoric> | ||||
| Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> | ||||
| Status: | CLOSED WONTFIX | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | manju656, samrat.dhillon | ||||
| Version: | 4.2.1 | Flags: | manju656:
review?
(manju656) |
||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Linux | ||||||
| Whiteboard: | stalebug | ||||||
| Attachments: |
|
||||||
Issue is reproducible using I20121029-2000. The code refactoring results in compiler error. Created attachment 236747 [details] Proposed fix and Test The existing code only copies the type parameters of the declaring class, but if the constructor itself declares any type parameters they are not copied to the factory method. Now copying the type parameters of the constructor as well. This change gives rise to another problem when we have duplicate type parameters in declaring class and the constructor. e.g. consider the code snippets below: class CtorTypeParam<E> { private <E> CtorTypeParam(E p) { } } class CtorTypeParam<E> { private <E extends Number> CtorTypeParam(E p) { } } class CtorTypeParam<E extends Number> { private <E> CtorTypeParam(E p) { } } Here the constructor is hiding the type parameters of the class. While creating the factory method it is difficult to determine which is the right type parameter. In my changes what I have done is that the code now detects if there are duplicate type parameter names. If so we show a warning to the user with the message "Ambiguous type Parameters on constructor and Declaring Type. Refactoring may lead to compilation error". If the user proceeds, the code builds a unique list of type parameter names, adding the type parameters of the constructor first as they are hiding the type parameters of the class, and then adding the type parameters of the class only if the same parameter name does not already exist. This contribution complies with http://www.eclipse.org/legal/CoO.php 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. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. 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. |
Steps to reporoduce: 1. Invoke "Introduce Factory" on "C" constructor in code below 2. Confirm default settings for the transformation 3. The resulting code does not compile ("F cannot be resolved to a type") class C<E> { // Invoke "Introduce Factory" on the following constructor <F extends E> C(F p) { } } (Thanks to Yilong Li for helping with the bug report.)