Diff two methods in eclipse

隐身守侯 提交于 2019-12-25 07:59:15

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4812632/diff-two-methods-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!