rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Improved handling of inner class named `$` in JavaTemplate

Open MBoegers opened this issue 2 years ago • 2 comments

What's changed?

  • TypeUtils handle $ better if determing the FQN
  • use TypeUtils in rewrite-java*

What's your motivation?

I want the fix the handling of $ as class name. And fixing

  • #3623

Have you considered any alternatives or workarounds?

Any additional context

If finished this should enable -https://github.com/openrewrite/rewrite-migrate-java/pull/285

Checklist

  • [ ] I've added unit tests to cover both positive and negative cases
  • [ ] I've read and applied the recipe conventions and best practices
  • [ ] I've used the IntelliJ IDEA auto-formatter on affected files

MBoegers avatar Jan 09 '24 22:01 MBoegers

Great to see, thanks @MBoegers ; saving others a click by copying the remaining failure here:

JavaTemplateSubstitutionsTest > anyForInnerClass() FAILED
    org.opentest4j.AssertionFailedError: [Unexpected result in "A.java":
diff --git a/A.java b/A.java
index df29fc4..f075a84 100644
--- a/A.java
+++ b/A.java
@@ -1,6 +1,6 @@ 
 class A {
     void foo() {
-        $ test = new $();
+        $ test = new A.$();
     }
     static class $ {
         static $ of() {
    ] 
    expected: 
      "class A {
          void foo() {
              $ test = new $();
          }
          static class $ {
              static $ of() {
                  return new $();
              }
          }
      }"
     but was: 
      "class A {
          void foo() {
              $ test = new A.$();
          }
          static class $ {
              static $ of() {
                  return new $();
              }
          }
      }"

timtebeek avatar Jan 10 '24 09:01 timtebeek