java 有没有办法在一个类的所有方法上设置断点?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15027323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:16:02  来源:igfitidea点击:

Is there any way to set breakpoints on all methods of a class?

javaintellij-idea

提问by Sergey Senkov

Is there any way to set breakpoints on all methods of a given class?

有没有办法在给定类的所有方法上设置断点?

I have a huge (2300 lines) legacy class and I need to set breakpoints on all method calls to understand how this mess works.

我有一个巨大的(2300 行)遗留类,我需要在所有方法调用上设置断点以了解这种混乱是如何工作的。

采纳答案by Sergey Senkov

I have discovered workaround :

1. I have set "Toggle Brakepoint" hotkey to Alt+Numpad 0.
2. After that you can click on first method
3. Use "Toggle Brakepoint"
4. Alt+Down- goto Next Method. ( Alt+Up- goto Previous Method. )
5. Repeat 3 step.

我发现了解决方法:

1. 我已将“Toggle Brakepoint”热键设置为Alt+ Numpad 0
2. 之后,您可以单击第一种方法
3. 使用“切换制动点”
4. Alt+ Down- 转到下一方法。( Alt+ Up- 转到上一个方法。)
5. 重复 3 步。

回答by vtsamis

You can follow the steps below:

您可以按照以下步骤操作:

  1. Run -> View breakpoints -> Add -> Java Method Breakpoints

  2. Class pattern -> full reference of your class (e.g., mypackage.MyClass)

  3. Method Name -> * (i.e., asterisk wild card)

  1. 运行 -> 查看断点 -> 添加 -> Java 方法断点

  2. 类模式 -> 类的完整参考(例如,mypackage.MyClass)

  3. 方法名称 -> * (即星号通配符)

Example

例子

回答by Gavin Haynes

This is similar to Sergey Senkov's answer, but without hotkeys.

这类似于 Sergey Senkov 的回答,但没有热键。

In the structure view, click on the first method. Repeat the following for each method:

在结构视图中,单击第一种方法。对每种方法重复以下操作:

  1. Context Menu Key
  2. Mto toggle the method breakpoint.
  3. Down
  1. Context Menu Key
  2. M切换方法断点。
  3. Down

回答by Andrey Lavrukhin

There is a plugin for idea: Simple Toggle All Method Breakpoint.

有一个想法插件: Simple Toggle All Method Breakpoint

It allows you to breakpoint all methods / clear all method's breakpoints in one click from context menu on class in Project view.

它允许您从项目视图中类的上下文菜单中一键单击所有方法的断点/清除所有方法的断点。

回答by Mirko Majki?

As Andrey Lavrukhin suggested, there is Simple Toggle All Method Breakpoint, install it through Settings -> Plugins. Works perfectly.

正如 Andrey Lavrukhin 所建议的,有Simple Toggle All Method Breakpoint,通过 Settings -> Plugins 安装它。完美运行。

回答by Sean Landsman

The only way you'll be able to do what you want is to set method breakpoints on each and every method with the class in question. You need to click on the left hand gutter next to the method - a little red circle with 4 dots will appear and you may get a warning saying method level breakpoints can impact performance. You can then further configure the breakpoint (by rightclicking on it, or select shift+F8) and set it so that it breaks on entry, exit or both

您能够做您想做的事情的唯一方法是在每个有问题的类的方法上设置方法断点。您需要单击方法旁边的左侧装订线 - 将出现一个带有 4 个点的红色小圆圈,您可能会收到一条警告,指出方法级别的断点会影响性能。然后,您可以进一步配置断点(通过右键单击它,或选择 shift+F8)并将其设置为在进入、退出或两者时中断

I'm afraid theres no way to do this in a single step/setting.

恐怕没有办法在一个步骤/设置中做到这一点。