Change method name
org.openrewrite.java.ChangeMethodName
Rename a method.
Recipe source
GitHub, Issue Tracker, Maven Central
This recipe is available under the Apache License Version 2.0.
Options
Type | Name | Description | Example |
---|---|---|---|
String | methodPattern | A method pattern is used to find matching method invocations. For example, to find all method invocations in the Guava library, use the pattern: com.google.common..*#*(..) .The pattern format is <PACKAGE>#<METHOD_NAME>(<ARGS>) . ..* includes all subpackages of com.google.common . *(..) matches any method name with any number of arguments. For more specific queries, like Guava's ImmutableMap , use com.google.common.collect.ImmutableMap#*(..) to narrow down the results. | org.mockito.Matchers anyVararg() |
String | newMethodName | The method name that will replace the existing name. | any |
Boolean | matchOverrides | Optional. When enabled, find methods that are overrides of the method pattern. | |
Boolean | ignoreDefinition | Optional. When set to true the definition of the old type will be left untouched. This is useful when you're replacing usage of a class but don't want to rename it. |
Used by
This recipe is used as part of the following composite recipes:
- Adopt
SequencedCollection
- Adopt
javax.security.auth.Subject.current()
andjavax.security.auth.Subject.callAs()
methods` - Adopt
setLongThreadID
injava.util.logging.LogRecord
- Adopt
setLongThreadID
injava.util.logging.LogRecord
- ArchUnit 0.x upgrade
- Change S3 methods to v2.
- Change S3EventNotification methods to v2.
- Change SDK Exception types from v1 to v2
- Change TransferManager simple methods to v2.
- Change
List#add
toList#plus
and verify. - Change auth related classes from v1 to v2
- Change config related classes from v1 to v2
- Change of method names brought by Camel JMX API changes
- Change of method names brought by Camel JMX API changes
- Change region related classes
- Change v1 enum getters to v2
- JUnit Jupiter migration from JUnit 4.x
- Migrate Apache Commons Logging 1.x to SLF4J 1.x
- Migrate Fest 2.x to AssertJ
- Migrate Hamcrest assertions to JUnit Jupiter
- Migrate JCL to Log4j 2.x API
- Migrate JUL to Log4j 2.x API
- Migrate Log4j 1.x to Log4j 2.x
- Migrate Log4j 2.x to SLF4J 1.x
- Migrate SLF4J to Log4j 2.x API
- Migrate from EasyMock to Mockito
- Migrate from Java Faker to Datafaker
- Migrate from Micronaut 2.x to 3.x
- Migrate from springdoc-openapi-common to springdoc-openapi-starter-common
- Migrate to ApacheHttpClient 5.x deprecated methods from 4.x
- Migrate to Hibernate 6.6.x
- Migrate to HtmlUnit 3.x
- Migrate to Reactor 3.5
- Migrate to Spring Framework 6.2
- Migrates to Apache Commons Lang 3.x
- Mockito 3.x migration from 1.x
- PlanningVariable's
nullable
is newly calledunassignedValues
- Prefer
Integer#compareUnsigned
- Prefer
Integer#divideUnsigned
- Prefer
Long#compareUnsigned
- Prefer
Long#divideUnsigned
- Prefer
Math#addExact
- Prefer
Math#clamp
- Prefer
Math#multiplyExact
- Prefer
Math#subtractExact
- Prefer
java.util.Objects#equals
- Prefer
java.util.Objects#hash
- Prefer
java.util.Objects#requireNonNullElse
- Prefer
java.util.Optional
- Prefer
java.util.function.Predicate
- Quarkus 1.13 migration from Quarkus 1.11
- Recommended Fit API becomes Assignment Recommendation API
- Replace deprecated Jakarta Servlet methods and classes
- Replace
ContainerState.getContainerIpAddress()
withgetHost()
- Replace
HttpServletRequestWrapper.isRequestedSessionIdFromUrl()
withisRequestedSessionIdFromURL()
- Replace
Paths.get
withPath.of
- Replace
SSLSession.getPeerCertificateChain()
method - Replace
doUpgrade(..)
withServerContainer.upgradeHttpToWebSocket(..)
- Replace
finalize
method injava.io.FileInputStream
andjava.io.FileOutputStream
- Replace
finalize
method injava.util.zip.ZipFile
,java.util.zip.Inflater
andjava.util.zip.Deflater
- Replace
hudson.Util.getPastTimeString
withgetTimeSpanString
- Replace
org.apache.commons.lang3.Validate#notNull
withObjects#requireNonNull
- Replace calls to
Thread.run()
withThread.start()
- Replace deprecated Jakarta Servlet methods and classes
- Replace deprecated setters in
RestTemplateBuilder
- The header name for the List metadata has changed
- Upgrade to SpringDoc 2.1
- Upgrade to the latest Timefold Solver
- Use
AtomicBoolean#weakCompareAndSetPlain(boolean, boolean)
- Use
AtomicInteger#weakCompareAndSetPlain(int, int)
- Use
AtomicIntegerArray#weakCompareAndSetPlain(int, int, int)
- Use
AtomicLong#weakCompareAndSetPlain(long, long)
- Use
AtomicLongArray#weakCompareAndSetPlain(int, long, long)
- Use
AtomicReference#weakCompareAndSetPlain(T, T)
- Use
AtomicReferenceArray#weakCompareAndSetPlain(int, T, T)
- Use
Character#isJavaIdentifierPart(char)
- Use
Character#isJavaIdentifierStart(char)
- Use
Character#isWhitespace(char)
- Use
JpaRepository#deleteAllInBatch(Iterable<T> entities)
- Use
JpaRepository#getById(ID id)
- Use
JpaRepository#getReferenceById(ID id)
- Use
RestTemplateBuilder#basicAuthentication
- Use
Runtime.Version#feature()
- Use
Runtime.Version#interim()
- Use
Runtime.Version#update()
- Use
StateManagementStrategy
- Use
StateManagementStrategy
- Use
getSSOCookieFromSSOToken
andlogout
- Use
isEagerFilterInit()
- Use
isParametersProvided()
- Use
jakarta.xml.soap.SOAPFactory
to createSOAPElements
- Use
java.net.MulticastSocket#getTimeToLive()
- Use
javax.management.monitor.CounterMonitor#setInitThreshold
- Use
javax.xml.stream.XMLEventFactory#newFactory(String, ClassLoader)
- Use
javax.xml.stream.XMLInputFactory#newFactory(String, ClassLoader)
- Use
javax.xml.stream.XMLOutputFactory#newFactory(String, ClassLoader)
- Use
setEagerFilterInit(boolean)
- io.quarkus.updates.core.quarkus324.MigrateFromHibernateOrmSessionMethodsRemovedIn7
- io.quarkus.updates.core.quarkus35.MutinyUniAndGroupCombinedWith
- io.quarkus.updates.core.quarkus35.MutinyUniMemoizeAtLeast
Usage
This recipe has required configuration parameters. Recipes with required configuration parameters cannot be activated directly (unless you are running them via the Moderne CLI). To activate this recipe you must create a new recipe which fills in the required parameters. In your rewrite.yml
create a new recipe with a unique name. For example: com.yourorg.ChangeMethodNameExample
.
Here's how you can define and customize such a recipe within your rewrite.yml:
---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.ChangeMethodNameExample
displayName: Change method name example
recipeList:
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.mockito.Matchers anyVararg()
newMethodName: any
Now that com.yourorg.ChangeMethodNameExample
has been defined, activate it in your build file:
- Gradle
- Maven
- Moderne CLI
- Add the following to your
build.gradle
file:
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("com.yourorg.ChangeMethodNameExample")
setExportDatatables(true)
}
repositories {
mavenCentral()
}
- Run
gradle rewriteRun
to run the recipe.
- Add the following to your
pom.xml
file:
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.15.0</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>com.yourorg.ChangeMethodNameExample</recipe>
</activeRecipes>
</configuration>
</plugin>
</plugins>
</build>
</project>
- Run
mvn rewrite:run
to run the recipe.
You will need to have configured the Moderne CLI on your machine before you can run the following command.
mod run . --recipe ChangeMethodName --recipe-option "methodPattern=org.mockito.Matchers anyVararg()" --recipe-option "newMethodName=any"
If the recipe is not available locally, then you can install it using:
mod config recipes jar install org.openrewrite:rewrite-java:8.59.1
See how this recipe works across multiple open-source repositories
Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.
Data Tables
- SourcesFileResults
- SourcesFileErrors
- RecipeRunStats
Source files that had results
org.openrewrite.table.SourcesFileResults
Source files that were modified by the recipe run.
Column Name | Description |
---|---|
Source path before the run | The source path of the file before the run. null when a source file was created during the run. |
Source path after the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
Parent of the recipe that made changes | In a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all. |
Recipe that made changes | The specific recipe that made a change. |
Estimated time saving | An estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds. |
Cycle | The recipe cycle in which the change was made. |
Source files that errored on a recipe
org.openrewrite.table.SourcesFileErrors
The details of all errors produced by a recipe run.
Column Name | Description |
---|---|
Source path | The file that failed to parse. |
Recipe that made changes | The specific recipe that made a change. |
Stack trace | The stack trace of the failure. |
Recipe performance
org.openrewrite.table.RecipeRunStats
Statistics used in analyzing the performance of recipes.
Column Name | Description |
---|---|
The recipe | The recipe whose stats are being measured both individually and cumulatively. |
Source file count | The number of source files the recipe ran over. |
Source file changed count | The number of source files which were changed in the recipe run. Includes files created, deleted, and edited. |
Cumulative scanning time (ns) | The total time spent across the scanning phase of this recipe. |
99th percentile scanning time (ns) | 99 out of 100 scans completed in this amount of time. |
Max scanning time (ns) | The max time scanning any one source file. |
Cumulative edit time (ns) | The total time spent across the editing phase of this recipe. |
99th percentile edit time (ns) | 99 out of 100 edits completed in this amount of time. |
Max edit time (ns) | The max time editing any one source file. |
Contributors
Jonathan Schnéider, JohannisK, Greg Adams, Sam Snyder, Tim te Beek, Knut Wannheden, Tyler Van Gorder, traceyyoshima, Aaron Gershman