How to diff two regions of the same file in Eclipse

为君一笑 提交于 2019-12-08 16:41:28

问题


I'm a TDDer and often have a need to refactor out common or similar code. Similar code is not always a result of copy and paste.

I'm not looking for tools to identify the regions or suspected duplications, there are a number of tools to do that. And if the code is exactly the same there is no big problem, Eclipse can almost always do that by itself.

I am looking for tools to visualize differences of sections of code that are radically different, but my human eye can see the structural similarities, and could possibly be made even more similar, so that the common code eventually could be factored out.

It would be very handy if there was a possibility to mark two regions and get Eclipse (or some other tool) to mark the differences. With this information it would be much simpler to iteratively move the regions closer until they are the same and then activate the Extract Method refactoring.

It can be done in Emacs of course, but I'd like to have this readily available from Eclipse. Any pointers?


回答1:


Seems there was somewhat usable answers in this question, a question articulating the same need. But, again those answers focus on finding duplications, not vizualising it.

Two suggestions that works are KDiff3 and Diffuse. Both allow you to open up the same file twice or paste different sections in the panes. There seems to be no way to use them from Eclipse though.




回答2:


I don not know of a way to mark regions and diff them in eclipse, but you can diff two files. In that way you might get what you are looking for by copying out the parts you want to diff in two paste files, at least 90%?

Select the two files you want to diff in the project tree and right-click -> select compare with -> each other.

cheers, Jørgen



来源:https://stackoverflow.com/questions/2818082/how-to-diff-two-regions-of-the-same-file-in-eclipse

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