Bug 567617 - [cleanup] "Raise embedded if into parent if" cleanup crashes with double lone ifs with ending comment
Summary: [cleanup] "Raise embedded if into parent if" cleanup crashes with double lone...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.17   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.18 M3   Edit
Assignee: Fabrice Tiercelin CLA
QA Contact: Carsten Hammer CLA
URL:
Whiteboard:
Keywords:
Depends on: 566870
Blocks:
  Show dependency tree
 
Reported: 2020-10-05 17:23 EDT by Fabrice Tiercelin CLA
Modified: 2020-11-21 03:39 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fabrice Tiercelin CLA 2020-10-05 17:23:51 EDT
We have a bug for double lone ifs:

Given:
if (isActive)
    if (isValid)
        int i = 0;

When:
Clean up the code enabling "Raise embeded if into parent if"

Expected:
if (isActive && isValid)
    int i = 0;

Actual:
org.eclipse.text.edits.MalformedTreeException: Range of child edit lies outside of parent edit
Comment 1 Fabrice Tiercelin CLA 2020-10-07 08:39:12 EDT
Actually, it is not due to the lone statement, it is due to an ending comment:

if (isActive)
    if (isValid)
        int i = 0; // foo
Comment 2 Fabrice Tiercelin CLA 2020-10-27 01:09:27 EDT
This can be fixed when cleanup will be multi-pass. This is planned: Bug 566870.

The idea is that when we encounter two embedded lone if statements, we only add bracket to the parent if. Doing this, the second pass will correctly cleanup the code (without bracket). So the code will be cleanup in two passes.
Comment 3 Eclipse Genie CLA 2020-11-01 07:48:36 EST
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/171577
Comment 5 Fabrice Tiercelin CLA 2020-11-21 03:39:55 EST
Verified for 4.18M3 using I20201116-1800 build