Class AddCommandAnnotation
- All Implemented Interfaces:
Cloneable
@CommandHandler and annotates their command parameter
types with @Command.
Routing-key lifting: If the command class has 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. Likewise, if the field carries
@TargetAggregateIdentifier (AF4) or its post-rename AF5 successor
@TargetEntityId, the field name is lifted onto @Command#routingKey; unlike
@RoutingKey, those annotations are preserved on the field.
Precedence: When a class declares both an explicit @RoutingKey field
and a @TargetAggregateIdentifier / @TargetEntityId field, the explicit
@RoutingKey field wins regardless of declaration order, matching AF4 routing semantics
where @RoutingKey takes precedence over the target-identifier annotations.
Idempotent updates: If the class already carries a @Command
annotation whose routingKey attribute is missing or blank, the recipe adds the
attribute rather than skipping the class. A @Command with a non-empty
routingKey is left untouched.
Ordering: 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 @RoutingKey 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, aggregateDataTableDescriptors, 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>
-