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 shebang in source file #569

Closed traceyyoshima closed 5 months ago

traceyyoshima commented 6 months ago
#!/usr/bin/env who
class Foo
traceyyoshima commented 6 months ago

The shebang exists as the first child of a file if it is present. On G.CompilationUnit, it is represented as a nullable String, which seems correct since it is not a comment and MUST be declared at the top of the file.

Unfortunately, whitespace is overly complex and would take time to fix and/or understand. I'm assigning this to @kunli2 since he has context to all the whitespace methods. Adding the shebang to the K.CU is simple, but it causes a idempotent print issue since the new line after the shebang is not preserved in the prefix of the class declaration.