diff --git a/src/main/java/org/openrewrite/java/migrate/CastArraysAsListToList.java b/src/main/java/org/openrewrite/java/migrate/CastArraysAsListToList.java index e51fa47514..408d56357f 100644 --- a/src/main/java/org/openrewrite/java/migrate/CastArraysAsListToList.java +++ b/src/main/java/org/openrewrite/java/migrate/CastArraysAsListToList.java @@ -63,11 +63,11 @@ public J visitTypeCast(J.TypeCast typeCast, ExecutionContext ctx) { elementType = ((JavaType.Array) elementType).getElemType(); } - boolean matches = (elementType instanceof JavaType.Class || elementType instanceof JavaType.Parameterized) - && ((JavaType.FullyQualified) elementType).getOwningClass() == null // does not support inner class now - && LIST_TO_ARRAY.matches(typeCast.getExpression()) - && typeCast.getExpression() instanceof J.MethodInvocation - && ARRAYS_AS_LIST.matches(((J.MethodInvocation) typeCast.getExpression()).getSelect()); + boolean matches = (elementType instanceof JavaType.Class || elementType instanceof JavaType.Parameterized) && + ((JavaType.FullyQualified) elementType).getOwningClass() == null // does not support inner class now + && LIST_TO_ARRAY.matches(typeCast.getExpression()) && + typeCast.getExpression() instanceof J.MethodInvocation && + ARRAYS_AS_LIST.matches(((J.MethodInvocation) typeCast.getExpression()).getSelect()); if (!matches) { return typeCast; } diff --git a/src/main/java/org/openrewrite/java/migrate/JREThrowableFinalMethods.java b/src/main/java/org/openrewrite/java/migrate/JREThrowableFinalMethods.java index 4c1a413651..e88432234d 100644 --- a/src/main/java/org/openrewrite/java/migrate/JREThrowableFinalMethods.java +++ b/src/main/java/org/openrewrite/java/migrate/JREThrowableFinalMethods.java @@ -56,9 +56,9 @@ public String getDisplayName() { @Override public String getDescription() { - return "The recipe renames `getSuppressed()` and `addSuppressed(Throwable exception)` methods in classes " - + "that extend `java.lang.Throwable` to `myGetSuppressed` and `myAddSuppressed(Throwable)`." - + "These methods were added to Throwable in Java 7 and are marked final which cannot be overridden."; + return "The recipe renames `getSuppressed()` and `addSuppressed(Throwable exception)` methods in classes " + + "that extend `java.lang.Throwable` to `myGetSuppressed` and `myAddSuppressed(Throwable)`." + + "These methods were added to Throwable in Java 7 and are marked final which cannot be overridden."; } @Override diff --git a/src/main/java/org/openrewrite/java/migrate/MXBeanRule.java b/src/main/java/org/openrewrite/java/migrate/MXBeanRule.java index d394cdc00c..865573f640 100644 --- a/src/main/java/org/openrewrite/java/migrate/MXBeanRule.java +++ b/src/main/java/org/openrewrite/java/migrate/MXBeanRule.java @@ -108,9 +108,9 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDeclarat } List modifiers = new ArrayList<>(cd.getModifiers()); - modifiers.removeIf(modifier -> modifier.getType() == Modifier.Type.Private - || modifier.getType() == Modifier.Type.Protected - || modifier.getType() == Modifier.Type.Abstract); + modifiers.removeIf(modifier -> modifier.getType() == Modifier.Type.Private || + modifier.getType() == Modifier.Type.Protected || + modifier.getType() == Modifier.Type.Abstract); modifiers.add(new J.Modifier(randomId(), Space.EMPTY, Markers.EMPTY, Modifier.Type.Public, emptyList())); return maybeAutoFormat(cd, cd.withModifiers(sortModifiers(modifiers)), ctx); } diff --git a/src/main/java/org/openrewrite/java/migrate/ReferenceCloneMethod.java b/src/main/java/org/openrewrite/java/migrate/ReferenceCloneMethod.java index 5fa45dd207..9c19ecd782 100644 --- a/src/main/java/org/openrewrite/java/migrate/ReferenceCloneMethod.java +++ b/src/main/java/org/openrewrite/java/migrate/ReferenceCloneMethod.java @@ -57,8 +57,8 @@ public TreeVisitor getVisitor() { @Override public J visitTypeCast(J.TypeCast typeCast, ExecutionContext ctx) { J j = super.visitTypeCast(typeCast, ctx); - if (Boolean.TRUE.equals(getCursor().pollNearestMessage(REFERENCE_CLONE_REPLACED)) - && j instanceof J.TypeCast) { + if (Boolean.TRUE.equals(getCursor().pollNearestMessage(REFERENCE_CLONE_REPLACED)) && + j instanceof J.TypeCast) { J.TypeCast tc = (J.TypeCast) j; if (TypeUtils.isOfType(tc.getType(), tc.getExpression().getType())) { return tc.getExpression(); diff --git a/src/main/java/org/openrewrite/java/migrate/ReplaceComSunAWTUtilitiesMethods.java b/src/main/java/org/openrewrite/java/migrate/ReplaceComSunAWTUtilitiesMethods.java index f9b3f0508f..3158c6d775 100644 --- a/src/main/java/org/openrewrite/java/migrate/ReplaceComSunAWTUtilitiesMethods.java +++ b/src/main/java/org/openrewrite/java/migrate/ReplaceComSunAWTUtilitiesMethods.java @@ -119,8 +119,8 @@ public J visitMethodInvocation(J.MethodInvocation mi, ExecutionContext ctx) { maybeAddImport("java.awt.GraphicsEnvironment", false); maybeAddImport("java.awt.Window", false); maybeAddImport("java.awt.GraphicsDevice.WindowTranslucency", false); - String templateString = "GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().isWindowTranslucencySupported(WindowTranslucency." - + ((J.FieldAccess) mi.getArguments().get(0)).getSimpleName(); + String templateString = "GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().isWindowTranslucencySupported(WindowTranslucency." + + ((J.FieldAccess) mi.getArguments().get(0)).getSimpleName(); return JavaTemplate.builder(templateString). imports("java.awt.GraphicsDevice", "java.awt.GraphicsEnvironment", diff --git a/src/main/java/org/openrewrite/java/migrate/UseJavaUtilBase64.java b/src/main/java/org/openrewrite/java/migrate/UseJavaUtilBase64.java index 148822d97f..02dd81430e 100644 --- a/src/main/java/org/openrewrite/java/migrate/UseJavaUtilBase64.java +++ b/src/main/java/org/openrewrite/java/migrate/UseJavaUtilBase64.java @@ -127,9 +127,9 @@ public J visitNewClass(J.NewClass newClass, ExecutionContext ctx) { J.NewClass c = (J.NewClass) super.visitNewClass(newClass, ctx); if (newBase64Encoder.matches(c)) { // noinspection Convert2MethodRef - JavaTemplate.Builder encoderTemplate = useMimeCoder - ? Semantics.expression(this, "getMimeEncoder", () -> Base64.getMimeEncoder()) - : Semantics.expression(this, "getEncoder", () -> Base64.getEncoder()); + JavaTemplate.Builder encoderTemplate = useMimeCoder ? + Semantics.expression(this, "getMimeEncoder", () -> Base64.getMimeEncoder()) : + Semantics.expression(this, "getEncoder", () -> Base64.getEncoder()); return encoderTemplate .build() .apply(updateCursor(c), c.getCoordinates().replace()); diff --git a/src/main/java/org/openrewrite/java/migrate/guava/AbstractNoGuavaImmutableOf.java b/src/main/java/org/openrewrite/java/migrate/guava/AbstractNoGuavaImmutableOf.java index 373f492c23..7da4e70d26 100644 --- a/src/main/java/org/openrewrite/java/migrate/guava/AbstractNoGuavaImmutableOf.java +++ b/src/main/java/org/openrewrite/java/migrate/guava/AbstractNoGuavaImmutableOf.java @@ -170,8 +170,8 @@ private boolean isParentTypeDownCast(MethodCall immutableMethod) { private boolean isParentTypeMatched(@Nullable JavaType type) { JavaType.FullyQualified fq = TypeUtils.asFullyQualified(type); - return TypeUtils.isOfClassType(fq, javaType) - || TypeUtils.isOfClassType(fq, "java.lang.Object"); + return TypeUtils.isOfClassType(fq, javaType) || + TypeUtils.isOfClassType(fq, "java.lang.Object"); } }); } diff --git a/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaCreateTempDir.java b/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaCreateTempDir.java index c2ba679e27..cf1cb1605a 100644 --- a/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaCreateTempDir.java +++ b/src/main/java/org/openrewrite/java/migrate/guava/NoGuavaCreateTempDir.java @@ -86,8 +86,8 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu private boolean isIOExceptionOrException(JavaType.@Nullable FullyQualified fqCatch) { return fqCatch != null && - ("java.io.IOException".matches(fqCatch.getFullyQualifiedName()) - || "java.lang.Exception".matches(fqCatch.getFullyQualifiedName())); + ("java.io.IOException".matches(fqCatch.getFullyQualifiedName()) || + "java.lang.Exception".matches(fqCatch.getFullyQualifiedName())); } private J.MethodInvocation toFilesCreateTempDir(J.MethodInvocation methodInvocation) { diff --git a/src/main/java/org/openrewrite/java/migrate/io/ReplaceFileInOrOutputStreamFinalizeWithClose.java b/src/main/java/org/openrewrite/java/migrate/io/ReplaceFileInOrOutputStreamFinalizeWithClose.java index eeef01591d..92a921d99a 100644 --- a/src/main/java/org/openrewrite/java/migrate/io/ReplaceFileInOrOutputStreamFinalizeWithClose.java +++ b/src/main/java/org/openrewrite/java/migrate/io/ReplaceFileInOrOutputStreamFinalizeWithClose.java @@ -68,8 +68,8 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu if (METHOD_MATCHER.matches(mi)) { Expression select = mi.getSelect(); JavaType type = select != null ? select.getType() : getCursor().firstEnclosingOrThrow(J.ClassDeclaration.class).getType(); - if (TypeUtils.isAssignableTo(JAVA_IO_FILE_INPUT_STREAM, type) - || TypeUtils.isAssignableTo(JAVA_IO_FILE_OUTPUT_STREAM, type)) { + if (TypeUtils.isAssignableTo(JAVA_IO_FILE_INPUT_STREAM, type) || + TypeUtils.isAssignableTo(JAVA_IO_FILE_OUTPUT_STREAM, type)) { return mi.withName(mi.getName().withSimpleName("close")); } } diff --git a/src/main/java/org/openrewrite/java/migrate/javax/AddColumnAnnotation.java b/src/main/java/org/openrewrite/java/migrate/javax/AddColumnAnnotation.java index 4f6085a6fa..874a744068 100644 --- a/src/main/java/org/openrewrite/java/migrate/javax/AddColumnAnnotation.java +++ b/src/main/java/org/openrewrite/java/migrate/javax/AddColumnAnnotation.java @@ -73,8 +73,8 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex @Override public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations multiVariable, ExecutionContext ctx) { // Exit if var does not have @ElementCollection or has @Transient - if (FindAnnotations.find(multiVariable, "@javax.persistence.ElementCollection").isEmpty() - || !FindAnnotations.find(multiVariable, "@javax.persistence.Transient").isEmpty()) { + if (FindAnnotations.find(multiVariable, "@javax.persistence.ElementCollection").isEmpty() || + !FindAnnotations.find(multiVariable, "@javax.persistence.Transient").isEmpty()) { return multiVariable; } diff --git a/src/main/java/org/openrewrite/java/migrate/javax/AddDefaultConstructorToEntityClass.java b/src/main/java/org/openrewrite/java/migrate/javax/AddDefaultConstructorToEntityClass.java index 811953a3a7..577fc08a62 100644 --- a/src/main/java/org/openrewrite/java/migrate/javax/AddDefaultConstructorToEntityClass.java +++ b/src/main/java/org/openrewrite/java/migrate/javax/AddDefaultConstructorToEntityClass.java @@ -47,8 +47,8 @@ public TreeVisitor getVisitor() { @Override public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) { // Exit if class not annotated with either @Entity or @MappedSuperclass - if (FindAnnotations.find(classDecl, "javax.persistence.Entity").isEmpty() - && FindAnnotations.find(classDecl, "javax.persistence.MappedSuperclass").isEmpty()) { + if (FindAnnotations.find(classDecl, "javax.persistence.Entity").isEmpty() && + FindAnnotations.find(classDecl, "javax.persistence.MappedSuperclass").isEmpty()) { return classDecl; } diff --git a/src/main/java/org/openrewrite/java/migrate/javax/AddJaxbRuntime.java b/src/main/java/org/openrewrite/java/migrate/javax/AddJaxbRuntime.java index 02f51bed27..09fcb6556d 100644 --- a/src/main/java/org/openrewrite/java/migrate/javax/AddJaxbRuntime.java +++ b/src/main/java/org/openrewrite/java/migrate/javax/AddJaxbRuntime.java @@ -147,8 +147,8 @@ public G.CompilationUnit visitCompilationUnit(G.CompilationUnit cu, ExecutionCon GradleProject gp = maybeGp.get(); GradleDependencyConfiguration rc = gp.getConfiguration("runtimeClasspath"); - if (rc == null || rc.findResolvedDependency(JAKARTA_API_GROUP, JAKARTA_API_ARTIFACT) == null - || rc.findResolvedDependency(JACKSON_GROUP, JACKSON_JAXB_ARTIFACT) != null) { + if (rc == null || rc.findResolvedDependency(JAKARTA_API_GROUP, JAKARTA_API_ARTIFACT) == null || + rc.findResolvedDependency(JACKSON_GROUP, JACKSON_JAXB_ARTIFACT) != null) { return g; } @@ -189,8 +189,8 @@ private Xml.Document maybeAddRuntimeDependency(Xml.Document d, ExecutionContext return d; } MavenResolutionResult mavenModel = getResolutionResult(); - if (!mavenModel.findDependencies(JACKSON_GROUP, JACKSON_JAXB_ARTIFACT, Scope.Runtime).isEmpty() - || mavenModel.findDependencies(JAKARTA_API_GROUP, JAKARTA_API_ARTIFACT, Scope.Runtime).isEmpty()) { + if (!mavenModel.findDependencies(JACKSON_GROUP, JACKSON_JAXB_ARTIFACT, Scope.Runtime).isEmpty() || + mavenModel.findDependencies(JAKARTA_API_GROUP, JAKARTA_API_ARTIFACT, Scope.Runtime).isEmpty()) { return d; } diff --git a/src/main/java/org/openrewrite/java/migrate/javax/AddTransientAnnotationToPrivateAccessor.java b/src/main/java/org/openrewrite/java/migrate/javax/AddTransientAnnotationToPrivateAccessor.java index c413a053cb..c84c4610ae 100644 --- a/src/main/java/org/openrewrite/java/migrate/javax/AddTransientAnnotationToPrivateAccessor.java +++ b/src/main/java/org/openrewrite/java/migrate/javax/AddTransientAnnotationToPrivateAccessor.java @@ -87,11 +87,11 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration md, Execut } private boolean isPrivateAccessorMethodWithoutTransientAnnotation(J.MethodDeclaration method) { - return method.hasModifier(J.Modifier.Type.Private) - && method.getParameters().get(0) instanceof J.Empty - && method.getReturnTypeExpression().getType() != JavaType.Primitive.Void - && FindAnnotations.find(method, "javax.persistence.Transient").isEmpty() - && methodReturnsFieldFromClass(method); + return method.hasModifier(J.Modifier.Type.Private) && + method.getParameters().get(0) instanceof J.Empty && + method.getReturnTypeExpression().getType() != JavaType.Primitive.Void && + FindAnnotations.find(method, "javax.persistence.Transient").isEmpty() && + methodReturnsFieldFromClass(method); } /** diff --git a/src/main/java/org/openrewrite/java/migrate/javax/AnnotateTypesVisitor.java b/src/main/java/org/openrewrite/java/migrate/javax/AnnotateTypesVisitor.java index f5bd1ad9f1..78345b3b0c 100644 --- a/src/main/java/org/openrewrite/java/migrate/javax/AnnotateTypesVisitor.java +++ b/src/main/java/org/openrewrite/java/migrate/javax/AnnotateTypesVisitor.java @@ -46,8 +46,8 @@ public AnnotateTypesVisitor(String annotationToBeAdded) { @Override public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Set injectedTypes) { J.ClassDeclaration cd = super.visitClassDeclaration(classDecl, injectedTypes); - if (injectedTypes.contains(TypeUtils.asFullyQualified(cd.getType()).getFullyQualifiedName()) - && cd.getLeadingAnnotations().stream().noneMatch(annotationMatcher::matches)) { + if (injectedTypes.contains(TypeUtils.asFullyQualified(cd.getType()).getFullyQualifiedName()) && + cd.getLeadingAnnotations().stream().noneMatch(annotationMatcher::matches)) { maybeAddImport(annotationToBeAdded); return template.apply(getCursor(), cd.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName))); } diff --git a/src/main/java/org/openrewrite/java/migrate/javax/RemoveEmbeddableId.java b/src/main/java/org/openrewrite/java/migrate/javax/RemoveEmbeddableId.java index a1728ac612..cb021391de 100644 --- a/src/main/java/org/openrewrite/java/migrate/javax/RemoveEmbeddableId.java +++ b/src/main/java/org/openrewrite/java/migrate/javax/RemoveEmbeddableId.java @@ -116,8 +116,8 @@ public void addClass(JavaType type) { public boolean isEmbeddableClass(@Nullable JavaType type) { return definedEmbeddableClasses.stream() - .anyMatch(emb -> type.equals(emb) - || type.isAssignableFrom(Pattern.compile(((JavaType.Class) emb).getFullyQualifiedName()))); + .anyMatch(emb -> type.equals(emb) || + type.isAssignableFrom(Pattern.compile(((JavaType.Class) emb).getFullyQualifiedName()))); } } } diff --git a/src/main/java/org/openrewrite/java/migrate/javax/UseJoinColumnForMapping.java b/src/main/java/org/openrewrite/java/migrate/javax/UseJoinColumnForMapping.java index bb867eaa57..70cf54b7c9 100644 --- a/src/main/java/org/openrewrite/java/migrate/javax/UseJoinColumnForMapping.java +++ b/src/main/java/org/openrewrite/java/migrate/javax/UseJoinColumnForMapping.java @@ -60,9 +60,9 @@ public TreeVisitor getVisitor() { @Override public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations multiVariable, ExecutionContext ctx) { // Exit if not annotated with @Column and a relationship mapping annotation - if (FindAnnotations.find(multiVariable, COLUMN).isEmpty() - || (FindAnnotations.find(multiVariable, "javax.persistence.OneToOne").isEmpty() - && FindAnnotations.find(multiVariable, "javax.persistence.ManyToOne").isEmpty())) { + if (FindAnnotations.find(multiVariable, COLUMN).isEmpty() || + (FindAnnotations.find(multiVariable, "javax.persistence.OneToOne").isEmpty() && + FindAnnotations.find(multiVariable, "javax.persistence.ManyToOne").isEmpty())) { return multiVariable; } diff --git a/src/main/java/org/openrewrite/java/migrate/lang/MigrateClassNewInstanceToGetDeclaredConstructorNewInstance.java b/src/main/java/org/openrewrite/java/migrate/lang/MigrateClassNewInstanceToGetDeclaredConstructorNewInstance.java index a00193aa02..4b91d2e887 100644 --- a/src/main/java/org/openrewrite/java/migrate/lang/MigrateClassNewInstanceToGetDeclaredConstructorNewInstance.java +++ b/src/main/java/org/openrewrite/java/migrate/lang/MigrateClassNewInstanceToGetDeclaredConstructorNewInstance.java @@ -70,8 +70,8 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu J.Try tri = getCursor().firstEnclosing(J.Try.class); J.Try.Catch catch_ = getCursor().firstEnclosing(J.Try.Catch.class); J.MethodDeclaration md = getCursor().firstEnclosing(J.MethodDeclaration.class); - if ((catch_ == null && tri != null && tri.getCatches().stream().anyMatch(c -> isExceptionType(c.getParameter().getType()))) - || (md != null && md.getThrows() != null && md.getThrows().stream().anyMatch(nt -> isExceptionType(nt.getType())))) { + if ((catch_ == null && tri != null && tri.getCatches().stream().anyMatch(c -> isExceptionType(c.getParameter().getType()))) || + (md != null && md.getThrows() != null && md.getThrows().stream().anyMatch(nt -> isExceptionType(nt.getType())))) { mi = (J.MethodInvocation) TO_DECLARED_CONS_NEW_INSTANCE.getVisitor().visitNonNull(mi, ctx); } } @@ -79,8 +79,8 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } private boolean isExceptionType(@Nullable JavaType type) { - return TypeUtils.isOfType(type, exType) - || TypeUtils.isOfType(type, thType); + return TypeUtils.isOfType(type, exType) || + TypeUtils.isOfType(type, thType); } } } diff --git a/src/main/java/org/openrewrite/java/migrate/lang/StringFormatted.java b/src/main/java/org/openrewrite/java/migrate/lang/StringFormatted.java index f8fd457bcd..4ef8347b04 100644 --- a/src/main/java/org/openrewrite/java/migrate/lang/StringFormatted.java +++ b/src/main/java/org/openrewrite/java/migrate/lang/StringFormatted.java @@ -88,10 +88,10 @@ public J visitMethodInvocation(J.MethodInvocation methodInvocation, ExecutionCon } private static boolean wrapperNotNeeded(Expression expression) { - return expression instanceof J.Identifier - || expression instanceof J.Literal - || expression instanceof J.MethodInvocation - || expression instanceof J.FieldAccess; + return expression instanceof J.Identifier || + expression instanceof J.Literal || + expression instanceof J.MethodInvocation || + expression instanceof J.FieldAccess; } } diff --git a/src/main/java/org/openrewrite/java/migrate/lang/UseTextBlocks.java b/src/main/java/org/openrewrite/java/migrate/lang/UseTextBlocks.java index 7a5a234e32..9ef09362d7 100644 --- a/src/main/java/org/openrewrite/java/migrate/lang/UseTextBlocks.java +++ b/src/main/java/org/openrewrite/java/migrate/lang/UseTextBlocks.java @@ -187,9 +187,9 @@ private boolean isEndsWithSpecialCharacters(String content) { } private static boolean allLiterals(Expression exp) { - return isRegularStringLiteral(exp) || exp instanceof J.Binary - && ((J.Binary) exp).getOperator() == J.Binary.Type.Addition - && allLiterals(((J.Binary) exp).getLeft()) && allLiterals(((J.Binary) exp).getRight()); + return isRegularStringLiteral(exp) || exp instanceof J.Binary && + ((J.Binary) exp).getOperator() == J.Binary.Type.Addition && + allLiterals(((J.Binary) exp).getLeft()) && allLiterals(((J.Binary) exp).getRight()); } private static boolean flatAdditiveStringLiterals(Expression expression, @@ -203,8 +203,8 @@ private static boolean flatAdditiveStringLiterals(Expression expression, } concatenationSb.append(b.getPrefix().getWhitespace()).append("-"); concatenationSb.append(b.getPadding().getOperator().getBefore().getWhitespace()).append("-"); - return flatAdditiveStringLiterals(b.getLeft(), stringLiterals, contentSb, concatenationSb) - && flatAdditiveStringLiterals(b.getRight(), stringLiterals, contentSb, concatenationSb); + return flatAdditiveStringLiterals(b.getLeft(), stringLiterals, contentSb, concatenationSb) && + flatAdditiveStringLiterals(b.getRight(), stringLiterals, contentSb, concatenationSb); } else if (isRegularStringLiteral(expression)) { J.Literal l = (J.Literal) expression; stringLiterals.add(l); diff --git a/src/main/java/org/openrewrite/java/migrate/lang/var/DeclarationCheck.java b/src/main/java/org/openrewrite/java/migrate/lang/var/DeclarationCheck.java index e44c9f7df4..d90d62cb85 100644 --- a/src/main/java/org/openrewrite/java/migrate/lang/var/DeclarationCheck.java +++ b/src/main/java/org/openrewrite/java/migrate/lang/var/DeclarationCheck.java @@ -113,8 +113,8 @@ public static boolean useGenerics(J.VariableDeclarations vd) { } initializer = initializer.unwrap(); - return initializer instanceof J.NewClass - && ((J.NewClass) initializer).getClazz() instanceof J.ParameterizedType; + return initializer instanceof J.NewClass && + ((J.NewClass) initializer).getClazz() instanceof J.ParameterizedType; } /** diff --git a/src/main/java/org/openrewrite/java/migrate/lombok/LombokValueToRecord.java b/src/main/java/org/openrewrite/java/migrate/lombok/LombokValueToRecord.java index 6bef69b7b6..e6d5cde053 100644 --- a/src/main/java/org/openrewrite/java/migrate/lombok/LombokValueToRecord.java +++ b/src/main/java/org/openrewrite/java/migrate/lombok/LombokValueToRecord.java @@ -116,12 +116,12 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex private boolean isRelevantClass(J.ClassDeclaration classDeclaration) { List allAnnotations = classDeclaration.getAllAnnotations(); - return classDeclaration.getType() != null - && !J.ClassDeclaration.Kind.Type.Record.equals(classDeclaration.getKind()) - && hasMatchingAnnotations(classDeclaration) - && !hasGenericTypeParameter(classDeclaration) - && classDeclaration.getBody().getStatements().stream().allMatch(this::isRecordCompatibleField) - && !hasIncompatibleModifier(classDeclaration); + return classDeclaration.getType() != null && + !J.ClassDeclaration.Kind.Type.Record.equals(classDeclaration.getKind()) && + hasMatchingAnnotations(classDeclaration) && + !hasGenericTypeParameter(classDeclaration) && + classDeclaration.getBody().getStatements().stream().allMatch(this::isRecordCompatibleField) && + !hasIncompatibleModifier(classDeclaration); } private static Predicate matchAnnotationWithNoArguments(AnnotationMatcher matcher) { @@ -268,9 +268,9 @@ private boolean isMethodInvocationOnRecordTypeClassMember(J.MethodInvocation met String methodName = methodInvocation.getName().getSimpleName(); String classFqn = classType.getFullyQualifiedName(); - return recordTypeToMembers.containsKey(classFqn) - && methodName.startsWith(STANDARD_GETTER_PREFIX) - && recordTypeToMembers.get(classFqn).contains(getterMethodNameToFluentMethodName(methodName)); + return recordTypeToMembers.containsKey(classFqn) && + methodName.startsWith(STANDARD_GETTER_PREFIX) && + recordTypeToMembers.get(classFqn).contains(getterMethodNameToFluentMethodName(methodName)); } private static boolean isClassExpression(@Nullable Expression expression) { diff --git a/src/main/java/org/openrewrite/java/migrate/maven/UseMavenCompilerPluginReleaseConfiguration.java b/src/main/java/org/openrewrite/java/migrate/maven/UseMavenCompilerPluginReleaseConfiguration.java index fa7c2e892d..587680804c 100644 --- a/src/main/java/org/openrewrite/java/migrate/maven/UseMavenCompilerPluginReleaseConfiguration.java +++ b/src/main/java/org/openrewrite/java/migrate/maven/UseMavenCompilerPluginReleaseConfiguration.java @@ -78,16 +78,16 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { Optional source = compilerPluginConfig.getChildValue("source"); Optional target = compilerPluginConfig.getChildValue("target"); Optional release = compilerPluginConfig.getChildValue("release"); - if (!source.isPresent() - && !target.isPresent() - && !release.isPresent() - || currentNewerThanProposed(release)) { + if (!source.isPresent() && + !target.isPresent() && + !release.isPresent() || + currentNewerThanProposed(release)) { return t; } Xml.Tag updated = filterTagChildren(t, compilerPluginConfig, child -> !("source".equals(child.getName()) || "target".equals(child.getName()))); - String releaseVersionValue = hasJavaVersionProperty(getCursor().firstEnclosingOrThrow(Xml.Document.class)) - ? "${java.version}" : releaseVersion.toString(); + String releaseVersionValue = hasJavaVersionProperty(getCursor().firstEnclosingOrThrow(Xml.Document.class)) ? + "${java.version}" : releaseVersion.toString(); updated = addOrUpdateChild(updated, compilerPluginConfig, Xml.Tag.build("" + releaseVersionValue + ""), getCursor().getParentOrThrow()); return updated; diff --git a/src/main/java/org/openrewrite/java/migrate/util/ListFirstAndLast.java b/src/main/java/org/openrewrite/java/migrate/util/ListFirstAndLast.java index 90d86184e2..9deddf8c89 100644 --- a/src/main/java/org/openrewrite/java/migrate/util/ListFirstAndLast.java +++ b/src/main/java/org/openrewrite/java/migrate/util/ListFirstAndLast.java @@ -137,9 +137,9 @@ private static J.MethodInvocation getMethodInvocation(J.MethodInvocation mi, Str private static boolean lastElementOfSequencedCollection(J.Identifier sequencedCollection, Expression expression) { if (expression instanceof J.Binary) { J.Binary binary = (J.Binary) expression; - if (binary.getOperator() == J.Binary.Type.Subtraction - && J.Literal.isLiteralValue(binary.getRight(), 1) - && SIZE_MATCHER.matches(binary.getLeft())) { + if (binary.getOperator() == J.Binary.Type.Subtraction && + J.Literal.isLiteralValue(binary.getRight(), 1) && + SIZE_MATCHER.matches(binary.getLeft())) { Expression sizeSelect = ((J.MethodInvocation) binary.getLeft()).getSelect(); if (sizeSelect instanceof J.Identifier) { return sequencedCollection.getSimpleName().equals(((J.Identifier) sizeSelect).getSimpleName()); diff --git a/src/main/java/org/openrewrite/java/migrate/util/RemoveFinalizerFromZip.java b/src/main/java/org/openrewrite/java/migrate/util/RemoveFinalizerFromZip.java index db2fcc5553..4934c9f612 100644 --- a/src/main/java/org/openrewrite/java/migrate/util/RemoveFinalizerFromZip.java +++ b/src/main/java/org/openrewrite/java/migrate/util/RemoveFinalizerFromZip.java @@ -91,9 +91,9 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) } private boolean shouldRemoveFinalize(JavaType type) { - return TypeUtils.isAssignableTo(JAVA_UTIL_ZIP_DEFLATER, type) - || TypeUtils.isAssignableTo(JAVA_UTIL_ZIP_INFLATER, type) - || TypeUtils.isAssignableTo(JAVA_UTIL_ZIP_ZIP_FILE, type); + return TypeUtils.isAssignableTo(JAVA_UTIL_ZIP_DEFLATER, type) || + TypeUtils.isAssignableTo(JAVA_UTIL_ZIP_INFLATER, type) || + TypeUtils.isAssignableTo(JAVA_UTIL_ZIP_ZIP_FILE, type); } }); } diff --git a/src/main/java/org/openrewrite/java/migrate/util/ReplaceStreamCollectWithToList.java b/src/main/java/org/openrewrite/java/migrate/util/ReplaceStreamCollectWithToList.java index f09cabb21d..f1f116c8c9 100644 --- a/src/main/java/org/openrewrite/java/migrate/util/ReplaceStreamCollectWithToList.java +++ b/src/main/java/org/openrewrite/java/migrate/util/ReplaceStreamCollectWithToList.java @@ -96,8 +96,8 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu return result; } Expression command = method.getArguments().get(0); - if (COLLECT_TO_UNMODIFIABLE_LIST.matches(command) - || convertToList && COLLECT_TO_LIST.matches(command)) { + if (COLLECT_TO_UNMODIFIABLE_LIST.matches(command) || + convertToList && COLLECT_TO_LIST.matches(command)) { maybeRemoveImport("java.util.stream.Collectors"); J.MethodInvocation toList = template.apply(updateCursor(result), result.getCoordinates().replace(), result.getSelect()); return toList.getPadding().withSelect(result.getPadding().getSelect()); diff --git a/src/main/java/org/openrewrite/java/migrate/util/UseEnumSetOf.java b/src/main/java/org/openrewrite/java/migrate/util/UseEnumSetOf.java index 978f9b8139..61b169b8a1 100644 --- a/src/main/java/org/openrewrite/java/migrate/util/UseEnumSetOf.java +++ b/src/main/java/org/openrewrite/java/migrate/util/UseEnumSetOf.java @@ -57,8 +57,8 @@ public TreeVisitor getVisitor() { public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { J.MethodInvocation m = super.visitMethodInvocation(method, ctx); - if (SET_OF.matches(method) && method.getType() instanceof JavaType.Parameterized - && !TypeUtils.isOfClassType(method.getType(), "java.util.EnumSet")) { + if (SET_OF.matches(method) && method.getType() instanceof JavaType.Parameterized && + !TypeUtils.isOfClassType(method.getType(), "java.util.EnumSet")) { Cursor parent = getCursor().dropParentUntil(is -> is instanceof J.Assignment || is instanceof J.VariableDeclarations || is instanceof J.Block); if (!(parent.getValue() instanceof J.Block)) { JavaType type = parent.getValue() instanceof J.Assignment ? diff --git a/src/test/java/org/openrewrite/java/migrate/lang/UseTextBlocksTest.java b/src/test/java/org/openrewrite/java/migrate/lang/UseTextBlocksTest.java index 995e9acd8a..d88fceb644 100644 --- a/src/test/java/org/openrewrite/java/migrate/lang/UseTextBlocksTest.java +++ b/src/test/java/org/openrewrite/java/migrate/lang/UseTextBlocksTest.java @@ -494,14 +494,14 @@ public static void main(String[] args) { """) @Test void textBlockDemo() { - String s1 = "\n=========================================================" - + "\n " - + "\n Welcome to Spring Integration! " - + "\n " - + "\n For more information please visit: " - + "\n https://www.springsource.org/spring-integration " - + "\n " - + "\n========================================================="; + String s1 = "\n=========================================================" + + "\n " + + "\n Welcome to Spring Integration! " + + "\n " + + "\n For more information please visit: " + + "\n https://www.springsource.org/spring-integration " + + "\n " + + "\n========================================================="; String s2 = """ =========================================================