Closed Laurens-W closed 6 months ago
Thanks for logging this as an issue! Indeed it seems our TypeAnnotationParameter recipe right now converts this to something that does not compile. We can either add handling in that existing recipe, or write a new recipe that executes first to do this particular replacement. Here's a test to get that started.
@Test
void booleanParameter() {
rewriteRun(
//language=java
java(
"""
import org.hibernate.annotations.Type;
public class TestApplication {
@Type(type = "boolean")
Object a;
}
""",
"""
import org.hibernate.annotations.Converter;
import org.hibernate.annotations.Type;
public class TestApplication {
@Convert(converter = org.hibernate.type.NumericBooleanConverter.class)
Object a;
}
"""
)
);
}
I opened #20 for a similar issue - the recipe could easily be extended to fix this (if it is accepted)
I extended #20 so the "boolean" mapping is migrated as well now. We have to somehow ensure that recipe runs before TypeAnnotationParameter, or TypeAnnotationParameter does nothing for type = "boolean
and type = "true_false
. Maybe it could check if the type-parameter is a valid FQN?
Added MigrateBooleanMappings to the recipe list, ahead of TypeAnnotationParameter. See #20
Unfortunately I found out that the "boolean"
type uses a dialect-specific mapping, so replacing it with the NumericBooleanConverter
might not always be the right thing to do.
What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a single module project.
What is the smallest, simplest way to reproduce the problem?
What did you expect to see?
What did you see instead?
What is the full stack trace of any errors you encountered?
It's not necessarily an issue with openrewrite, more that the code left after the recipe ran is non compiling. I think the NumericConverter matches previous behaviour.
Are you interested in contributing a fix to OpenRewrite?