开发者

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜