Class GeneratedRecipeSupport
RecipeIrGenerationExtension).
The plugin generates Recipe subclasses whose
getVisitor() body is a single call into one of these factories,
keeping the IR codegen small and the matching/replacing logic
Java-readable.
methodInvocationRewrite (Kotlin) and methodInvocationRewriteJava
are parallel paths selected by the LST-structural classifier in the IR
extension: the default is methodInvocationRewriteJava (a
JavaVisitor walks both Java AND Kotlin sources via
invalid reference
org.openrewrite.kotlin.TreeVisitorAdapterK.*
LST node — see RecipeIrLanguageDescriptors.isKotlinSpecificTreeNode.
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.openrewrite.TreeVisitor<?, org.openrewrite.ExecutionContext> composeSequential(org.openrewrite.TreeVisitor<?, org.openrewrite.ExecutionContext>[] visitors) Compose visitors sequentially: each runs in declaration order on the result of the previous one.static org.openrewrite.TreeVisitor<?, org.openrewrite.ExecutionContext> methodInvocationRewrite(String matcherSpecsLines, String afterTemplate, String substitutionSourcesCsv, int strictArgCount) Visitor for arewrite { ... } to { ... }recipe whose before lambda body is a method invocation rooted at the receiver param.static org.openrewrite.TreeVisitor<?, org.openrewrite.ExecutionContext> methodInvocationRewriteJava(String matcherSpecsLines, String afterTemplate, String substitutionSourcesCsv, int strictArgCount) Java-rooted parallel ofmethodInvocationRewrite(java.lang.String, java.lang.String, java.lang.String, int).static org.openrewrite.TreeVisitor<?, org.openrewrite.ExecutionContext> methodInvocationRewriteKotlinNotNull(String matcherSpecsLines, String afterTemplate, String substitutionSourcesCsv) Variant ofmethodInvocationRewrite(java.lang.String, java.lang.String, java.lang.String, int)for recipes whose before lambda body issomeCall()!!(a method invocation immediately not-null-asserted).static org.openrewrite.TreeVisitor<?, org.openrewrite.ExecutionContext> propertyAccessRewrite(String matcherSpecsLines, String afterTemplate, String substitutionSourcesCsv) Visitor for arewrite { d: Duration -> d.inHours } to { d -> d.inWholeHours }recipe whose before lambda body is a property access (rather than a method invocation).
-
Method Details
-
methodInvocationRewrite
public static org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> methodInvocationRewrite(String matcherSpecsLines, String afterTemplate, String substitutionSourcesCsv, int strictArgCount) Visitor for arewrite { ... } to { ... }recipe whose before lambda body is a method invocation rooted at the receiver param. Matching is delegated toMethodMatcher; the after template is aKotlinTemplatestring with one#{any()}placeholder per substitution slot.matcherSpecsLinesis a\n-delimited list of MethodMatcher specs — multi-before recipes (rewrite(b1, b2, ...) to a) yield one spec per before lambda and we accept a method invocation when any spec matches. ThesubstitutionSourcesCsvencodes, in template-left-to-right order, how to fill each placeholder from the matched method invocation:-1formethod.getSelect()(the receiver),N >= 0formethod.getArguments().get(N). The CSV is shared across all matchers because the IR pass requires every before lambda to agree on the captured argument shape (same param-index references and same literal(kind, value)at each position). -
methodInvocationRewriteKotlinNotNull
public static org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> methodInvocationRewriteKotlinNotNull(String matcherSpecsLines, String afterTemplate, String substitutionSourcesCsv) Variant ofmethodInvocationRewrite(java.lang.String, java.lang.String, java.lang.String, int)for recipes whose before lambda body issomeCall()!!(a method invocation immediately not-null-asserted). In the rewrite-kotlin LST that pattern parses asK.Unary(NotNull, J.MethodInvocation)— visiting onlyJ.MethodInvocationwould replace just the call and leave a stranded!!on the rewritten template, so this visitor walksK.Unaryinstead and swaps the whole not-null expression for the after template.Matcher specs, substitution-source CSV, and trailing-lambda fix-up semantics are identical to the bare variant — only the entry point and the replacement coordinate (the K.Unary, not its inner J.MethodInvocation) change.
-
propertyAccessRewrite
public static org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> propertyAccessRewrite(String matcherSpecsLines, String afterTemplate, String substitutionSourcesCsv) Visitor for arewrite { d: Duration -> d.inHours } to { d -> d.inWholeHours }recipe whose before lambda body is a property access (rather than a method invocation). The Kotlin parser modelsobj.propas aJ.FieldAccess— so this visitor walksJ.FieldAccessinstead ofJ.MethodInvocation.Matcher specs use the
<owner-fqn>#<property-name>format (rather than theMethodMatcherspelling), since property access has no parenthesised parameter list. Each line ofmatcherSpecsLinesis one such spec; the visitor accepts a field access iff its target type FQN and selector name match any spec.Property accessors have no value arguments, so the substitution source CSV always references the receiver via
-1— the IR pass still emits the receiver placeholder uniformly with the method-invocation path, which keeps the after-template synthesis logic shared. -
methodInvocationRewriteJava
public static org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> methodInvocationRewriteJava(String matcherSpecsLines, String afterTemplate, String substitutionSourcesCsv, int strictArgCount) Java-rooted parallel ofmethodInvocationRewrite(java.lang.String, java.lang.String, java.lang.String, int). Used when the LST-structural classifier defaults arewrite { } to { }clause to aJavaVisitor: the visitor walks both Java and Kotlin sources via, but the template is parsed viainvalid reference
org.openrewrite.kotlin.TreeVisitorAdapterJavaTemplate.Matching, substitution-source semantics, and the multi-spec
\ndelimiter are identical to the Kotlin variant — only the visitor type and the template engine differ. There is no trailing-lambda fix-up: Java has no trailing-lambda syntax, so theOmitParenthesesdance is Kotlin-specific. -
composeSequential
public static org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> composeSequential(org.openrewrite.TreeVisitor<?, org.openrewrite.ExecutionContext>[] visitors) Compose visitors sequentially: each runs in declaration order on the result of the previous one. Backs multi-statementedit/scan/generatebodies inorg.openrewrite.RecipeDsl.Semantics (per plan §7):
isAcceptable(SourceFile, ctx)returns true iff ANY inner visitor accepts the source. Non-accepting inner visitors are skipped for that source.visit(tree, ctx)threadstreethrough each visitor in declaration order, restarting cursor state between visitors. Cursor messages set by one inner visitor are NOT visible to the next. Returning the same instance does NOT short-circuit — the next visitor still runs.- Exceptions propagate; there's no partial-state recovery.
-