问题
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:
- Open the class.
- Show the Outline view (Window->Show View->Outline)
- Hold CTRL and click on the method you wish to compare.
- Right click on the highlighted method.
- Click on "Compare With->Element From Local History"
- 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