rewrite: ChangePackage doesn't handle classes with GWT JNSI methods

What version of OpenRewrite are you using?

I am using OpenRewrite v8.44.2 with the ChangePackage recipe.

What is the smallest, simplest way to reproduce the problem?

type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.ChangePackageExample
displayName: Rename package name example
recipeList:
  - org.openrewrite.java.ChangePackage:
      oldPackageName: old_package_name
      newPackageName: new_package_name
package old_package_name;
class A {
  native void alert(String msg) /*-{ $wnd.alert(msg); }-*/;
}

What did you expect to see?

package new_package_name;
class A {
  native void alert(String msg) /*-{ $wnd.alert(msg); }-*/;
}

What did you see instead?

OpenRewrite didn’t touch the file. It seems like it ignores Java classes with native methods and/or trailing comment.

See reproducer

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

I am thinking something like this, but I haven’t tested it and I am unsure what the code I removed here was exactly supposed to do:

Index: rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java
--- a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java	(revision 03828cea1127bfb53f6db89cf7f1310735970479)
+++ b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java	(date 1739185371877)
@@ -1925,9 +1925,7 @@
             case METHOD:
                 JCMethodDecl m = (JCMethodDecl) t;
                 if (m.body == null || m.defaultValue != null) {
-                    String suffix = source.substring(cursor, positionOfNext(";", null));
-                    int idx = findFirstNonWhitespaceChar(suffix);
-                    return sourceBefore(idx >= 0 ? "" : ";");
+                    return sourceBefore(";");
                 } else {
                     return sourceBefore("");
                 }

No, i didn’t look into the parser side yet and i probably don’t have time until after the weekend.

Hmm… looks i’ve made some errror on my side, the reproducer isn’t correct.