Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Eclipse have a tool to merge a type hierarchy into a single class?

Tags:

java

eclipse

Does eclipse have a tool that can create Merged from A and B ?

public class A {
    int a;

    public int getA(){
        return A;
    }
}

public class B extends A {
    int b;

    public int getB(){
        return b;
    }
}

public class Merged {
    int a;
    int b;

    public int getA(){
        return A;
    }
    public int getB(){
        return b;
    }
}
like image 844
unR Avatar asked Jul 18 '11 08:07

unR


People also ask

How do I type a hierarchy in Eclipse?

Press Ctrl+Shift+H -or- from the Menu Bar go to Navigate | Open Type in Hierarchy. The "Open Type in Hierarchy" dialog is displayed.

How do I create a class definition in eclipse?

You can ctrl-click on the variable name and you get to the variable declaration. And then you can ctrl-click on the type to get to the class definition.

How do I select a class to run in Eclipse?

Step 1: Open Eclipse and click File > New > Java Project. Step 2: Provide the Project Name and click on the Finish button. Step 3: In the Package Explorer (left-hand side of the window) select the project which you have created. Step 4: Right-click on the src folder, select New > Class from the submenu.


1 Answers

I don't think so. It's not so simple task. Your example is simple, but consider this:

class A {
    private int a;
    public void foo(){
        System.out.println(a);
    }
}

class AA extends A {
    private int a; //its not the same 'a'!!
    public void foo(){ //ok, we override, so we can 'overwrite', but...
        super.foo(); //... what with this?
        System.out.println(a);
    }
}

As you can see, its hard to automate. And what if some class in this hierarchy extends some lib class, for which you don't have sources? So, merging is hard, and very very bad, thats why I don't think anyone wrote such tool.

like image 95
Adam Jurczyk Avatar answered Oct 17 '22 06:10

Adam Jurczyk