Eclipse调试器和集合 [英] Eclipse debugger and collections

查看:147
本文介绍了Eclipse调试器和集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些我想在Eclipse调试器中分析的集合。我对每个元素的特定属性感兴趣。



让我们举个例子,列出一个 Person s每个都有一个地址属性,后者又有一个 city 属性)。在调试器中,我可以查看每个元素,或者查看 list.get(i).address.city



<对于大型建筑物来说,这不是很有帮助。有可能应用一个函数到数据结构,类似于Perl中的 map 函数(在调试器中不在代码中)。



输入将是我的列表,我感兴趣的路径(Person.address.city),输出一个列表,只有选定的元素(与我的示例的城市列表)。 / p>

在Perl中:

  map {$ _-> {address }  - > {city}} @list 

修改



我可以使用详细格式化程序生成 String

  StringBuilder sb = new StringBuilder(); 
for(Person p:this){
sb.append(p.address.city());
sb.append(,);
}
return sb.toString();

这将格式化我的列表,只需要我感兴趣的元素(作为一个



尽管它走向正确的方向,但如果我可以返回一个新的列表,那将是很好的,我可以用调试器分析。

解决方案

我认为,Eclipse Debugger功能你感兴趣被称为逻辑结构。您可以在Eclipse首选项(Java / Debug / Logical结构)中定义一个逻辑结构,您可以在其中编写这样的表达式(希望),然后在变量视图上,您​​可以在弹出菜单中替换列表的显示。



看到这篇博客文章的基本想法: http://www.javalobby.org/forums/thread.jspa?threadID=16736&messageID=91823528


I have some collections that I would like to analyze in the Eclipse debugger. I am interested in a particular attribute of each element.

Let's take an example with a list of Persons (each one with an address attribute which in turn has a city attribute). In the debugger I can either look at each element or look at list.get(i).address.city.

Doing this for large structures is not really helpful. Is there the possibility to apply a function to a data structure, something similar to the map function in Perl (in the debugger not in the code).

The input would be my list with the path I am interested in (Person.address.city), the output a list with just the selected elements (a list of cities with my example).

In Perl:

map { $_->{address}->{city} } @list

Edit

I am able to generate a String with a Detail Formatter:

StringBuilder sb = new StringBuilder();
for (Person p : this) {
    sb.append(p.address.city());
    sb.append(", ");
}
return sb.toString();

This will format my list with just the elements I am interested in (as a String).

Although it goes in the right direction it would be nice if I could return a new List that I can analyze with the debugger.

解决方案

I think, the Eclipse Debugger feature you are interested is called logical structures. You could define a logical structure in Eclipse preferences (Java/Debug/Logical structures), where you could write such an expression (hopefully), and then on the variables view you could replace the display of the list in the pop-up menu.

See this blog post for basic ideas: http://www.javalobby.org/forums/thread.jspa?threadID=16736&messageID=91823528

这篇关于Eclipse调试器和集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆