openrewrite / rewrite-kotlin

Work-in-progress implementation of Kotlin language support for OpenRewrite.
Apache License 2.0
38 stars 11 forks source link

Multiline comments have non-print-idempotent line endings on windows #520

Closed nmck257 closed 6 months ago

nmck257 commented 6 months ago

What version of OpenRewrite are you using?

I am using

What is the smallest, simplest way to reproduce the problem?

I couldn't reproduce this in a unit test case, but it consistently happens for a file like this via Maven plugin:

/**
 * Foo
 *
 * Bar
 */
class Foo

What did you expect to see?

Successful parse

What did you see instead?

This section went down the exception path: https://github.com/openrewrite/rewrite/blob/b19730693662b69321980e2559a7cab90ccd2512/rewrite-core/src/main/java/org/openrewrite/Parser.java#L44-L54

GitHub isn't letting me upload my screenshot of the IDEA debugger showing the input/output diff, so here it is manually: input.getSource(ctx).readFully = "/**\r\n * Foo\r\n *\r\n * Bar\r\n */\r\nclass Foo sourcefile.printall() = "/**\r\n * Foo\n *\n * Bar\r\n */\r\nclass Foo ^ Observe that the two "internal" line endings in the multiline comment have lost their \r characters.

Are you interested in contributing a fix to OpenRewrite?

Y'all would probably fix this much more easily than me :)

traceyyoshima commented 6 months ago

@kunli2 is the most familiar with whitespace parsing in the Kotlin parser visitor.

This is a slight revision to the windowsJavadoc with the minimum text to reproduce the issue:

    @Test
    void crlfInKdoc() {
        String windowsJavadoc =
          "/**\r\n" +
          " *\r\n" +
          " * Foo\r\n" +
          " */\r\n" +
          "class Test {\r\n" +
          "}";

        rewriteRun(
          kotlin(
            windowsJavadoc
          )
        );
    }