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:

  1. 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 @EventSourcingHandler method, and (2) the first argument of every AggregateLifecycle.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 @EventTag treatment).
  2. 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 Classes
    Modifier and Type
    Class
    Description
    static class 
    Maps 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
     
    getInitialValue(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, getVisitor

    Methods 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

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait