This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 262164 - Bad formatting of if-statement
Summary: Bad formatting of if-statement
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.1
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-20 12:25 UTC by Peter Nabbefeld
Modified: 2016-05-20 12:25 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Nabbefeld 2016-05-20 12:25:40 UTC
Formatting of an if-statement like this does not work correctly:

if (condition_1) {
    // Comment-1
    doSomething(1);
} else {
    // Comment-2
    if (condition_2) {
        doSomething(2);
    } else {
        doSomething(3);
    }
}

Is formatted as:

if (condition_1) {
    // Comment-1
    doSomething(1);
} else // Comment-2
if (condition_2) {
    doSomething(2);
} else {
    doSomething(3);
}

As "Comment-2" is behind the "else", it doesn't look like a comment for the following if-statement, but as a comment for the else-statement.

Instead, formatting should not change anything in this special case (the block following the else contains a comment in the very first line). However, I really like building a switch-like if-else structure, when there is no comment in the first line of the block following else, like this:

if (condition_1) {
    // Comment-1
    doSomething(1);
} else {
    if (condition_2) {
        doSomething(2);
    } else {
        doSomething(3);
    }
}

being formatted to:

if (condition_1) {
    // Comment-1
    doSomething(1);
} else if (condition_2) {
    doSomething(2);
} else {
    doSomething(3);
}

as this does not change source code semantics.