Improving readability of code

Hi, I was wondering if it was possible to do the following in IntelliJ:

I'm currently writing up a bunch of code, but my code is pretty difficult to read. An excerpt of a piece of a method that I have is as follows:

ArrayList<EnumMap<ComponentType,Component>> getComponentsFromKey(long key){
        Set<Map.Entry<Thing,EnumMap<ComponentType,Component>>> entries = components.entrySet();
        ArrayList<EnumMap<ComponentType,Component>> components = new ArrayList<EnumMap<ComponentType, Component>>();
        ...
        int heuristic = ((a+b/c)*2;
        ...
}



While everything seems to work as it should, the nested expressions make the code difficult to read at a glance, at least to me. Is it possible to format a block of code to insert spaces and/or line breaks in order to make long stretches of code more easier to read? Ie. something like the following:

ArrayList< EnumMap< ComponentType, Component> > getComponentsFromKey( long key ){
        Set<
               Map.Entry<Thing, EnumMap<ComponentType, Component> > > entries = components.entrySet();
        ArrayList< EnumMap<ComponentType, Component> > components = new ArrayList< EnumMap<ComponentType, Component> >();
        ...
        int heuristic = ((a + b) / c) * 2;

        ...

}



(maybe not exactly like this; there could be better ways to insert spaces/line breaks that make the code even more readable, but hopefully the idea comes through)

Naturally, I could insert the spaces/breaks myself if necessary. But I was wondering if IntelliJ had this feature to save time.on my part.
3 comments
Comment actions Permalink

Hi Gar,

Yes, you can configure your code style settings accordingly (e.g. set 'project settings | code style | java | wrapping and braces | assignment statement' to 'wrap if long'), select target text at the editor and call 'Reformat' action.

Denis

0
Comment actions Permalink

This is exactly what I'm looking for. Thanks!

0
Comment actions Permalink

You are welcome

Denis

0

Please sign in to leave a comment.