Package org.axonframework.migration
Class AddEventTagAnnotation
java.lang.Object
org.openrewrite.Recipe
org.openrewrite.ScanningRecipe<AddEventTagAnnotation.Accumulator>
org.axonframework.migration.AddEventTagAnnotation
- All Implemented Interfaces:
Cloneable
public class AddEventTagAnnotation
extends org.openrewrite.ScanningRecipe<AddEventTagAnnotation.Accumulator>
Adds
@EventTag(key = "<EntitySimpleName>") to the aggregate-identifier field of every
event class used in @EventSourcingHandler methods.
The recipe runs in two phases:
- Scan – visits entity classes (annotated with
@Aggregate,@EventSourced, or@EventSourcedEntity) and records the event payload type for every event used in the entity, together with the entity's identifier field name and the entity's simple class name. Events are discovered from two sources: (1) the first parameter of each@EventSourcingHandlermethod, and (2) the first argument of everyAggregateLifecycle.apply(...)call site in the entity body. The second source catches events that are published but never re-sourced in this entity (a valid AF4 pattern that would otherwise miss the@EventTagtreatment). - Edit – for every event class recorded in the scan, locates the field whose name
matches the entity's identifier field name and annotates it with
@EventTag(key = "<EntitySimpleName>"). If no field with that exact name is found, the recipe falls back to the first declared field and emits a// TODO(axon4to5):comment so a human reviewer can verify the choice.
Must run before @AggregateIdentifier is removed (i.e. before the
RemoveAnnotation step inside Axon4ToAxon5Modelling), so
that the annotation is still present for the scan.
What the LLM must still do: verify the selected field is truly the aggregate
identifier (especially when the fallback path fires), and adjust key if the entity
simple name differs from the intended tag name.
- Since:
- 5.1.1
- Author:
- Mateusz Nowak
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classMaps event-class FQN → scan result needed to place@EventTag.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 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
-
AddEventTagAnnotation
public AddEventTagAnnotation()
-
-
Method Details
-
getDisplayName
- Specified by:
getDisplayNamein classorg.openrewrite.Recipe
-
getDescription
- Specified by:
getDescriptionin classorg.openrewrite.Recipe
-
getInitialValue
- Specified by:
getInitialValuein classorg.openrewrite.ScanningRecipe<AddEventTagAnnotation.Accumulator>
-
getScanner
public org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> getScanner(AddEventTagAnnotation.Accumulator acc) - Specified by:
getScannerin classorg.openrewrite.ScanningRecipe<AddEventTagAnnotation.Accumulator>
-
getVisitor
public org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> getVisitor(AddEventTagAnnotation.Accumulator acc) - Overrides:
getVisitorin classorg.openrewrite.ScanningRecipe<AddEventTagAnnotation.Accumulator>
-