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 270934 - formatting if clause with single code line and commentary breaks code
Summary: formatting if clause with single code line and commentary breaks code
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: Dev
Hardware: PC Other
: P2 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-22 20:21 UTC by Maksim Khramov
Modified: 2017-09-03 02:50 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Proposed change (1.38 KB, patch)
2017-08-07 06:17 UTC, Svata Dedic
Details | Diff
Proposed changes (9.81 KB, patch)
2017-08-07 13:31 UTC, Svata Dedic
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Maksim Khramov 2017-06-22 20:21:11 UTC
Product Version: NetBeans IDE Dev (Build 201705310001)
Java: 1.8.0_131; Java HotSpot(TM) 64-Bit Server VM 25.131-b11

Steps to reproduce:
try to format next two code lines:

        if(true)
            System.out.println("true"); // TODO code application logic here

IDE adds opening bracket but closing bracket is missing
Comment 1 Svata Dedic 2017-08-04 14:36:13 UTC
Should be already fixed as part of issues #258227, #260880, see http://hg.netbeans.org/jet-main/rev/88e5205dddf7
Comment 2 Svata Dedic 2017-08-04 14:37:51 UTC
oops, sorry. Commented on incorrect issue.
Comment 3 Svata Dedic 2017-08-04 14:49:07 UTC
One must select the 2nd line up to the end, but NOT INCLUDING end of line (go to 1st line, then SHIFT-down, SHIFT-end) in order to produce the defect. If the 2nd line is selected including the (invisible) line terminator (2x SHIFT-down), the closing brace is inserted, although with bad indentation.
Comment 4 Svata Dedic 2017-08-07 06:16:14 UTC
In the reformatter, if formatting checks if the whole IfTree is enclosed in the formatted region. With the sample code, the if statement ends (end position is offset past last character of the statement) at the same offset as the selection (past the last character on the line).

Dusane, please review the diff.
Comment 5 Svata Dedic 2017-08-07 06:17:04 UTC
Created attachment 164906 [details]
Proposed change

Just < to <= change.
Comment 6 Svata Dedic 2017-08-07 10:09:33 UTC
oops ;) disregard the last message. Wrongly tested, I'll give it yet another try -- if I fail, I'll reassign.
Comment 7 Svata Dedic 2017-08-07 13:31:04 UTC
Created attachment 164908 [details]
Proposed changes

"end of node" is computed incl. possible trailing comments and whitespaces as the end of the last statement's line - because closing brace is added on a separate line. If the newline is not part of the formatting (selection till end of the line), the added closing brace (on the line following the selection) will be filtered out of the diff, and braces become unballanced.

the same issue is in do-while, while and for loops.
Comment 8 Dusan Balek 2017-09-01 11:50:11 UTC
Fixed in jet-main. Thanks for the patch.

http://hg.netbeans.org/jet-main/rev/8cf0f89a6094
Comment 9 Quality Engineering 2017-09-03 02:50:35 UTC
Integrated into 'main-silver', will be available in build *201709030001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/8cf0f89a6094
User: Dusan Balek <dbalek@netbeans.org>
Log: Issue #270934 - formatting if clause with single code line and commentary breaks code - fixed.