catch32
catch32

Reputation: 18572

how to configure code formatter on intellij

I have to write code in another style. Am I wondering how to configure IntelliJ for this purpose?

It is before code looking:

@Override
public void generateTestObjectsInDb(Object... objects) {
    try {
        for (Object obj : objects) {
            DataBaseObjectService.createObjectInDB(obj);
        }
    } catch (Exception e) {
        Logger.fatal("Error occured while generating data in product Database.", e);
    }
}

And here is how it should look:

@Override
public void generateTestObjectsInDb(Object... objects)
{
    try
    {
        for (Object obj : objects)
        {
            DataBaseObjectService.createObjectInDB(obj);
        }
    }
    catch (Exception e)
    {
        Logger.fatal("Error occured while generating data in product Database.", e);
    }
}

How to achive this new code looking after using statndard key bindings Ctrl + Alt + L?

Upvotes: 2

Views: 4291

Answers (2)

ROMANIA_engineer
ROMANIA_engineer

Reputation: 56636

IntelliJ IDEA 15

Code Style is under Editor.

File > Settings... > Editor > Code Style > Java > Wrapping and Braces > Braces Placement > change "End of line" to "Next line" for "In class declaration", "In method declaration" and "Other" > OK

Braces placement

On the right side, you will see a live preview.

Apply the new formatting

  • For the current file:
    • click on the editor area > press Ctrl + Alt + L
  • For the whole project / a folder
    • click on a folder from the project structure (E.g.: on src) > press Ctrl + Alt + L

Upvotes: 0

Pavel
Pavel

Reputation: 140

You can change this in settings

File => Settings => Code Style => Java => Wrapping and Braces => Braces Placement.

Upvotes: 5

Related Questions