History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEA-15564
Type: Bug Bug
Status: Open Open
Assignee: Bas Leijdekkers
Reporter: AlexL
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
IDEA: Feedback

Control flow statement wtihout braces - Quickfix doesn't respect code format settings

Created: 09 Oct 07 07:13   Updated: 09 Oct 07 12:42
Component/s: Code Analysis. Inspection

File Attachments: None
Image Attachments:

1. 7330_code_style_settings.png
(17 kb)
Environment: Windows XP SP2

Build: 7,330
Severity: Medium


 Description  « Hide
Given the following code:
TestWrapBraces.java
package org.intellij;

/**
 * User: Alex
 */
public class TestWrapBraces
{
    public boolean foo(int i) {
        if (i > 0)
            return true;
        else
            return false;
    }
}

If I have "Control flow statement without braces" inspection turned on, I will see warnings
on the if and else blocks:
'if' without braces
'elsel without braces

I can use ALT+ENTER on both if and else to add braces or I can hit ALT+ENTER once on
one of them and then RIGHT_ARROW and ENTER on 'Fix all 'Control flow statement without braces' problems.
Either way I end up with:

TestWrapBraces.java - After Fix
package org.intellij;

/**
 * User: Alex
 */
public class TestWrapBraces
{
    public boolean foo(int i) {
        if (i > 0) {
            return true;
        }
        else {
            return false;
        }
    }
}

The problem is that IDEA is not using the settings for 'Place on New Line'. (See screenshot).
I have "else" on new line disabled, so I would expected the Quickfix to put the else after the closing
brace.

Here is what I get if I reformat the code either before or after I made the quickfixes. (Reformat also
inserts braces automatically.)

TestWrapBraces.java – After Reformat
package org.intellij;

/**
 * User: Alex
 */
public class TestWrapBraces
{

    public boolean foo(int i) {
        if (i > 0) {
            return true;
        } else {
            return false;
        }
    }
}

The reason it is important to fix this QuickFix is that in a team environment, we try not to Reformat the entire file. So, that
isn't a good workaround. It would be much better if the quickfix could produce could which matches what the reformat
would have done.



 All   Comments   Work Log   Change History      Sort Order:
There are no comments yet on this issue.