INRIA / spoon

Spoon is a metaprogramming library to analyze and transform Java source code. :spoon: is made with :heart:, :beers: and :sparkles:. It parses source files to build a well-designed AST with powerful analysis and transformation API.
http://spoon.gforge.inria.fr/
Other
1.76k stars 352 forks source link

Unexpected indent printed out when printing Java multiline string. #5983

Open treenwang opened 1 month ago

treenwang commented 1 month ago

Describe the bug

Unexpected indent printed out when printing Java multiline string.

Source code you are trying to analyze/transform

No response

Source code for your Spoon processing

@Test
    void testMultilineString(){
        CtType<?> ctType = Launcher.parseClass("class A{ void a(){var s = \"\"\"\na\n\"\"\";} }");
        System.out.println(ctType.toStringWithImports());
        Assertions.assertEquals("class A {\n" +
            "    void a() {\n" +
            "        var s = \"\"\"\na\"\"\";\n" +
            "    }\n" +
            "}\n", ctType.toStringWithImports());
    }

Actual output

class A {
    void a() {
        var s = """
        a
        """;
    }
}

Expected output

class A {
    void a() {
        var s = """
a
""";
    }
}

Spoon Version

11.1.0

JVM Version

Java 17+

What operating system are you using?

MacOS