← All recipes
Moderne licensed

Replace Kotlin property assignment with setter call

Recipe IDio.moderne.java.spring.kotlin.ReplaceKotlinPropertyAssignmentWithSetterCall
Artifactio.moderne.recipe:rewrite-spring

Rewrites 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.

Single recipeProprietary

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.0

Options

NameTypeDescription
methodPatternrequiredStringA 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(..)
propertyNamerequiredStringThe 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