简体   繁体   中英

Formatter intellij

I'm using IntelliJ 2017.1 I'm attempting configure the formatter, I have the following code:

if (Integer.parseInt(oneProcess[1]) == 1 || Integer.parseInt(oneProcess[1]) == 2 || Integer.parseInt(oneProcess[1]) == 3) {
    processArray[i] = new Process(initialTime, endTime);
}

When I press Option + Command + L , IntelliJ formats the code as follows:

if (Integer.parseInt(oneProcess[1]) == 1 || Integer.parseInt(oneProcess[1]) == 2 || Integer.parseInt(
        oneProcess[1]) == 3) {
    processArray[i] = new Process(burstTime, arrivalTime);
}

I want to configure the formatter as follows:

if (Integer.parseInt(oneProcess[1]) == 1 || Integer.parseInt(oneProcess[1]) == 2 || 
    Integer.parseInt(oneProcess[1]) == 3) {
    processArray[i] = new Process(burstTime, arrivalTime);
}

This means that IntelliJ must do line jump when it exceeds the right margin and align with the previous condition.

I found Preferences > Editor > Code Style > Java > Wrapping and Braces but I can't configure as I explained before.

How can I configure the formatter?

I think that for easy to view, you should format like the formatter does. Because if the broke line are indented in the same space with the previous line then it lead to confused. Example:

if (Integer.parseInt(oneProcess[1]) == 1 || Integer.parseInt(oneProcess[1]) == 2 || 
    Integer.parseInt(oneProcess[1]) == 3) {
    processArray[i] = new Process(burstTime, arrivalTime);
}

This indent make others thought Integer.parseInt(oneProcess[1]) == 3) is the new line of code in the body. (My opinion)

If you have a line:

String x = x + "dslkfajds" + "d;asfkdsa;" + "dslkfajds" + "d;asfkdsa;" + "dslkfajds" + "d;asfkdsa;" + "dslkfajds" + "d;asfkdsa;"+ "d;asfkdsa;" + "dslkfajds" + "d;asfkdsa;";

Then you should indent like this:

    String x = x + "dslkfajds" + "d;asfkdsa;" + "dslkfajds" 
         + "d;asfkdsa;" + "dslkfajds" + "d;asfkdsa;" + "dslkfajds" + "d;asfkdsa;"
         + "d;asfkdsa;" + "dslkfajds" + "d;asfkdsa;";

Instead of this:

String x = x + "dslkfajds" + "d;asfkdsa;" + "dslkfajds" 
+ "d;asfkdsa;" + "dslkfajds" + "d;asfkdsa;" + "dslkfajds" + "d;asfkdsa;"
+ "d;asfkdsa;" + "dslkfajds" + "d;asfkdsa;";

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