Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automated way to Extract Interfaces from a Java Class

I've got a collection of concrete Classes which define an API, and I would like to extract the Interface of these classes (ie: essentially the type hierarchy and public methods) from the actual implementation of the API.

So for example if one of the public classes in the API is

 public class Foo extends Bar {
     /* some fields which I don't care about */

     public void method() {
     /* implementation here */
     } 

     public void otherMethod() {
     /* implementation goes here */
     }

    /* some non public methods which I don't care about */

 }

I would like to break into an interface and an implementation

ie

public interface FooInterface extends BarInterface {
    public void method();
    public void otherMethod()
}

 public class Foo implements FooInterface {
  /* etc etc */
 }

and

Is there a tool I can use to do this separation in automated way, or am I going to have to roll my own program to do the job? It needs to be a tool that requires minimal interaction.

like image 524
hhafez Avatar asked Jan 07 '11 04:01

hhafez


1 Answers

I found the solution!

Eclipse, has support for refactoring scripts, the scripts are in xml yet not very human friendly but I have generated the scripts anyway that makes eclipse perform all the refactoring.

For details of eclipse script refactoring, look here and use eclipse to generate a few examples for you so you know what the script should look like

like image 59
hhafez Avatar answered Oct 02 '22 22:10

hhafez