Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong indentation of single statement ifs/etc #239

Closed
webczat opened this issue Dec 6, 2016 · 8 comments
Closed

wrong indentation of single statement ifs/etc #239

webczat opened this issue Dec 6, 2016 · 8 comments

Comments

@webczat
Copy link

webczat commented Dec 6, 2016

I have noticed that when you write a line such as:
if (a == 1)
and then press enter, the next statement does not get properly indented. When manually formatting the source using the format menu item, it is indented correctly.

@eric-milles
Copy link
Member

Just double-checking, do you have the option "Enter key adjusts the indentation on the new line" checked in Preferences > Java > Editor > Typing?

@eric-milles
Copy link
Member

eric-milles commented Dec 6, 2016

This test should confirm your issue

    void testIndentAfterIfStatement() {
        makeEditor("""\
            class Bagaga {
                def foo(def a, def b) {
                    if (a == b)${CARET}
                }
            }
            """.stripIndent())

        send('\n')

        assertEditorContents("""\
            class Bagaga {
                def foo(def a, def b) {
                    if (a == b)
                        ${CARET}
                }
            }
            """.stripIndent())
    }

It currently fails, just as you have noted.

@eric-milles
Copy link
Member

Looks like this guy does not find an imbalance in braces or parens and so returns the same indent level.

    private int simpleComputeNextLineIndentLevel(int indentLevel, List<Token> tokens) {
        int adjust = getOpenVersusCloseBalance(tokens);
        if (adjust > 0)
            indentLevel += getPrefs().getIndentationSize();
        else if (adjust < 0)
            indentLevel = indentLevel - getPrefs().getIndentationSize();
        return indentLevel;
    }

@eric-milles
Copy link
Member

Should be fixed.

@webczat
Copy link
Author

webczat commented Dec 6, 2016

I do not know what I have enabled, but I have definitely tested some nonsensical instructions like if (1==2)\nreturn and stuff in both java and groovy, and in java it indented, in groovy it didn't.
If you still need this test after this comment, do you need me to paste that in any source code or where?

@eric-milles
Copy link
Member

Sorry, I made a small error that failed the build. This should be available for test in a few minutes.

@webczat
Copy link
Author

webczat commented Dec 7, 2016

okay, I downloaded the latest update and tried to use it.
If I write something like (without indentation here):
if (1 == 2)
return
//whatever

then the if line is of course correctly indented, return is correctly indented (shifted right), but the next line has not been unindented properly.

@eric-milles
Copy link
Member

Was your original request satisfied? Can you close this issue and open a new one with current and expected code snippets? Use three backticks to start and end a multi-line code block.

@webczat webczat closed this as completed Dec 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants