Skip to main content

Find method usages

org.openrewrite.analysis.search.FindMethods

Find method usages by pattern.

Recipe source

GitHub: FindMethods.java, Issue Tracker, Code Genome Project

This recipe is available under the Apache License Version 2.0.

Options

TypeNameDescriptionExample
StringmethodPatternA method pattern that is used to find matching method invocations.java.util.List add(..)
BooleanmatchOverridesOptional. When enabled, find methods that are overrides of the method pattern.
StringflowOptional. When enabled, show the data or taint flow of the method invocation. Valid options: none, data, taint

Example

Parameters
ParameterValue
methodPatternA <constructor>(String)
matchOverridesfalse
flownull
Unchanged
class A {
public A(String s) {}
}
Before
class Test {
A a = new A("test");
}
After
class Test {
A a = /*~~>*/new A("test");
}

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.FindMethodsExample. Here's how you can define and customize such a recipe within your rewrite.yml:

rewrite.yml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.FindMethodsExample
displayName: Find method usages example
recipeList:
- org.openrewrite.analysis.search.FindMethods:
methodPattern: java.util.List add(..)

Now that com.yourorg.FindMethodsExample has been defined, activate it and take a dependency on org.openrewrite.meta:rewrite-analysis:2.37.1 in your build file:

OpenRewrite artifacts are distributed through the Code Genome Project repository (https://artifacts.codegenomeproject.org/maven), which requires authentication. Sign in to the Code Genome Project to create a download token, then in the snippets below replace USERNAME with the email or username you signed in with and TOKEN with that token. See the quickstart guide for details.

  1. Add the following to your build.gradle file:
    build.gradle
    plugins {
    id("org.openrewrite.rewrite") version("latest.release")
    }

    rewrite {
    activeRecipe("com.yourorg.FindMethodsExample")
    setExportDatatables(true)
    }

    repositories {
    mavenCentral()
    maven {
    url = "https://artifacts.codegenomeproject.org/maven"
    credentials {
    username = "USERNAME"
    password = "TOKEN"
    }
    }
    }

    dependencies {
    rewrite("org.openrewrite.meta:rewrite-analysis:2.37.1")
    }
  2. Run gradle rewriteRun to run the recipe.

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

Method calls

org.openrewrite.java.table.MethodCalls

The text of matching method invocations.

Column NameDescription
Source fileThe source file that the method call occurred in.
Method callThe text of the method call.
Class nameThe class name of the method call.
Method nameThe method name of the method call.
Argument typesThe argument types of the method call.