Replace annotation
Recipe ID
org.openrewrite.java.ReplaceAnnotationArtifact
org.openrewrite:rewrite-javaReplace an Annotation with another one if the annotation pattern matches. Only fixed parameters can be set in the replacement.
Usage
You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.java.ReplaceAnnotation --recipe-option "annotationPatternToReplace=@org.jetbrains.annotations.NotNull("Test")" --recipe-option "annotationTemplateToInsert=@org.jetbrains.annotations.NotNull("Null not permitted")"If the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite:rewrite-java:8.88.0Options
| Name | Type | Description |
|---|---|---|
annotationPatternToReplacerequired | String | An annotation matcher, expressed as a method pattern to replace. e.g. @org.jetbrains.annotations.NotNull("Test") |
annotationTemplateToInsertrequired | String | An annotation template to add instead of original one, will be parsed with JavaTemplate.e.g. @org.jetbrains.annotations.NotNull("Null not permitted") |
classpathResourceName | String | If the annotation's type is defined by a jar within the META-INF/rewrite/classpath directory provide its name here so that it can be loaded. When this parameter is not passed the runtime classpath of the recipe is provided to the parser producing the new annotation. This is necessary when the annotation is not on the runtime classpath of the recipe and isn't in the Java standard library. e.g. annotations |
Data tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats