Add support for merging two BeanRegistrationAotContribution instances

Closes gh-31446
This commit is contained in:
Stéphane Nicoll
2023-10-17 12:31:06 +02:00
parent 22db1ac146
commit 9465ff0334
2 changed files with 99 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ package org.springframework.beans.factory.aot;
import java.util.function.UnaryOperator;
import org.springframework.aot.generate.GenerationContext;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -82,4 +83,31 @@ public interface BeanRegistrationAotContribution {
};
}
/**
* Create a contribution that applies the contribution of the first contribution
* followed by the second contribution. Any contribution can be {@code null} to be
* ignored and the concatenated contribution is {@code null} if both inputs are
* {@code null}.
* @param a the first contribution
* @param b the second contribution
* @return the concatenation of the two contributions, or {@code null} if
* they are both {@code null}.
* @since 6.1
*/
@Nullable
static BeanRegistrationAotContribution concat(@Nullable BeanRegistrationAotContribution a,
@Nullable BeanRegistrationAotContribution b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
return (generationContext, beanRegistrationCode) -> {
a.applyTo(generationContext, beanRegistrationCode);
b.applyTo(generationContext, beanRegistrationCode);
};
}
}