fastcodejava
fastcodejava

Reputation: 41087

Diff two methods in eclipse

I have an eclipse which generates java code. So if a method is there and is regenerated I want to show the old method and the newly generated one so the user can see the difference. Is this possible?

Upvotes: 0

Views: 1278

Answers (2)

Jason Thompson
Jason Thompson

Reputation: 4833

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

To compare a method with a previously generated version, do the following:

  1. Open the class.
  2. Show the Outline view (Window->Show View->Outline)
  3. Hold CTRL and click on the method you wish to compare.
  4. Right click on the highlighted method.
  5. Click on "Compare With->Element From Local History"
  6. Double click with the revision you wish to compare with.

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

Upvotes: 1

mchv
mchv

Reputation: 963

If your code generator is the one used by default by EMF, you can copy the generated method, and remove the @generated tag to the original one, then simply suffix the copied generated method with Gen and keep the @generated tag. For instance :

/* original code */
public String getName() {
...
}

@generated
public String getNameGen() {
...
}

At the next generation only getNameGen will me modified and you will be able to compare.

If you are looking to a more general solution to know if the regeneration modified some files, the best way is probably to store you files on a repo (with SVN or Git). After a regeneration filez not in sync will be indicated with graphical decorators and you will be able to use the compare editor to see the differences for each of them.

Upvotes: 1

Related Questions