是否有可能在任何 Java IDE 中折叠源代码中的类型定义?
最近我经常不得不阅读这样的 Java 代码:
LinkedHashMap<String, Integer> totals = new LinkedHashMap<String, Integer>(listOfRows.get(0))
for (LinkedHashMap<String, Integer> row : (ArrayList<LinkedHashMap<String,Integer>>) table.getValue()) {
for(Entry<String, Integer> elem : row.entrySet()) {
String colName=elem.getKey();
int Value=elem.getValue();
int oldValue=totals.get(colName);
int sum = Value + oldValue;
totals.put(colName, sum);
}
}
由于长且嵌套的类型定义,简单的算法变得相当模糊。因此,我希望可以使用 IDE 删除或折叠类型定义,以查看没有类型的 Java 代码,例如:
totals = new (listOfRows.get(0))
for (row : table.getValue()) {
for(elem : row.entrySet()) {
colName=elem.getKey();
Value=elem.getValue();
oldValue=totals.get(colName);
sum = Value + oldValue;
totals.put(colName, sum);
}
}
最好的方法当然是折叠类型定义,但是当将鼠标移到变量上时,会将类型显示为工具提示。是否有 Java IDE 或 IDE 插件可以做到这一点?
Lately I often have to read Java code like this:
LinkedHashMap<String, Integer> totals = new LinkedHashMap<String, Integer>(listOfRows.get(0))
for (LinkedHashMap<String, Integer> row : (ArrayList<LinkedHashMap<String,Integer>>) table.getValue()) {
for(Entry<String, Integer> elem : row.entrySet()) {
String colName=elem.getKey();
int Value=elem.getValue();
int oldValue=totals.get(colName);
int sum = Value + oldValue;
totals.put(colName, sum);
}
}
Due to the long and nested type definitions the simple algorithm becomes quite obscured. So I wished I could remove or collapse the type definitions with my IDE to see the Java code without types like:
totals = new (listOfRows.get(0))
for (row : table.getValue()) {
for(elem : row.entrySet()) {
colName=elem.getKey();
Value=elem.getValue();
oldValue=totals.get(colName);
sum = Value + oldValue;
totals.put(colName, sum);
}
}
The best way of course would be to collapse the type definitions, but when moving the mouse over a variable show the type as a tooltip. Is there a Java IDE or a plugin for an IDE that can do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IntelliJ IDEA 会将声明右侧的类型转换为
<~>
。这样:将显示折叠为:
这可以通过编辑器/代码折叠/通用构造函数和方法参数属性和IDE 的社区版 是免费的。
Or you could use Scala, which has type inference:
IntelliJ IDEA will convert the types on the right-hand side of a declaration to
<~>
. So that:Will appear folded as:
This is settable via the Editor / Code Folding / Generic Constructor and Method Parameters property and the community edition of the IDE is free.
Or you could use Scala, which has type inference: