Zamir
Zamir

Reputation: 1572

how to compare two methods in eclipse

I want to compare two methods that I think are the same, but the eclipse refactor won't make extract method from their content together.

Can I compare the two of the them using eclipse compare?

Upvotes: 15

Views: 4721

Answers (3)

c0der
c0der

Reputation: 18812

An illustration might make it easier to follow the instructions in this answer and this answer:

enter image description here

Upvotes: 1

Jason Thompson
Jason Thompson

Reputation: 4833

I'm using Eclipse Kepler, so depending on your version your mileage may vary.

To compare two methods in the same class, do the following:

  1. Open the class.
  2. Show the Outline view (Window->Show View->Outline)
  3. Hold CTRL and click on the two methods you wish to compare.
  4. Right click on one of the highlighted methods.
  5. Click on "Compare With->Each Other By Member"

You'll get a diff window similar to if you were comparing two files.

Update

Since answering this question, I have found a similar, but more powerful way to do this. Follow the steps above, except use the "Package Explorer" view rather than the outline view. The advantage of this is that you can choose to compare two methods that are in the same class or compare two methods that are in different classes. It's a great way to prove that two methods or subclasses are identical and can be refactored into a common shared resource.

Upvotes: 17

Haoming Zhang
Haoming Zhang

Reputation: 2852

May be you can put the two methods in different class file, and put them in Eclipse together. Then simply select them in the navigator or package explorer, right click, and click 'Compare with Each Other'.

Or you can check this question: Diff two methods in eclipse

Upvotes: 3

Related Questions