简体   繁体   中英

how to configure code formatter on intellij

I have to write code at another style. I wondering to 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 looks:

@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 chive this new code looking after using statndard key bindings Ctrl + Alt + L ?

You can change this in settings

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

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

大括号放置

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 (Eg: on src ) > press Ctrl + Alt + L

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM