Skip to content

Recipe UseSystemLineSeparator fails in one case, and could be replaced by the new ChangeStaticFieldToMethod #54

@csemrau

Description

@csemrau

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).

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions