From 0b8a50220b6e70268e3d8fbed297bb1d2e02e06b Mon Sep 17 00:00:00 2001 From: Patrick Date: Tue, 7 Jun 2022 13:12:23 -0700 Subject: [PATCH] Add package-info.java and polish RemoveConstructorBindingAnnotation fqn check --- .../RemoveConstructorBindingAnnotation.java | 10 +--------- .../java/spring/boot3/package-info.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/openrewrite/java/spring/boot3/package-info.java diff --git a/src/main/java/org/openrewrite/java/spring/boot3/RemoveConstructorBindingAnnotation.java b/src/main/java/org/openrewrite/java/spring/boot3/RemoveConstructorBindingAnnotation.java index c70e04c39..d0b02f21b 100644 --- a/src/main/java/org/openrewrite/java/spring/boot3/RemoveConstructorBindingAnnotation.java +++ b/src/main/java/org/openrewrite/java/spring/boot3/RemoveConstructorBindingAnnotation.java @@ -20,7 +20,6 @@ import org.openrewrite.internal.ListUtils; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.tree.J; -import org.openrewrite.java.tree.JavaType; import org.openrewrite.java.tree.TypeUtils; /** @@ -46,15 +45,8 @@ public JavaIsoVisitor getVisitor() { return new JavaIsoVisitor() { @Override public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext context) { - boolean isConfigPropsAnnotationPresent = classDecl.getLeadingAnnotations().stream().filter(a -> { - JavaType.FullyQualified fqType = TypeUtils.asFullyQualified(a.getType()); - if (fqType != null && ANNOTATION_CONFIG_PROPERTIES.equals(fqType.getFullyQualifiedName())) { - return true; - } - return false; - }).findFirst().isPresent(); J.ClassDeclaration c = super.visitClassDeclaration(classDecl, context); - if (isConfigPropsAnnotationPresent) { + if (classDecl.getLeadingAnnotations().stream().anyMatch(a -> TypeUtils.isOfClassType(a.getType(), ANNOTATION_CONFIG_PROPERTIES))) { c = c.withLeadingAnnotations(ListUtils.map(c.getLeadingAnnotations(), anno -> { if (TypeUtils.isOfClassType(anno.getType(), ANNOTATION_CONSTRUCTOR_BINDING)) { maybeRemoveImport(ANNOTATION_CONSTRUCTOR_BINDING); diff --git a/src/main/java/org/openrewrite/java/spring/boot3/package-info.java b/src/main/java/org/openrewrite/java/spring/boot3/package-info.java new file mode 100644 index 000000000..c9d12d20b --- /dev/null +++ b/src/main/java/org/openrewrite/java/spring/boot3/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2021 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@NonNullApi @NonNullFields +package org.openrewrite.java.spring.boot3; + +import org.openrewrite.internal.lang.NonNullApi; +import org.openrewrite.internal.lang.NonNullFields;