Apply "instanceof pattern matching" in AopProxyUtils
This commit is contained in:
parent
d533eb4a55
commit
36cf1ac1ef
|
@ -36,7 +36,8 @@ import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility methods for AOP proxy factories.
|
* Utility methods for AOP proxy factories.
|
||||||
* Mainly for internal use within the AOP framework.
|
*
|
||||||
|
* <p>Mainly for internal use within the AOP framework.
|
||||||
*
|
*
|
||||||
* <p>See {@link org.springframework.aop.support.AopUtils} for a collection of
|
* <p>See {@link org.springframework.aop.support.AopUtils} for a collection of
|
||||||
* generic AOP utility methods which do not depend on AOP framework internals.
|
* generic AOP utility methods which do not depend on AOP framework internals.
|
||||||
|
@ -59,10 +60,10 @@ public abstract class AopProxyUtils {
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Object getSingletonTarget(Object candidate) {
|
public static Object getSingletonTarget(Object candidate) {
|
||||||
if (candidate instanceof Advised) {
|
if (candidate instanceof Advised advised) {
|
||||||
TargetSource targetSource = ((Advised) candidate).getTargetSource();
|
TargetSource targetSource = advised.getTargetSource();
|
||||||
if (targetSource instanceof SingletonTargetSource) {
|
if (targetSource instanceof SingletonTargetSource singleTargetSource) {
|
||||||
return ((SingletonTargetSource) targetSource).getTarget();
|
return singleTargetSource.getTarget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -82,8 +83,8 @@ public abstract class AopProxyUtils {
|
||||||
Assert.notNull(candidate, "Candidate object must not be null");
|
Assert.notNull(candidate, "Candidate object must not be null");
|
||||||
Object current = candidate;
|
Object current = candidate;
|
||||||
Class<?> result = null;
|
Class<?> result = null;
|
||||||
while (current instanceof TargetClassAware) {
|
while (current instanceof TargetClassAware targetClassAware) {
|
||||||
result = ((TargetClassAware) current).getTargetClass();
|
result = targetClassAware.getTargetClass();
|
||||||
current = getSingletonTarget(current);
|
current = getSingletonTarget(current);
|
||||||
}
|
}
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
|
Loading…
Reference in New Issue