This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 214128 - Create Refactoring Options That Work With Multiple Selected Classes
Summary: Create Refactoring Options That Work With Multiple Selected Classes
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 7.2
Hardware: All All
: P3 normal with 1 vote (vote)
Assignee: Ralph Ruijs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-13 13:07 UTC by mjr_1974
Modified: 2012-06-13 17:24 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mjr_1974 2012-06-13 13:07:35 UTC
Product Version = NetBeans IDE 7.2 Beta (Build 201205031832)
Operating System = Linux version 2.6.35-32-generic running on amd64
Java; VM; Vendor = 1.7.0_03
Runtime = Java HotSpot(TM) 64-Bit Server VM 22.1-b02

Some (most?) of us use the refactoring copy option to avoid creating a new class from scratch (new class that will likely share some functionality with the first one).
I think a refactoring option should exist for this case, in which it will compare methods names and signatures from those classes, present a window -like the one for extracting a superclass or interface- with the methods that exist in both classes and the option to select where to save the soon-to-be-created superclass or interface. 
Obviously this method should modify the first classes to extends/implement the new superclass/interface.
Comment 1 Ralph Ruijs 2012-06-13 14:08:53 UTC
Sounds interesting, but I'm not really sure I fully understand. Could you describe a use case, with a before and after code-sample?
Thanks!
Comment 2 mjr_1974 2012-06-13 17:24:36 UTC
@ralphbenjamin

Yes, it might be a bit long, but here it goes:
Suppose you start with this class:

-------------------------------------------------
package myorg.package

public class A {
    public void method1() {...}
    public void method2(int arg2) {...}
    public void method2(String arg3) {...}
}
-------------------------------------------------

and you copy it to another package (it could be the same package too) and you chage its name to B, you also add and remove some methods:

-------------------------------------------------
package myorg.anotherpackage

public class B {
    public void method1() {...}
    public void method2(int arg2) {...}
    public int getNumber() {...}
    public String getName() {...}
}
-------------------------------------------------

Because the class was copied, the implementation of method1 and method2 are redundant, so a superclass could be used there.

Now, in the Projects view, I would like to select both classes (Ctrl + click), make a right click on either of them, select Refactoring, and extract superclass (or extract common superclass). 

Because 2 (there might be more) classes were selected, the refactoring code would compare the methods contents (if they were different, the user could select which implementation should go to the soon-to-be-created superclass) and will ask for a superclass name, its location and if it should be made abstract (pretty much the same options we currently have for refactoring).

Let's say that we choose SuperclassAB for its name, myorg.commonpackage for the package in which it should be located and we choose to make it abstract.
The code after refactoring would look like this:

-------------------------------------------------
package myorg.commonpackage

public abstract class SuperclassAB {
    public void method1() {...}
    public void method2(int arg2) {...}
}
-------------------------------------------------

-------------------------------------------------
import myorg.commonpackage.SuperclassAB;

package myorg.package

public class A extends SuperclassAB {
    public void method2(String arg3) {...}
}
-------------------------------------------------

-------------------------------------------------
import myorg.commonpackage.SuperclassAB;

package myorg.anotherpackage

public class B extends SuperclassAB {
    public int getNumber() {...}
    public String getName() {...}
}
-------------------------------------------------

Of course the same could be applied if we want to extract a common interface. In this case the code code would be:


-------------------------------------------------
package myorg.commonpackage

public abstract class IntefaceAB {
    void method1();
    void method2(int arg2);
}
-------------------------------------------------

-------------------------------------------------
import myorg.commonpackage.InterfaceAB;

package myorg.package

public class A implements InterfaceAB {
    @Override public void method1() {...}
    @Override public void method2(int arg2) {...}
    public void method2(String arg3) {...}
}
-------------------------------------------------

-------------------------------------------------
import myorg.commonpackage.IntefaceAB;

package myorg.anotherpackage

public class B implements InterfaceAB {
    @Override public void method1() {...}
    @Override public void method2(int arg2) {...}
    public int getNumber() {...}
    public String getName() {...}
}
-------------------------------------------------

Well, I hope the idea is clear now... Please let me know if you need any further clarification.
Thanks!