简体   繁体   English

快速比较IntelliJ中的方法

[英]Quick way to compare methods in IntelliJ

I'm currently working on a legacy java code which was written with almost no coding conventions or common practices. 我目前正在研究遗留的Java代码,该代码几乎没有编写代码或常见做法。 I often come across working but very lousy code snippets (typos in variable names, redundancy and many others) that I find myself urging to fix. 我经常遇到工作但非常糟糕的代码片段(变量名称,冗余和许多其他的拼写错误),我发现自己要求修复。 In one of those instances, I've found a class that contains three methods with different names but almost identical method bodies. 在其中一个实例中,我发现一个类包含三个具有不同名称但几乎相同的方法体的方法。

As per my initial observation, the only difference was the name of one of the parameters. 根据我最初的观察,唯一的区别是其中一个参数的名称。

Before taking any steps and merge them though, I wanted to make a comparison of three methods to see if there's any subtle difference that I didn't notice. 在采取任何步骤并合并它们之前,我想对三种方法进行比较,看看是否存在我没​​有注意到的任何细微差别。

I know it's possible to compare two files, compare with the version from VCS etc. but I was not able to find a quick way to compare the method definitions in the same file. 我知道可以比较两个文件,与VCS等版本进行比较,但我无法找到快速比较同一文件中方法定义的方法。

Is there a more practical way to compare different sections of the same file in IntelliJ rather than copying them into different files and run a file comparison? 是否有更实用的方法来比较IntelliJ中同一文件的不同部分,而不是将它们复制到不同的文件并运行文件比较?

Thanks, 谢谢,

Another quick way to compare methods (or any block of code) within IntelliJ: 在IntelliJ中比较方法(或任何代码块)的另一种快速方法:

  1. Copy one version to the clipboard. 将一个版本复制到剪贴板。
  2. Highlight the other version. 突出显示其他版本。
  3. Use the "Compare with Clipboard" feature from either the context menu in the editor or from View > Compare with Clipboard. 使用编辑器中的上下文菜单中的“与剪贴板比较”功能,或从“视图”>“与剪贴板比较”。

IntelliJ has Locate Duplicates in the Analysis. IntelliJ在分析中找到重复项 It's highly configurable and language-aware to the point that it's not just looking for blocks of text that are the same. 它具有高度可配置性和语言感知能力,它不仅仅是寻找相同的文本块。 It would be able to detect if two blocks of code are the same, but with different variable names for example. 它能够检测两个代码块是否相同,但是具有不同的变量名称。

You can even expand the scope so that it detects code duplicates that in different files. 您甚至可以扩展范围,以便检测不同文件中的代码重复。

See this help page for more information. 有关更多信息,请参阅此帮助页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM