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 246506 - Join consecutive ifs into if-else failes
Summary: Join consecutive ifs into if-else failes
Status: RESOLVED WORKSFORME
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0.1
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-17 17:41 UTC by MackSix
Modified: 2014-08-18 08:31 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Java source file (625 bytes, application/octet-stream)
2014-08-17 17:41 UTC, MackSix
Details
logfile (41.46 KB, text/plain)
2014-08-17 17:43 UTC, MackSix
Details

Note You need to log in before you can comment on or make changes to this bug.
Description MackSix 2014-08-17 17:41:08 UTC
Created attachment 148736 [details]
Java source file

1. Open attached source file.
2. Put cursor on keyword "else" on line 8.
3. Invoke the tool tip refactoring on line 8, "Join consecutive ifs into if-else"

Results:

----------

package suggestions;

public class JoinConsecutiveIfsIntoIfElse {

    public void method(boolean cond1, boolean cond2) {
        if(cond1) {
            
        } else //Hint: Join nested if into the enclosing if
            if(cond2) {
                System.out.println("ok");
            } else {
                System.out.println("ko");
            }
//            System.out.println("");

        if(cond1) {
            
        } else { //NoHint: Join nested if into the enclosing if
            if(cond2) {
                System.out.println("ok");
            }
            System.out.println("");
        }
    }
}

----------

Expected:

----------

package suggestions;

public class JoinConsecutiveIfsIntoIfElse {

    public void method(boolean cond1, boolean cond2) {
        if(cond1) {
            
        } else if(cond2) {
            System.out.println("ok");
        } else {
            System.out.println("ko");
        }
        if(cond1) {
            
        } else { //NoHint: Join nested if into the enclosing if
            if(cond2) {
                System.out.println("ok");
            }
            System.out.println("");
        }
    }
}

-----
Comment 1 MackSix 2014-08-17 17:43:09 UTC
Created attachment 148737 [details]
logfile
Comment 2 Jiri Prox 2014-08-18 08:31:16 UTC
The result is correct - the wrapping braces in else part are removed, the only changes to previous version is that the line comments are preserved, so the else if is not merged to one line.