rewrite
rewrite copied to clipboard
Improved handling of inner class named `$` in JavaTemplate
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
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 $();
}
}
}"