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

Bug 539067

Summary: [Quickfix] "Create Method" quickfix with generic parameter types needs to add type parameter to new method
Product: [Eclipse Project] JDT Reporter: Luke Hutchison <luke.hutch>
Component: UIAssignee: Jeff Johnston <jjohnstn>
Status: CLOSED MOVED QA Contact:
Severity: normal    
Priority: P3 CC: gautier.desaintmartinlacaze, jjohnstn, stephan.herrmann
Version: 4.8   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard: stalebug

Description Luke Hutchison CLA 2018-09-14 06:05:32 EDT
Given this method

    public static <T> void test(T a) {
        test(a, a);      // error here
    }

Apply "Quickfix > Create method 'test(T, T)'", which adds this method:

    private static void test(T a, T a2) {
    }

The method is missing its own type parameter <T>.
Comment 1 Luke Hutchison CLA 2018-09-14 06:16:22 EDT
Another related but different problem: if the destination is already generic, the correct type variable is not used.

Before quickfix:

    public class Bug {
        
        private static class Class1<T> {
            T t;
            Class2<T> c2;
            
            void method() {
                c2.useT(t);  // Quickfix "Create method 'useT(T)' in Class2"
            }
        }
    
        private static class Class2<U> {
        }
    }

After quickfix:

    public class Bug {
        
        private static class Class1<T> {
            T t;
            Class2<T> c2;
            
            void method() {
                c2.useT(t);
            }
        }
    
        private static class Class2<U> {
            public void useT(T t) {  // Should be (U t), not (T t)
            }
        }
    }
Comment 2 Eclipse Genie CLA 2020-10-02 09:26:30 EDT
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 3 Luke Hutchison CLA 2020-10-02 13:06:29 EDT
Pinging so that this doesn't get closed.
Comment 4 Eclipse Genie CLA 2022-11-02 17:24:20 EDT
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 5 Jeff Johnston CLA 2022-11-07 11:21:00 EST
(In reply to Luke Hutchison from comment #0)
> Given this method
> 
>     public static <T> void test(T a) {
>         test(a, a);      // error here
>     }
> 
> Apply "Quickfix > Create method 'test(T, T)'", which adds this method:
> 
>     private static void test(T a, T a2) {
>     }
> 
> The method is missing its own type parameter <T>.

This problem has been opened as issue: 

https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/322 and fixed for 4.26 M3
Comment 6 Jeff Johnston CLA 2022-11-07 16:38:51 EST
(In reply to Luke Hutchison from comment #1)
> Another related but different problem: if the destination is already
> generic, the correct type variable is not used.
> 
> Before quickfix:
> 
>     public class Bug {
>         
>         private static class Class1<T> {
>             T t;
>             Class2<T> c2;
>             
>             void method() {
>                 c2.useT(t);  // Quickfix "Create method 'useT(T)' in Class2"
>             }
>         }
>     
>         private static class Class2<U> {
>         }
>     }
> 
> After quickfix:
> 
>     public class Bug {
>         
>         private static class Class1<T> {
>             T t;
>             Class2<T> c2;
>             
>             void method() {
>                 c2.useT(t);
>             }
>         }
>     
>         private static class Class2<U> {
>             public void useT(T t) {  // Should be (U t), not (T t)
>             }
>         }
>     }

This has been opened in github as: https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/330

and will be fixed by 4.27 M1
Comment 7 Jeff Johnston CLA 2022-11-07 16:39:51 EST
Both issues have been opened in github so closing this bug.