我是一名 TDDer,经常需要重构常见或类似的代码。类似的代码并不总是复制和粘贴的结果。
我不是在寻找工具来识别区域或可疑的重复,有很多工具可以做到这一点。如果代码完全相同,那就没有什么大问题,Eclipse 几乎总是可以自己做到这一点。
我正在寻找工具来可视化完全不同的代码部分的差异,但我的肉眼可以看到结构相似性,并且可能变得更加相似,以便最终可以分解出公共代码。
如果能够标记两个区域并让 Eclipse(或其他工具)来标记差异,那将会非常方便。有了这些信息,就可以更简单地迭代地将区域移近,直到它们相同,然后激活提取方法重构。
当然可以在 Emacs 中完成,但我希望可以从 Eclipse 轻松获得此功能。有什么指点吗?
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?
发布评论
评论(2)
似乎这个问题中有一些有用的答案,表达相同需求的问题。但是,这些答案再次集中在查找重复项上,而不是对其进行可视化。
两个有效的建议是 KDiff3 和 扩散。两者都允许您打开同一文件两次或将不同的部分粘贴到窗格中。但似乎没有办法从 Eclipse 使用它们。
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.
我不知道如何在 Eclipse 中标记区域并比较它们,但您可以比较两个文件。这样,您可以通过在两个粘贴文件中复制出您想要比较的部分来获得您正在寻找的内容,至少 90%?
在项目树中选择要比较的两个文件,然后右键->选择比较->彼此。
干杯,
约尔根
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