Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to compare two methods in eclipse

Tags:

diff

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?

  • the methods are of the same class.
like image 253
Zamir Avatar asked Jan 03 '12 05:01

Zamir


2 Answers

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.

like image 77
Jason Thompson Avatar answered Sep 20 '22 21:09

Jason Thompson


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

like image 30
Haoming Zhang Avatar answered Sep 17 '22 21:09

Haoming Zhang