Class AddCommandAnnotation
- All Implemented Interfaces:
Cloneable
@CommandHandler and annotates their command parameter
types with @Command.
If the command class had a field — or a Java record component, or a Kotlin
data class primary constructor parameter — annotated with @RoutingKey, that
annotation is removed and replaced with @Command(routingKey = "fieldName") on the class,
matching the AF5 routing-key contract where the routing key is declared on the command class
itself. Java records and class fields complete the lift in a single OpenRewrite cycle: the
recipe walks J.ClassDeclaration.primaryConstructor (records) and
J.ClassDeclaration.body (fields) directly, and crucially performs the
@RoutingKey removal AFTER JavaTemplate.apply adds the class-level
@Command — JavaTemplate.apply walks the visitor's cursor (still pointing at
the un-modified class declaration) and would otherwise discard any child mutations applied
beforehand. Kotlin data class primary-constructor parameters live outside
J.ClassDeclaration (the Kotlin parser keeps them on a sibling Kotlin LST node), so
for Kotlin the recipe falls back to the visitVariableDeclarations hook to capture
the parameter name and to strip the now-orphaned annotation in a second cycle.
Both AF4 (org.axonframework.commandhandling.CommandHandler) and AF5
(org.axonframework.messaging.commandhandling.annotation.CommandHandler) FQNs are matched
so the recipe is safe to run before or after Axon4ToAxon5Messaging.
- Since:
- 5.1.1
- Author:
- Mateusz Nowak
-
Nested Class Summary
Nested ClassesNested 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 TypeMethodDescriptiongetInitialValue(org.openrewrite.ExecutionContext ctx) org.openrewrite.TreeVisitor<?, org.openrewrite.ExecutionContext> org.openrewrite.TreeVisitor<?, org.openrewrite.ExecutionContext> Methods inherited from class org.openrewrite.ScanningRecipe
clone, generate, generate, getAccumulator, getVisitorMethods inherited from class org.openrewrite.Recipe
addDataTable, builder, buildRecipeList, causesAnotherCycle, 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
-
AddCommandAnnotation
public AddCommandAnnotation()
-
-
Method Details
-
getDisplayName
- Specified by:
getDisplayNamein classorg.openrewrite.Recipe
-
getDescription
- Specified by:
getDescriptionin classorg.openrewrite.Recipe
-
getInitialValue
- Specified by:
getInitialValuein classorg.openrewrite.ScanningRecipe<AddCommandAnnotation.Accumulator>
-
getScanner
public org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> getScanner(AddCommandAnnotation.Accumulator acc) - Specified by:
getScannerin classorg.openrewrite.ScanningRecipe<AddCommandAnnotation.Accumulator>
-
getVisitor
public org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> getVisitor(AddCommandAnnotation.Accumulator acc) - Overrides:
getVisitorin classorg.openrewrite.ScanningRecipe<AddCommandAnnotation.Accumulator>
-