Skip to content

Commit f73e157

Browse files
committed
Modified recipe to be extension agnostic, support different file types
1 parent 6c91647 commit f73e157

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

rewrite-java/src/main/java/org/openrewrite/java/ChangeType.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,11 @@ public J visit(@Nullable Tree tree, ExecutionContext ctx) {
649649
String oldPath = cu.getSourcePath().toString().replace('\\', '/');
650650
String oldFqn = fqnToPath(originalType.getFullyQualifiedName());
651651
String newFqn = fqnToPath(targetType.getFullyQualifiedName());
652-
653-
// Only update the path when it ends with oldFqn + ".java" (this file is the old type's source).
652+
int lastDot = oldPath.lastIndexOf('.');
653+
String extension = lastDot >= 0 ? oldPath.substring(lastDot) : "";
654654
String newPathStr = oldPath;
655-
if (oldPath.endsWith(oldFqn + ".java")) {
656-
newPathStr = oldPath.substring(0, oldPath.length() - (oldFqn + ".java").length()) + newFqn + ".java";
655+
if (!extension.isEmpty() && oldPath.endsWith(oldFqn + extension)) {
656+
newPathStr = oldPath.substring(0, oldPath.length() - (oldFqn + extension).length()) + newFqn + extension;
657657
}
658658
Path newPath = Paths.get(newPathStr);
659659
if (updatePath(cu, oldPath, newPath.toString())) {

0 commit comments

Comments
 (0)