Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 444002 - [pull up] "Refactor > Pull up" adds unnecessary import
Summary: [pull up] "Refactor > Pull up" adds unnecessary import
Status: CLOSED DUPLICATE of bug 497368
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 467490 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-09-12 18:36 EDT by Zorzella Mising name CLA
Modified: 2016-07-15 07:52 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zorzella Mising name CLA 2014-09-12 18:36:48 EDT
The "Pull up" refactoring, when used to pull up to an interface, has all sorts of quirks. Here's a few, illustrated by an example (more quirks at the bottom). Start with this class and pull up the "baz" method. Accept the warning to make the method more visible:

public class PullUpToInterfaceBug {

  interface Foo {
  }
  
  static class Bar implements Foo {
    
    /** baz it! */
    void baz(final String s) {
    }
  }
}

******************

You end up with this

******************

public class PullUpToInterfaceBug {

  interface Foo {
    protected abstract void baz(final String s);
  }
  
  static class Bar implements Foo {
    /** baz it! */
    @Override
    protected void baz(final String s) {
    }
  }
}
*****************

1. the method added to the interface is declared "protected" and "abstract", and the param is "final", none of which are appropriate for interfaces (it should read be "void baz(String s)")

2. the javadoc was not moved (or even copied) to the interface

3. the visibility of the implemented method went to "protected", which is invalid. It should be "public"

4. Furthermore, if doing the same to this class:

*****************

import java.util.List;

public class PullUpBaz implements PullUpToInterfaceBug.Foo {

  public void b() {
    List<Object> l = null;
  }
}

*****************

causes PullUpToInterfaceBug to have an import of java.util.List, even though List is not used in the signature (only in the method body).
Comment 1 Noopur Gupta CLA 2014-09-17 08:30:52 EDT
(In reply to "Z" Zorzella from comment #0)
> 
> 1. the method added to the interface is declared "protected" and "abstract",
> and the param is "final", none of which are appropriate for interfaces (it
> should read be "void baz(String s)")
> 
> 3. the visibility of the implemented method went to "protected", which is
> invalid. It should be "public"

These 2 will be handled in bug 428965.

> 2. the javadoc was not moved (or even copied) to the interface 

This will be handled in bug 326832.

> 4. Furthermore, if doing the same to this class:
> causes PullUpToInterfaceBug to have an import of java.util.List

Updated this bug's title to reflect this issue.
Comment 2 Noopur Gupta CLA 2015-05-25 04:53:52 EDT
*** Bug 467490 has been marked as a duplicate of this bug. ***
Comment 3 Noopur Gupta CLA 2016-07-15 07:52:36 EDT

*** This bug has been marked as a duplicate of bug 497368 ***