Replace Kotlin property assignment with setter call
Recipe ID
io.moderne.java.spring.kotlin.ReplaceKotlinPropertyAssignmentWithSetterCallArtifact
io.moderne.recipe:rewrite-springRewrites a Kotlin property-style assignment (obj.prop = value) to an explicit setter invocation (obj.setProp(value)). Use when a Java library adopts JSpecify @NullMarked and a previously-var synthetic property is demoted to val: Kotlin requires the getter's return type and the setter's parameter type to share the same nullability, and once they diverge the assignment stops compiling.
Usage
You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe io.moderne.java.spring.kotlin.ReplaceKotlinPropertyAssignmentWithSetterCall --recipe-option "methodPattern=org.springframework.boot.web.servlet.AbstractFilterRegistrationBean setFilter(..)" --recipe-option "propertyName=filter"If the recipe isn’t available locally, install it with:
mod config recipes jar install io.moderne.recipe:rewrite-spring:0.39.0Options
| Name | Type | Description |
|---|---|---|
methodPatternrequired | String | A MethodMatcher pattern identifying the Java setter to convert to. Kotlin property assignments whose resolved setter matches this pattern will be rewritten to an explicit set...(value) call.e.g. org.springframework.boot.web.servlet.AbstractFilterRegistrationBean setFilter(..) |
propertyNamerequired | String | The Kotlin synthetic-property name corresponding to the setter (e.g. filter for setFilter, URL for setURL, isEnabled for setEnabled paired with isEnabled()). Kotlin's naming rules preserve acronyms and the is prefix on boolean properties, so the property name is stated explicitly rather than derived.e.g. filter |
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