diff --git a/src/main/java/org/openrewrite/hibernate/ReplaceLazyCollectionAnnotation.java b/src/main/java/org/openrewrite/hibernate/ReplaceLazyCollectionAnnotation.java index 35b160b..84e6398 100644 --- a/src/main/java/org/openrewrite/hibernate/ReplaceLazyCollectionAnnotation.java +++ b/src/main/java/org/openrewrite/hibernate/ReplaceLazyCollectionAnnotation.java @@ -26,11 +26,7 @@ import org.openrewrite.java.RemoveAnnotationVisitor; import org.openrewrite.java.search.FindAnnotations; import org.openrewrite.java.search.UsesType; -import org.openrewrite.java.tree.Expression; -import org.openrewrite.java.tree.J; -import org.openrewrite.java.tree.JavaType; -import org.openrewrite.java.tree.Space; -import org.openrewrite.java.tree.TypeUtils; +import org.openrewrite.java.tree.*; import java.util.List; import java.util.Optional; diff --git a/src/main/java/org/openrewrite/hibernate/TypeAnnotationParameter.java b/src/main/java/org/openrewrite/hibernate/TypeAnnotationParameter.java index 3fba472..8024770 100644 --- a/src/main/java/org/openrewrite/hibernate/TypeAnnotationParameter.java +++ b/src/main/java/org/openrewrite/hibernate/TypeAnnotationParameter.java @@ -90,8 +90,8 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct if (arg instanceof J.Assignment) { J.Assignment assignment = (J.Assignment) arg; if (assignment.getVariable() instanceof J.Identifier && - "type".equals(((J.Identifier) assignment.getVariable()).getSimpleName()) && - assignment.getAssignment() instanceof J.Literal) { + "type".equals(((J.Identifier) assignment.getVariable()).getSimpleName()) && + assignment.getAssignment() instanceof J.Literal) { String fqTypeName = (String) ((J.Literal) assignment.getAssignment()).getValue(); J.Identifier identifier = new J.Identifier( Tree.randomId(), diff --git a/src/test/java/org/openrewrite/hibernate/MigrateBooleanMappingsTest.java b/src/test/java/org/openrewrite/hibernate/MigrateBooleanMappingsTest.java index 08b3362..ee61796 100644 --- a/src/test/java/org/openrewrite/hibernate/MigrateBooleanMappingsTest.java +++ b/src/test/java/org/openrewrite/hibernate/MigrateBooleanMappingsTest.java @@ -32,7 +32,7 @@ class MigrateBooleanMappingsTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec.recipe(new MigrateBooleanMappings()) .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(),"hibernate-core", "jakarta.persistence-api") + .classpathFromResources(new InMemoryExecutionContext(), "hibernate-core", "jakarta.persistence-api") ); } diff --git a/src/test/java/org/openrewrite/hibernate/MigrateToHibernate61Test.java b/src/test/java/org/openrewrite/hibernate/MigrateToHibernate61Test.java index 5b4cb1a..3134d0b 100644 --- a/src/test/java/org/openrewrite/hibernate/MigrateToHibernate61Test.java +++ b/src/test/java/org/openrewrite/hibernate/MigrateToHibernate61Test.java @@ -134,19 +134,19 @@ void groupIdHypersistenceUtilsRenamedAndPackageUpdated() { - """.formatted(matcher.group(1)); + """.formatted(matcher.group(1)); }) ), //language=java srcMainJava( java(""" import com.vladmihalcea.hibernate.type.json.JsonBinaryType; - + public class TestApplication { } """, """ import io.hypersistence.utils.hibernate.type.json.JsonBinaryType; - + public class TestApplication { } """ diff --git a/src/test/java/org/openrewrite/hibernate/ReplaceLazyCollectionAnnotationTest.java b/src/test/java/org/openrewrite/hibernate/ReplaceLazyCollectionAnnotationTest.java index 7fa6c04..db77674 100644 --- a/src/test/java/org/openrewrite/hibernate/ReplaceLazyCollectionAnnotationTest.java +++ b/src/test/java/org/openrewrite/hibernate/ReplaceLazyCollectionAnnotationTest.java @@ -52,14 +52,14 @@ void methodAnnotation_shouldBeUpdated_whenFetchArgumentIsMissing( import org.hibernate.annotations.LazyCollection; import org.hibernate.annotations.LazyCollectionOption; import jakarta.persistence.%1$s; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + private Set items = new HashSet<>(); - + @LazyCollection(%2$s) @%1$s public Set getItems() { @@ -70,14 +70,14 @@ public Set getItems() { """ import jakarta.persistence.FetchType; import jakarta.persistence.%1$s; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + private Set items = new HashSet<>(); - + @%1$s(fetch = %2$s) public Set getItems() { return items; @@ -105,11 +105,11 @@ void fieldAnnotation_shouldBeUpdated_whenFetchArgumentIsMissing( import org.hibernate.annotations.LazyCollection; import org.hibernate.annotations.LazyCollectionOption; import jakarta.persistence.%1$s; - + import java.util.List; - + class SomeClass { - + @LazyCollection(%2$s) @%1$s private List items; @@ -118,11 +118,11 @@ class SomeClass { """ import jakarta.persistence.FetchType; import jakarta.persistence.%1$s; - + import java.util.List; - + class SomeClass { - + @%1$s(fetch = %2$s) private List items; } @@ -144,14 +144,14 @@ void methodAnnotation_shouldNotBeUpdated_whenFetchArgumentIsPresent() { import org.hibernate.annotations.LazyCollectionOption; import jakarta.persistence.FetchType; import jakarta.persistence.ManyToMany; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + private Set items = new HashSet<>(); - + @LazyCollection(LazyCollectionOption.FALSE) @ManyToMany(fetch = FetchType.LAZY) public Set getItems() { @@ -162,14 +162,14 @@ public Set getItems() { """ import jakarta.persistence.FetchType; import jakarta.persistence.ManyToMany; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + private Set items = new HashSet<>(); - + @ManyToMany(fetch = FetchType.LAZY) public Set getItems() { return items; @@ -193,12 +193,12 @@ void fieldAnnotation_shouldNotBeUpdated_whenFetchArgumentIsPresent() { import org.hibernate.annotations.LazyCollectionOption; import jakarta.persistence.ElementCollection; import jakarta.persistence.FetchType; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + @LazyCollection(LazyCollectionOption.FALSE) @ElementCollection(fetch = FetchType.LAZY) private Set items; @@ -207,12 +207,12 @@ class SomeClass { """ import jakarta.persistence.ElementCollection; import jakarta.persistence.FetchType; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + @ElementCollection(fetch = FetchType.LAZY) private Set items; } @@ -230,14 +230,14 @@ void methodAnnotation_shouldNotBeUpdated_whenLazyCollectionOptionIsExtra() { import org.hibernate.annotations.LazyCollection; import org.hibernate.annotations.LazyCollectionOption; import jakarta.persistence.ElementCollection; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + private Set items; - + @LazyCollection(LazyCollectionOption.EXTRA) @ElementCollection public Set getItems() { @@ -258,12 +258,12 @@ void fieldAnnotation_shouldNotBeUpdated_whenLazyCollectionOptionIsExtra() { import org.hibernate.annotations.LazyCollection; import org.hibernate.annotations.LazyCollectionOption; import jakarta.persistence.ElementCollection; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + @LazyCollection(LazyCollectionOption.EXTRA) @ElementCollection private Set items; @@ -284,14 +284,14 @@ void methodAnnotation_shouldKeepPreviousArguments_whenFetchTypeIsAdded() { import org.hibernate.annotations.LazyCollectionOption; import jakarta.persistence.CascadeType; import jakarta.persistence.OneToMany; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + private Set items = new HashSet<>(); - + @LazyCollection(LazyCollectionOption.FALSE) @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE }) public Set getItems() { @@ -303,14 +303,14 @@ public Set getItems() { import jakarta.persistence.CascadeType; import jakarta.persistence.FetchType; import jakarta.persistence.OneToMany; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + private Set items = new HashSet<>(); - + @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE }, fetch = FetchType.EAGER) public Set getItems() { return items; @@ -331,12 +331,12 @@ void fieldAnnotation_shouldKeepPreviousArguments_whenFetchTypeIsAdded() { import org.hibernate.annotations.LazyCollectionOption; import jakarta.persistence.CascadeType; import jakarta.persistence.OneToMany; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + @LazyCollection(LazyCollectionOption.FALSE) @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE }) private Set items = new HashSet<>(); @@ -346,12 +346,12 @@ class SomeClass { import jakarta.persistence.CascadeType; import jakarta.persistence.FetchType; import jakarta.persistence.OneToMany; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE }, fetch = FetchType.EAGER) private Set items = new HashSet<>(); } @@ -370,29 +370,29 @@ void allLazyCollectionAnnotationsInClass_ShouldBeProcessed() { import org.hibernate.annotations.LazyCollectionOption; import jakarta.persistence.ElementCollection; import jakarta.persistence.ManyToMany; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + private Set items1; private Set items2; - + @ElementCollection @LazyCollection(LazyCollectionOption.EXTRA) private Set items3; - + @LazyCollection @ElementCollection private Set items4; - + @ManyToMany @LazyCollection(LazyCollectionOption.TRUE) public Set getItems1() { return items1; } - + @LazyCollection(LazyCollectionOption.FALSE) @ManyToMany public Set getItems2() { @@ -406,27 +406,27 @@ public Set getItems2() { import jakarta.persistence.ElementCollection; import jakarta.persistence.FetchType; import jakarta.persistence.ManyToMany; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + private Set items1; private Set items2; - + @ElementCollection @LazyCollection(LazyCollectionOption.EXTRA) private Set items3; - + @ElementCollection(fetch = FetchType.LAZY) private Set items4; - + @ManyToMany(fetch = FetchType.LAZY) public Set getItems1() { return items1; } - + @ManyToMany(fetch = FetchType.EAGER) public Set getItems2() { return items2; @@ -450,14 +450,14 @@ void regression_indentationIsWrong_whenSeveralAnnotationsArePresent() { import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinTable; import jakarta.persistence.ManyToMany; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + private Set items = new HashSet<>(); - + @Cascade(CascadeType.MERGE) @LazyCollection(LazyCollectionOption.FALSE) @ManyToMany @@ -474,14 +474,14 @@ public Set getItems() { import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinTable; import jakarta.persistence.ManyToMany; - + import java.util.HashSet; import java.util.Set; - + class SomeClass { - + private Set items = new HashSet<>(); - + @Cascade(CascadeType.MERGE) @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "A_B", joinColumns = @JoinColumn(name = "A_ID"), inverseJoinColumns = @JoinColumn(name = "B_ID")) diff --git a/src/test/java/org/openrewrite/hibernate/TypeAnnotationParameterTest.java b/src/test/java/org/openrewrite/hibernate/TypeAnnotationParameterTest.java index 9e3c17a..65c8710 100644 --- a/src/test/java/org/openrewrite/hibernate/TypeAnnotationParameterTest.java +++ b/src/test/java/org/openrewrite/hibernate/TypeAnnotationParameterTest.java @@ -38,7 +38,7 @@ void onlyOneParameter() { java( """ import org.hibernate.annotations.Type; - + public class TestApplication { @Type(type = "java.util.concurrent.atomic.AtomicBoolean") Object a; @@ -46,9 +46,9 @@ public class TestApplication { """, """ import org.hibernate.annotations.Type; - + import java.util.concurrent.atomic.AtomicBoolean; - + public class TestApplication { @Type(AtomicBoolean.class) Object a; @@ -65,7 +65,7 @@ void multipleParameters() { java( """ import org.hibernate.annotations.Type; - + class TestApplication { @Type(type = "java.util.concurrent.atomic.AtomicBoolean", parameters = {}) Object a; @@ -73,9 +73,9 @@ class TestApplication { """, """ import org.hibernate.annotations.Type; - + import java.util.concurrent.atomic.AtomicBoolean; - + class TestApplication { @Type(value = AtomicBoolean.class, parameters = {}) Object a; @@ -92,7 +92,7 @@ void removedParameter() { java( """ import org.hibernate.annotations.Type; - + public class TestApplication { @Type(type = "org.hibernate.type.TextType") Object a;