groovy-eclipse icon indicating copy to clipboard operation
groovy-eclipse copied to clipboard

Poor indenting of nested expressions

Open cal101 opened this issue 7 years ago • 1 comments

When formatting

class Formatting {
    StringBuilder m1() {
        return new StringBuilder();
    }
    StringBuilder m2(String p1, StringBuilder p2) {
        return new StringBuilder();
    }
 
    def main(args) {
        println(m1().
                append("a").
                append("b").
                append("c").
                append(m2(
                "x",
                m1().
                append("aa").
                append("ab"))))
    }
}

I expected something at least as what IDEA produces:

class Formatting {
    StringBuilder m1() {
        return new StringBuilder();
    }

    StringBuilder m2(String p1, StringBuilder p2) {
        return new StringBuilder();
    }

    def main(args) {
        println(m1().
                append("a").
                append("b").
                append("c").
                append(m2(
                        "x",
                        m1().
                                append("aa").
                                append("ab"))))
    }
}

so the nesting of the expressions gets respected. I develop a groovy DSL and proper indentation of the expressions is a must to avoid nesting errors.

If you provide a hint to the relevant code I may actually be able to help.

cal101 avatar May 28 '18 19:05 cal101

Formatter is at https://github.com/groovy/groovy-eclipse/blob/master/ide/org.codehaus.groovy.eclipse.refactoring/src/org/codehaus/groovy/eclipse/refactoring/formatter/DefaultGroovyFormatter.java and tests at https://github.com/groovy/groovy-eclipse/blob/master/ide-test/org.codehaus.groovy.eclipse.refactoring.test/src/org/codehaus/groovy/eclipse/refactoring/test/formatter/GroovyFormatterTests.groovy

eric-milles avatar May 29 '18 04:05 eric-milles