forked from openrewrite/rewrite-migrate-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava-best-practices.yml
More file actions
77 lines (76 loc) · 3.84 KB
/
java-best-practices.yml
File metadata and controls
77 lines (76 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#
# Copyright 2026 the original author or authors.
# <p>
# Licensed under the Moderne Source Available License (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# <p>
# https://docs.moderne.io/licensing/moderne-source-available-license
# <p>
# 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.
#
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.JavaBestPractices
displayName: Java best practices
description: >-
Applies opinionated best practices for Java projects targeting Java 25.
This recipe includes the full Java 25 upgrade chain plus additional improvements
to code style, API usage, and third-party dependency reduction that go beyond
what the version migration recipes apply.
tags:
- java25
- best-practices
preconditions:
- org.openrewrite.Singleton
recipeList:
# Upgrade to the latest Java version
- org.openrewrite.java.migrate.UpgradeToJava25
# Text blocks for strings without newlines (upgrade chain only does convertStringsWithoutNewlines: false)
- org.openrewrite.java.migrate.lang.UseTextBlocks:
convertStringsWithoutNewlines: true
# Prefer Java standard library over Guava where possible
- org.openrewrite.java.migrate.guava.NoGuava
# JSpecify nullability annotations best practices
- org.openrewrite.java.jspecify.JSpecifyBestPractices
# Local variable type inference — targeted, non-controversial uses
# NOTE: UseVarForGenericsConstructors and UseVarForGenericMethodInvocations must run
# before UseDiamondOperator, as they need the explicit type arguments on constructors
# to safely infer the type for var. Diamond would erase that information.
- org.openrewrite.java.migrate.lang.var.UseVarForTypeCast
- org.openrewrite.java.migrate.lang.var.UseVarForConstructors
- org.openrewrite.java.migrate.lang.var.UseVarForGenericsConstructors
- org.openrewrite.java.migrate.lang.var.UseVarForGenericMethodInvocations
- org.openrewrite.java.migrate.lang.var.UseVarForPrimitive
# Prefer modern Java collection factories and utilities
- org.openrewrite.java.migrate.util.JavaUtilAPIs
# Static analysis: bug prevention
- org.openrewrite.staticanalysis.ReplaceWeekYearWithYear
- org.openrewrite.staticanalysis.RemoveHashCodeCallsFromArrayInstances
- org.openrewrite.staticanalysis.RemoveToStringCallsFromArrayInstances
- org.openrewrite.staticanalysis.UseObjectNotifyAll
- org.openrewrite.staticanalysis.RemoveCallsToSystemGc
- org.openrewrite.staticanalysis.RemoveCallsToObjectFinalize
# Static analysis: modernization and cleanup
- org.openrewrite.staticanalysis.ReplaceLambdaWithMethodReference
- org.openrewrite.staticanalysis.UseDiamondOperator
- org.openrewrite.staticanalysis.UnnecessaryParentheses
- org.openrewrite.staticanalysis.ReplaceStringBuilderWithString
- org.openrewrite.staticanalysis.UseCollectionInterfaces
- org.openrewrite.staticanalysis.CompareEnumsWithEqualityOperator
- org.openrewrite.staticanalysis.CombineSemanticallyEqualCatchBlocks
- org.openrewrite.staticanalysis.UseStringReplace
- org.openrewrite.staticanalysis.UseStandardCharset
- org.openrewrite.staticanalysis.UseSystemLineSeparator
- org.openrewrite.staticanalysis.RemoveRedundantTypeCast
- org.openrewrite.staticanalysis.ReplaceStackWithDeque
- org.openrewrite.staticanalysis.UseListSort
- org.openrewrite.staticanalysis.EqualsToContentEquals
# Markdown documentation comments (JEP 467, Java 23+)
- org.openrewrite.java.migrate.lang.JavadocToMarkdownDocComment
# Cleanup imports left behind by transformations
- org.openrewrite.java.RemoveUnusedImports