Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
package org.openrewrite.java.migrate.lang;

import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.ExpectedToFail;
import org.openrewrite.DocumentExample;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.java.ChangeType;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

Expand Down Expand Up @@ -327,4 +329,70 @@ int count(List<String> items) {
)
);
}

@ExpectedToFail("References to the renamed class in other source files keep the old `_` spelling")
@Test
void classReferencesInAnotherSourceFileFollowTheRename() {
rewriteRun(
spec -> spec.recipes(new ChangeType("UNDERSCORE", "_", false), new RenameUnderscoreIdentifier())
.allSources(s -> s.markers(javaVersion(8))),
//language=java
java(
"""
class UNDERSCORE {
}
""",
"""
class __ {
}
""",
spec -> spec.path("_.java")
),
//language=java
java(
"""
class User {
UNDERSCORE field = new UNDERSCORE();
}
""",
"""
class User {
__ field = new __();
}
"""
)
);
}

@ExpectedToFail("The chosen name duplicates a package private class declared in a differently named file")
@Test
void classRenameAvoidsASecondaryClassDeclaredInAnotherSourceFile() {
rewriteRun(
spec -> spec.recipes(new ChangeType("UNDERSCORE", "_", false), new RenameUnderscoreIdentifier())
.allSources(s -> s.markers(javaVersion(8))),
//language=java
java(
"""
class UNDERSCORE {
}
""",
"""
class _ {
}
""",
spec -> spec.path("_.java")
),
//language=java
java(
"""
class Other {
}

class __ {
}
""",
spec -> spec.path("Other.java")
)
);
}
}