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:
System.out.println("true"); // TODO code application logic here
IDE adds opening bracket but closing bracket is missing
Should be already fixed as part of issues #258227, #260880, see http://hg.netbeans.org/jet-main/rev/88e5205dddf7
oops, sorry. Commented on incorrect issue.
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.
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.
Created attachment 164906 [details]
Just < to <= change.
oops ;) disregard the last message. Wrongly tested, I'll give it yet another try -- if I fail, I'll reassign.
Created attachment 164908 [details]
"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.
Fixed in jet-main. Thanks for the patch.
Integrated into 'main-silver', will be available in build *201709030001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
User: Dusan Balek <firstname.lastname@example.org>
Log: Issue #270934 - formatting if clause with single code line and commentary breaks code - fixed.