-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved handling of inner class named $
in JavaTemplate
#3898
base: main
Are you sure you want to change the base?
Conversation
dbe5d96
to
c0d6c08
Compare
Great to see, thanks @MBoegers ; saving others a click by copying the remaining failure here:
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() {
|
rewrite-java-test/src/test/java/org/openrewrite/java/RemoveUnusedImportsTest.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/tree/TypeUtils.java
Outdated
Show resolved
Hide resolved
$
in JavaTemplate
rewrite-java/src/main/java/org/openrewrite/java/tree/TypeUtils.java
Outdated
Show resolved
Hide resolved
@@ -126,7 +126,7 @@ private String substituteTypedPattern(String key, int index, TemplateParameterPa | |||
if (arrayType.getElemType() instanceof JavaType.Primitive) { | |||
s += ((JavaType.Primitive) arrayType.getElemType()).getKeyword(); | |||
} else if (arrayType.getElemType() instanceof JavaType.FullyQualified) { | |||
s += ((JavaType.FullyQualified) arrayType.getElemType()).getFullyQualifiedName().replace("$", "."); | |||
s += TypeUtils.toFullyQualifiedName(((JavaType.FullyQualified) arrayType.getElemType()).getFullyQualifiedName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A JavaType.FullyQualified
instance currently typically uses the binary name, which in the compiler's AST is represented by Symbol#flatName()
.
I think that instead of changing and using TypeUtils.toFullyQualifiedName()
to get the fully qualified name of a instances implementing JavaType.FullyQualified
we would be better off either changing the internal representation or deriving the name from the current representation.
Changing the current internal representation is trickier (with regards to backward compatibility), but adding a utility that can return the "source name" for a JavaType.FullyQualified
instance should be possible by combining what is returned by getOwningClass()
and by getFullyQualifiedName()
.
I am saying this because a class could also be called Foo$Bar
if you wanted to and that is another $
we shouldn't be replacing.
What's changed?
What's your motivation?
I want the fix the handling of $ as class name.
And fixing
Have you considered any alternatives or workarounds?
Any additional context
If finished this should enable
-openrewrite/rewrite-migrate-java#285
Checklist