The recipe UseSystemLineSeparator fails in this test case:
UseSystemLineSeparatorTest.kt
@Test
fun migratesFieldInitializer() = assertChanged(
before = """
import org.apache.commons.io.IOUtils;
class A {
private final String LINE_SEPARATOR_AND_INDENTATION = IOUtils.LINE_SEPARATOR + " ";
}
""",
after = """
class A {
private final String LINE_SEPARATOR_AND_INDENTATION = System.lineSeparator() + " ";
}
"""
)
This is the same issue as ChangeStaticFieldToMethod had in my original attempt (openrewrite/rewrite#1071). The issue was fixed for that class before it was merged.
Now that ChangeStaticFieldToMethod is available, the UseSystemLineSeparator recipe is merely a special case of it and could be replaced by a declarative recipe that amounts to using ChangeStaticFieldToMethod("org.apache.commons.io.IOUtils", "LINE_SEPARATOR", "java.lang.System", "lineSeparator") (as it would be written in the Kotlin test class).