Package org.axonframework.migration
Class ConvertCommandHandlerConstructorToCompanionObject
java.lang.Object
org.openrewrite.Recipe
org.axonframework.migration.ConvertCommandHandlerConstructorToCompanionObject
- All Implemented Interfaces:
Cloneable
public class ConvertCommandHandlerConstructorToCompanionObject
extends org.openrewrite.Recipe
Kotlin counterpart to
ConvertCommandHandlerConstructorToStaticMethod.
Rewrites every @CommandHandler constructor(...) on a Kotlin entity class into a
@JvmStatic @CommandHandler fun handle(...) placed inside a companion object
on the same class. The companion-object form is the Kotlin equivalent of the Java
static factory shape that AF5's command-creates-entity handler discovery requires:
the JVM bytecode produced by @JvmStatic matches the static method that
Java aggregates emit, so a single AF5 framework path discovers both.
class Auction { class Auction {
@CommandHandler → companion object {
constructor(cmd: CreateAuction) { @JvmStatic
AggregateLifecycle.apply(cmd) @CommandHandler
} fun handle(cmd: CreateAuction) {
} AggregateLifecycle.apply(cmd)
}
}
}
The recipe sub-parses a synthetic holder class containing the desired companion-object shape
via KotlinParser, then grafts the parsed companion-object node into the original
class body. Building the KObject-marked J.ClassDeclaration via the parser
— rather than synthesizing it node-by-node — sidesteps the Kotlin-specific markers
(KObject, the companion / object J.Modifiers) that the
Kotlin printer needs to emit the right keywords.
Existing companion objects on the host class are NOT merged into; if the developer needs to consolidate, that's a follow-up cleanup.
- Since:
- 5.1.1
- Author:
- Mateusz Nowak
-
Nested Class Summary
Nested classes/interfaces inherited from class org.openrewrite.Recipe
org.openrewrite.Recipe.Builder, org.openrewrite.Recipe.DelegatingRecipe -
Field Summary
Fields inherited from class org.openrewrite.Recipe
contributors, examples, PANIC -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.openrewrite.TreeVisitor<?, org.openrewrite.ExecutionContext> Methods inherited from class org.openrewrite.Recipe
addDataTable, builder, buildRecipeList, causesAnotherCycle, clone, createRecipeDescriptor, equals, getContributors, getDataTableDescriptors, getDescriptor, getEstimatedEffortPerOccurrence, getExamples, getInstanceName, getInstanceNameSuffix, getJacksonPolymorphicTypeTag, getMaintainers, getName, getRecipeList, getTags, hashCode, maxCycles, noop, onComplete, run, run, run, setContributors, setExamples, validate, validate, validateAll, validateAll, withOptions
-
Constructor Details
-
ConvertCommandHandlerConstructorToCompanionObject
public ConvertCommandHandlerConstructorToCompanionObject()
-
-
Method Details
-
getDisplayName
- Specified by:
getDisplayNamein classorg.openrewrite.Recipe
-
getDescription
- Specified by:
getDescriptionin classorg.openrewrite.Recipe
-
getVisitor
public org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> getVisitor()- Overrides:
getVisitorin classorg.openrewrite.Recipe
-