-
Notifications
You must be signed in to change notification settings - Fork 349
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
ChangeType
not working with types provided to the parser using dependsOn
.
#4030
Comments
That's a strange case indeed; thanks for the detailed runnable example. I wouldn't quite know why that's missed here. I'm guessing you ran into this when doing something similar in an actual recipe beyond this test case? Thanks for the offer to look into this as well! |
Findings:
There's a fix for this issue: #4040
|
Updated the last comment with the fixes for the first 2 findings. |
Thanks for the fixes so far! I've given the test that you provided above another go and I can replicate it using only a capital letter in the package name already 🤔 @Test
void renamePackageWithDependsOn() {
@Language("java") final String schemaClass1 = """
package foo.Capital;
public class MySchemaType {}
""";
@Language("java") final String schemaClass2 = """
package bar.Capital;
public class MySchemaType {}
""";
rewriteRun(
spec -> spec
.parser(JavaParser.fromJavaVersion().dependsOn(schemaClass1, schemaClass2))
.recipe(new ChangeType(
"foo.Capital.MySchemaType",
"bar.Capital.MySchemaType",
true
)),
//language=java
java(
"""
package my.example.app;
import foo.Capital.MySchemaType;
class MyApp {
void doWork(MySchemaType mySchema) {}
}
""",
"""
package my.example.app;
import bar.Capital.MySchemaType;
class MyApp {
void doWork(MySchemaType mySchema) {}
}
"""
)
);
} Which again fails with diff --git a/my/example/app/MyApp.java b/my/example/app/MyApp.java
index 7fe83d7..9ff90dd 100644
--- a/my/example/app/MyApp.java
+++ b/my/example/app/MyApp.java
@@ -1,7 +1,5 @@
package my.example.app;
-import bar.Capital.MySchemaType;
-
class MyApp {
void doWork(MySchemaType mySchema) {}
} |
Here's a simpler test: @Test
void changeTypeWithCapitalLettersInPackageName() {
@Language("java") final String schemaClass = """
package bar.Capital;
public class MySchemaType {}
""";
rewriteRun(
java(schemaClass, spec -> spec.afterRecipe(cu -> {
JavaType.FullyQualified typeFromParser = cu.getClasses().get(0).getType();
// Called on ChangeClassDefinition constructor
JavaType.ShallowClass shallowClass = JavaType.ShallowClass
.build(typeFromParser.getFullyQualifiedName());
assertThat(shallowClass)
.hasFieldOrPropertyWithValue("fullyQualifiedName", typeFromParser.getFullyQualifiedName())
.hasFieldOrPropertyWithValue("owningClass", typeFromParser.getOwningClass());
}
))
);
} And a variant for classes starting with lowercase letters, also failing: @Test
void changeTypeWithClassNamesStartingWithLowercaseLetters() {
@Language("java") final String schemaClass = """
package bar.capital;
public class mySchemaType {}
""";
rewriteRun(
java(schemaClass, spec -> spec.afterRecipe(cu -> {
JavaType.FullyQualified typeFromParser = cu.getClasses().get(0).getType();
// Called on ChangeClassDefinition constructor
JavaType.ShallowClass shallowClass = JavaType.ShallowClass
.build(typeFromParser.getFullyQualifiedName());
assertThat(shallowClass)
.hasFieldOrPropertyWithValue("fullyQualifiedName", typeFromParser.getFullyQualifiedName())
.hasFieldOrPropertyWithValue("owningClass", typeFromParser.getOwningClass());
}
))
);
} |
What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
I am using the following unit test:
What is the smallest, simplest way to reproduce the problem?
Using the provided test.
What did you expect to see?
What did you see instead?
What is the full stack trace of any errors you encountered?
Are you interested in contributing a fix to OpenRewrite?
Yes.
The text was updated successfully, but these errors were encountered: