如何扩展 IntelliJ IDEA CE 代码评估功能?
我正在使用 IntelliJ IDEA Community Edition 10 开发 Java SE 项目。
我的应用程序需要很长时间才能启动,因此我调试代码的首选方式是 Launch ->在断点处停止->打开代码评估窗口->输入一些代码并查看它返回什么。
但是当我的代码返回一个大的对象数组/集合时,问题就出现了。我想要的是按字段值或其他一些条件过滤对象。
我可以使用 Apache Commons Collections 或 Google Guava 进行过滤,但 IntelliJ IDEA 的代码评估不允许动态创建匿名类,我需要定义谓词。
我也可以使用 lambdaJ,但是我的巨大集合中的对象类被声明为最终的(并且我无法更改这一点),因此 lambdaJ 无法扩展这些类的操作。
我还尝试使用 BeanShell,但它要求我将代码作为字符串传递,这会杀死 IDEA 的代码-完成。此外,bsh 无法在正在调试的进程内使用局部变量。最后,我每次都必须指定完整的类名。
任何人都可以帮助找到解决这个问题的方法吗?这可能是扩展 IntelliJ IDEA 的代码评估以支持匿名类的某种神奇方法,或者是在这种情况下适用的另一种过滤集合的方法。
I'm using IntelliJ IDEA Community Edition 10 to develop a Java SE project.
My app takes a long time to start, so my preferred way of debugging the code is Launch -> Stop at a breakpoint -> Open the code evaluation window -> type in some code and see what it returns.
But the problem arises when my code returns a large array/collection of objects. What I want is filter the objects by value of a field or some other criteria.
I could use Apache Commons Collections or Google Guava to do the filtering, but IntelliJ IDEA's code evaluation does not allow creation of anonymous classes on-the-fly, which I need to define Predicates.
I could also use lambdaJ, but the classes of objects in my huge collections are declared final (and I can't change that), so lambdaJ cannot extend these classes for its operation.
I also tried to use BeanShell, but it requires me to pass the code as a string, which kills IDEA's code-completion. Also bsh cannot make use of local variables inside the process being debugged. Lastly, I have to specify full class names every time.
Can anyone help to find a solution to this problem? It might be some magical way to extend the IntelliJ IDEA's code evaluation to support anonymous classes, or another way to filter collections which will work in this situation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您仍然可以通过使用自己的转换器、聚合器和匹配器扩展其功能来使用 lambdaj,如下所述:
http://code.google.com/p/lambdaj/wiki/LambdajExtensibility
You could still use lambdaj by extending its features with your own Converters, Aggregators and Matchers as described here:
http://code.google.com/p/lambdaj/wiki/LambdajExtensibility
您可以编写自己的方法来按照您想要的方式过滤结果。只要在开始调试之前编译它们,就可以在评估中使用它们。例如
You can write you own methods to filter the results how you want. As long as they are compiled before you start debugging, they can be used in the evaluation. e.g.