Is it possible to collapse type definitions in source code in any Java IDE?

Recently, I often have to read Java code as follows:

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 definition, a simple algorithm becomes completely obscure. Therefore, I would like to remove or collapse type definitions using my IDE to see Java code without types such as:

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, display the type as a tooltip. Is there a Java IDE or plugin for the IDE that can do this?

+3
source share
1 answer

IntelliJ IDEA converts the types on the right side of the declaration to <~>. So that:

Map<Integer, String> m = new HashMap<Integer, String>();

Will appear folded as:

Map<Integer, String> m = new HashMap<~>();

Editor/Code Folding/Generic Constructor Method Parameters, IDE .

</" > Scala, :

val totals = new mutable.Map[String, Int]
for { 
    row <- table.getValue
    (colName, value) <- row.entrySet 
} totals += (colName -> (value + totals.get(colName) getOrElse 0)
+5

Source: https://habr.com/ru/post/1782914/


All Articles