Class MigrateSequencingPolicyLambda

java.lang.Object
org.openrewrite.Recipe
org.axonframework.migration.MigrateSequencingPolicyLambda
All Implemented Interfaces:
Cloneable

public class MigrateSequencingPolicyLambda extends org.openrewrite.Recipe
Rewrites single-argument SequencingPolicy lambdas to the AF5 two-argument shape with an Optional return.

The SequencingPolicy functional interface changed in two ways between AF4 and AF5:

  • The single method took Object getSequenceIdentifierFor(T event) (one argument, nullable Object return) and now takes Optional<Object> sequenceIdentifierFor(M message, ProcessingContext context) (two arguments, Optional<Object> return).
  • The <T> type parameter was renamed to <M extends Message>.
Source written for AF4 typically looks like e -> e.getMetaData().get(KEY); that does not satisfy the AF5 functional interface (wrong arity, wrong return type), and the user must rewrite both the parameter list and the return.

This recipe handles the common shape — a single-parameter lambda with an expression body whose target type is SequencingPolicy — and rewrites it to (msg, ctx) -> Optional.ofNullable(body), preserving the original parameter name and using Optional.ofNullable to retain the AF4 contract that null indicates "no sequencing requirement". Lambdas with block bodies, multiple parameters, or anonymous inner classes implementing SequencingPolicy are left alone for manual rewriting — the structural variety is too broad for a safe automatic transformation.

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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
     
    org.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

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MigrateSequencingPolicyLambda

      public MigrateSequencingPolicyLambda()
  • Method Details

    • getDisplayName

      public String getDisplayName()
      Specified by:
      getDisplayName in class org.openrewrite.Recipe
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in class org.openrewrite.Recipe
    • getVisitor

      public org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> getVisitor()
      Overrides:
      getVisitor in class org.openrewrite.Recipe