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 258098 - Special if else treatment - different handling 8.0.x vs 8.1
Summary: Special if else treatment - different handling 8.0.x vs 8.1
Status: RESOLVED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 8.1
Hardware: PC Windows 7
: P2 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-22 15:12 UTC by dboldureanu
Modified: 2016-05-25 01:50 UTC (History)
1 user (show)

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 dboldureanu 2016-02-22 15:12:23 UTC
Netbeans 8.0.2 and earlier do not remove the {} in case they already exist, while Netbeans 8.1 does this.

So this code, in Netbeans 8.0.1, 8.0.2 with Special "else if" Treatment enabled will keep the code like this.

    if (true) {
      System.out.println("1");
    }
    else {
      if (true) {
        System.out.println("2");
      }
    }

In Netbeans 8.1, for the same configuration, the code will be formatted into:

    if (true)
    {
      System.out.println("1");
    }
    else if (true)
    {
      System.out.println("2");
    }
Comment 1 puce 2016-05-22 11:40:49 UTC
This is very annoying!

Please note that when you disable this special treatment, NetBeans reformats all else if statements to } else { if statements!
Comment 2 puce 2016-05-22 21:23:38 UTC
Please provide a hotfix for this. This is driving me crazy!

Format on save just messes up everything.
Sometimes after manual changes it keeps the formatting sometimes it reformats the code with the above mentioned issue.

Format Alt+Shift+F behaves different again (always with the issue mentioned above).
Comment 3 Dusan Balek 2016-05-23 10:58:11 UTC
This is as expected behaviour. Special "else if" Treatment means: if there is a top-level if-statement with an else-block containing the single nested if-statement, remove the unnecessary block and put the nested statement directly as the else-part of the top-level statement.
Comment 4 puce 2016-05-23 21:08:28 UTC
That might be as you say, but if you disable this feature }else if(){ will be reformatted to } else { if(){

But as a developer I want to be in control when to use the former and when the latter.

This used to work in previous NetBeans versions, so this is a regression.

Also note that sometimes the format on save feature plays havoc with the brace alignments.
Comment 5 Dusan Balek 2016-05-24 12:06:00 UTC
Agree. Fixed in jet-main.

http://hg.netbeans.org/jet-main/rev/f8edddb8edf1
Comment 6 Quality Engineering 2016-05-25 01:50:51 UTC
Integrated into 'main-silver', will be available in build *201605250002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/f8edddb8edf1
User: Dusan Balek <dbalek@netbeans.org>
Log: Issue #258098 - Special if else treatment - different handling 8.0.x vs 8.1 - fixed.