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.
Summary: | formatting if clause with single code line and commentary breaks code | ||
---|---|---|---|
Product: | java | Reporter: | Maksim Khramov <mkhramov> |
Component: | Refactoring | Assignee: | Dusan Balek <dbalek> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | dbalek, sdedic |
Priority: | P2 | ||
Version: | Dev | ||
Hardware: | PC | ||
OS: | Other | ||
Issue Type: | DEFECT | Exception Reporter: | |
Attachments: |
Proposed change
Proposed changes |
Description
Maksim Khramov
2017-06-22 20:21:11 UTC
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]
Proposed change
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]
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.
Fixed in jet-main. Thanks for the patch. http://hg.netbeans.org/jet-main/rev/8cf0f89a6094 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. |