简体   繁体   English

在IntelliJ IDEA中,如何为在当前实例上执行的方法调用着色?

[英]In IntelliJ IDEA, how can I color method calls acting on the current instance?

I find it useful to have fields colored in different way than local variables so that I find it easier to visually read the code flow. 我发现以不同于局部变量的方式为字段着色是很有用的,因此我发现更容易直观地读取代码流。

In the same way, I would like to color method calls acting on the current instance, so that they look different from method calls acting on other instances (regardless of their type). 同样,我想为作用在当前实例上的方法调用涂上颜色,以使它们看起来不同于作用在其他实例上的方法调用(无论其类型如何)。 This should affect interface methods, inherited methods, abstract methods... 这应该影响接口方法,继承的方法,抽象方法...

These methods are most of the time self-documenting code, or duplicated code that was refactored but not deemed worthy enough of having another class handle the common logic. 这些方法大多数时候是自记录代码,或者是重构的重复代码,但被认为不足以让另一个类处理通用逻辑。 Therefore I find it useful to visually see I'm not leaving the responsibility of this class. 因此,从视觉上看我没有离开这个班级的责任,我发现这很有用。

How can I achieve this in IntelliJ Idea? 如何在IntelliJ Idea中实现这一目标?


I am writing this question because I have found a similar question related to Android Studio while looking for an answer to this, but when I tried to google/search the question days later it was absolutely painful as it did not come up anywhere in the search results, I did not remember how I found it in the first place. 我写这个问题的原因是,在寻找答案的同时我发现了一个 Android Studio相关的类似问题 ,但是几天后当我尝试Google /搜索问题时,它却非常痛苦,因为它没有出现在搜索中的任何地方结果,我不记得我是如何找到它的。 I'm writing this question in the hopes it will be useful to any future reader having the same question. 我正在写这个问题,希望对将来有同样问题的读者有用。

There's a way, but it's a workaround, it will have side effects. 有一种方法,但这是一种解决方法,它将产生副作用。

IntelliWindows

How: 怎么样:

  • Go to File > Settings > Inspections (Choose the Global Profile if necessary). 转到文件>设置>检查(如有必要,请选择全局配置文件)。

  • Type in the search: qualified . 输入搜索内容: qualified

  • Tick the checkbox next to " Instance method call not qualified with 'this' ". 勾选“ 实例方法调用不符合'this' ”旁边的复选框。

  • Click on Severity > Edit severities, add new entry by clicking the green + button. 单击严重性>编辑严重性,单击绿色+按钮添加新条目。

    • Name it whatever you want. 随便命名。

    • You must put it at the bottom of the list using the arrows. 必须使用箭头将其放在列表底部 If you don't, the F2 key will no longer work as you expect it as it will prioritize errors at the top of the list. 如果您不这样做,则F2键将不再起作用,因为它将按优先级排列列表顶部的错误。

    • Set the Error stripe mark to #FFFFFF, or the same color as the scrollbar. 将错误条纹标记设置为#FFFFFF或与滚动条相同的颜色。

    • Set it bold if you wish. 如果需要,将其设置为粗体。

    • If you want to set a color, you must set a background color to white (or black if you have a black interface). 如果要设置颜色,则必须将背景颜色设置为白色(如果界面为黑色,则为黑色)。 If you don't, the color will appear black in most conditions. 如果不这样做,在大多数情况下颜色将显示为黑色。

  • If you really want to, do the same for " Unnecessary 'this' qualifier "; 如果确实要,请对“ 不必要的'this'限定符 ”执行相同的操作; there is an additional checkbox to make it only apply to methods and not fields. 还有一个额外的复选框,使其仅适用于方法而不适用于字段。

Side effects: 副作用:

  • This enables inspections, which is not desired. 这样可以进行检查,这是不希望的。

  • Pointing the mouse cursor onto the method calls will cause a hover text to appear describing the inspection. 将鼠标指针指向方法调用将导致显示一个悬停文本来描述检查。

  • If your code has no errors, no warnings, and no additional informative inspections, pressing F2 will jump through these calls. 如果您的代码没有错误,没有警告,也没有进行任何其他有益的检查,则按F2键将跳过这些调用。

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

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