openrewrite / rewrite-kotlin

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

Idempotent print issue: on imports with `$` characters in class name #559

Open traceyyoshima opened 6 months ago

traceyyoshima commented 6 months ago

Source: https://github.com/KengoTODA/flix-gradle-plugin/blob/main

import ca.uwaterloo.flix.tools.`Tester$`
kunli2 commented 5 months ago

This is a test to reproduce this issue, from the example source project, seems this is a way to import scala objests.

    @Test
    void scalaImport() {
        rewriteRun(
          kotlin(
            """
              import my.org.`x$`

              fun main() {

              }
              """
          )
        );
    }

It got a StringIndexOutOfBoundsException. the root cause is here, when building a typeTree, the delimiter includes $, but for this case, we don't want to delimiter it by $.

I found that $ delimiter is added by this commit, @knutwannheden maybe you know the background of this change. I have verified that if we change the delimiter back (without $), then this test will pass.