diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java index 8ef1bf148a1..5beb29f55b5 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java @@ -78,10 +78,9 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence */ public static JoinPoint currentJoinPoint() { MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation(); - if (!(mi instanceof ProxyMethodInvocation)) { + if (!(mi instanceof ProxyMethodInvocation pmi)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } - ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; JoinPoint jp = (JoinPoint) pmi.getUserAttribute(JOIN_POINT_KEY); if (jp == null) { jp = new MethodInvocationProceedingJoinPoint(pmi); @@ -714,10 +713,9 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence if (this == other) { return true; } - if (!(other instanceof AdviceExcludingMethodMatcher)) { + if (!(other instanceof AdviceExcludingMethodMatcher otherMm)) { return false; } - AdviceExcludingMethodMatcher otherMm = (AdviceExcludingMethodMatcher) other; return this.adviceMethod.equals(otherMm.adviceMethod); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java index 60a45977513..9497eb30a26 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java @@ -158,7 +158,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov /** The pointcut expression associated with the advice, as a simple String. */ @Nullable - private String pointcutExpression; + private final String pointcutExpression; private boolean raiseExceptions; @@ -759,10 +759,10 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov */ private static class PointcutBody { - private int numTokensConsumed; + private final int numTokensConsumed; @Nullable - private String text; + private final String text; public PointcutBody(int tokens, @Nullable String text) { this.numTokensConsumed = tokens; diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java index 7a7029323d2..e3530a11a5a 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java @@ -63,10 +63,9 @@ public class AspectJAroundAdvice extends AbstractAspectJAdvice implements Method @Override @Nullable public Object invoke(MethodInvocation mi) throws Throwable { - if (!(mi instanceof ProxyMethodInvocation)) { + if (!(mi instanceof ProxyMethodInvocation pmi)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } - ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; ProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi); JoinPointMatch jpm = getJoinPointMatch(pmi); return invokeAdviceMethod(pjp, jpm, null, null); diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java index 8b5e5f6f3e0..40aa1c95f74 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java @@ -523,10 +523,9 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut if (this == other) { return true; } - if (!(other instanceof AspectJExpressionPointcut)) { + if (!(other instanceof AspectJExpressionPointcut otherPc)) { return false; } - AspectJExpressionPointcut otherPc = (AspectJExpressionPointcut) other; return ObjectUtils.nullSafeEquals(this.getExpression(), otherPc.getExpression()) && ObjectUtils.nullSafeEquals(this.pointcutDeclarationScope, otherPc.pointcutDeclarationScope) && ObjectUtils.nullSafeEquals(this.pointcutParameterNames, otherPc.pointcutParameterNames) && diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java index b1a12175212..17fc3422a96 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java @@ -97,10 +97,9 @@ public class AspectJPointcutAdvisor implements PointcutAdvisor, Ordered { if (this == other) { return true; } - if (!(other instanceof AspectJPointcutAdvisor)) { + if (!(other instanceof AspectJPointcutAdvisor otherAdvisor)) { return false; } - AspectJPointcutAdvisor otherAdvisor = (AspectJPointcutAdvisor) other; return this.advice.equals(otherAdvisor.advice); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java index 58f3c23b459..54110bcd0d8 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java @@ -214,8 +214,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac private String resolveExpression(A annotation) { for (String attributeName : EXPRESSION_ATTRIBUTES) { Object val = AnnotationUtils.getValue(annotation, attributeName); - if (val instanceof String) { - String str = (String) val; + if (val instanceof String str) { if (!str.isEmpty()) { return str; } diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AspectJAutoProxyBeanDefinitionParser.java b/spring-aop/src/main/java/org/springframework/aop/config/AspectJAutoProxyBeanDefinitionParser.java index 4271bec65d5..1f23b5ecb7e 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/AspectJAutoProxyBeanDefinitionParser.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/AspectJAutoProxyBeanDefinitionParser.java @@ -59,8 +59,7 @@ class AspectJAutoProxyBeanDefinitionParser implements BeanDefinitionParser { NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); - if (node instanceof Element) { - Element includeElement = (Element) node; + if (node instanceof Element includeElement) { TypedStringValue valueHolder = new TypedStringValue(includeElement.getAttribute("name")); valueHolder.setSource(parserContext.extractSource(includeElement)); includePatterns.add(valueHolder); diff --git a/spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java b/spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java index de31818c70a..70b6870f75c 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java @@ -93,7 +93,7 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser { private static final int POINTCUT_INDEX = 1; private static final int ASPECT_INSTANCE_FACTORY_INDEX = 2; - private ParseState parseState = new ParseState(); + private final ParseState parseState = new ParseState(); @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/config/ScopedProxyBeanDefinitionDecorator.java b/spring-aop/src/main/java/org/springframework/aop/config/ScopedProxyBeanDefinitionDecorator.java index ca940ec518f..0e51956f940 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/ScopedProxyBeanDefinitionDecorator.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/ScopedProxyBeanDefinitionDecorator.java @@ -42,8 +42,7 @@ class ScopedProxyBeanDefinitionDecorator implements BeanDefinitionDecorator { @Override public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { boolean proxyTargetClass = true; - if (node instanceof Element) { - Element ele = (Element) node; + if (node instanceof Element ele) { if (ele.hasAttribute(PROXY_TARGET_CLASS)) { proxyTargetClass = Boolean.parseBoolean(ele.getAttribute(PROXY_TARGET_CLASS)); } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java index d941bdac4c9..57c301e9b11 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java @@ -69,8 +69,7 @@ public abstract class AbstractAdvisingBeanPostProcessor extends ProxyProcessorSu return bean; } - if (bean instanceof Advised) { - Advised advised = (Advised) bean; + if (bean instanceof Advised advised) { if (!advised.isFrozen() && isEligible(AopUtils.getTargetClass(bean))) { // Add our local Advisor to the existing proxy's Advisor chain... if (this.beforeExistingAdvisors) { diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java index b2b8060b8a6..65ca054410e 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java @@ -283,8 +283,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised { } Advisor advisor = this.advisors.remove(index); - if (advisor instanceof IntroductionAdvisor) { - IntroductionAdvisor ia = (IntroductionAdvisor) advisor; + if (advisor instanceof IntroductionAdvisor ia) { // We need to remove introduction interfaces. for (Class ifc : ia.getInterfaces()) { removeInterface(ifc); diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java index 022cc0fddf2..0e6504b64a0 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java @@ -949,10 +949,9 @@ class CglibAopProxy implements AopProxy, Serializable { if (this == other) { return true; } - if (!(other instanceof ProxyCallbackFilter)) { + if (!(other instanceof ProxyCallbackFilter otherCallbackFilter)) { return false; } - ProxyCallbackFilter otherCallbackFilter = (ProxyCallbackFilter) other; AdvisedSupport otherAdvised = otherCallbackFilter.advised; if (this.advised.isFrozen() != otherAdvised.isFrozen()) { return false; diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java b/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java index a8f458781d6..67e435a8835 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 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. @@ -60,9 +60,8 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ Boolean hasIntroductions = null; for (Advisor advisor : advisors) { - if (advisor instanceof PointcutAdvisor) { + if (advisor instanceof PointcutAdvisor pointcutAdvisor) { // Add it conditionally. - PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor; if (config.isPreFiltered() || pointcutAdvisor.getPointcut().getClassFilter().matches(actualClass)) { MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher(); boolean match; @@ -90,8 +89,7 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ } } } - else if (advisor instanceof IntroductionAdvisor) { - IntroductionAdvisor ia = (IntroductionAdvisor) advisor; + else if (advisor instanceof IntroductionAdvisor ia) { if (config.isPreFiltered() || ia.getClassFilter().matches(actualClass)) { Interceptor[] interceptors = registry.getInterceptors(advisor); interceptorList.addAll(Arrays.asList(interceptors)); @@ -111,8 +109,7 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ */ private static boolean hasMatchingIntroductions(Advisor[] advisors, Class actualClass) { for (Advisor advisor : advisors) { - if (advisor instanceof IntroductionAdvisor) { - IntroductionAdvisor ia = (IntroductionAdvisor) advisor; + if (advisor instanceof IntroductionAdvisor ia) { if (ia.getClassFilter().matches(actualClass)) { return true; } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java index 6c9efc49f0d..d14f8008edd 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java @@ -479,8 +479,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport Advisor[] advisors = getAdvisors(); List freshAdvisors = new ArrayList<>(advisors.length); for (Advisor advisor : advisors) { - if (advisor instanceof PrototypePlaceholderAdvisor) { - PrototypePlaceholderAdvisor pa = (PrototypePlaceholderAdvisor) advisor; + if (advisor instanceof PrototypePlaceholderAdvisor pa) { if (logger.isDebugEnabled()) { logger.debug("Refreshing bean named '" + pa.getBeanName() + "'"); } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java b/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java index 1db34223cb4..6b57eb9fa49 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 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. @@ -165,11 +165,9 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea Object interceptorOrInterceptionAdvice = this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex); - if (interceptorOrInterceptionAdvice instanceof InterceptorAndDynamicMethodMatcher) { + if (interceptorOrInterceptionAdvice instanceof InterceptorAndDynamicMethodMatcher dm) { // Evaluate dynamic method matcher here: static part will already have // been evaluated and found to match. - InterceptorAndDynamicMethodMatcher dm = - (InterceptorAndDynamicMethodMatcher) interceptorOrInterceptionAdvice; Class targetClass = (this.targetClass != null ? this.targetClass : this.method.getDeclaringClass()); if (dm.methodMatcher.matches(this.method, targetClass, this.arguments)) { return dm.interceptor.invoke(this); diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java index 7f2c66144b6..da24c8017cf 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java @@ -58,10 +58,9 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se if (adviceObject instanceof Advisor) { return (Advisor) adviceObject; } - if (!(adviceObject instanceof Advice)) { + if (!(adviceObject instanceof Advice advice)) { throw new UnknownAdviceTypeException(adviceObject); } - Advice advice = (Advice) adviceObject; if (advice instanceof MethodInterceptor) { // So well-known it doesn't even need an adapter. return new DefaultPointcutAdvisor(advice); diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisors.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisors.java index 7dfb777dee3..17aa3bfaf52 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisors.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisors.java @@ -68,10 +68,9 @@ public abstract class ExposeBeanNameAdvisors { * @throws IllegalStateException if the bean name has not been exposed */ public static String getBeanName(MethodInvocation mi) throws IllegalStateException { - if (!(mi instanceof ProxyMethodInvocation)) { + if (!(mi instanceof ProxyMethodInvocation pmi)) { throw new IllegalArgumentException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } - ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; String beanName = (String) pmi.getUserAttribute(BEAN_NAME_ATTRIBUTE); if (beanName == null) { throw new IllegalStateException("Cannot get bean name; not set on MethodInvocation: " + mi); @@ -113,10 +112,9 @@ public abstract class ExposeBeanNameAdvisors { @Override @Nullable public Object invoke(MethodInvocation mi) throws Throwable { - if (!(mi instanceof ProxyMethodInvocation)) { + if (!(mi instanceof ProxyMethodInvocation pmi)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } - ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; pmi.setUserAttribute(BEAN_NAME_ATTRIBUTE, this.beanName); return mi.proceed(); } @@ -138,10 +136,9 @@ public abstract class ExposeBeanNameAdvisors { @Override @Nullable public Object invoke(MethodInvocation mi) throws Throwable { - if (!(mi instanceof ProxyMethodInvocation)) { + if (!(mi instanceof ProxyMethodInvocation pmi)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } - ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; pmi.setUserAttribute(BEAN_NAME_ATTRIBUTE, this.beanName); return super.invoke(mi); } diff --git a/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyFactoryBean.java b/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyFactoryBean.java index 281b975a4c8..2a77bf6b54b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyFactoryBean.java +++ b/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyFactoryBean.java @@ -85,11 +85,9 @@ public class ScopedProxyFactoryBean extends ProxyConfig @Override public void setBeanFactory(BeanFactory beanFactory) { - if (!(beanFactory instanceof ConfigurableBeanFactory)) { + if (!(beanFactory instanceof ConfigurableBeanFactory cbf)) { throw new IllegalStateException("Not running in a ConfigurableBeanFactory: " + beanFactory); } - ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) beanFactory; - this.scopedTargetSource.setBeanFactory(beanFactory); ProxyFactory pf = new ProxyFactory(); diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AbstractPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/AbstractPointcutAdvisor.java index 7b7c95a8ac5..9c515e8ed04 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/AbstractPointcutAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/AbstractPointcutAdvisor.java @@ -69,10 +69,9 @@ public abstract class AbstractPointcutAdvisor implements PointcutAdvisor, Ordere if (this == other) { return true; } - if (!(other instanceof PointcutAdvisor)) { + if (!(other instanceof PointcutAdvisor otherAdvisor)) { return false; } - PointcutAdvisor otherAdvisor = (PointcutAdvisor) other; return (ObjectUtils.nullSafeEquals(getAdvice(), otherAdvisor.getAdvice()) && ObjectUtils.nullSafeEquals(getPointcut(), otherAdvisor.getPointcut())); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java index a6ca47c15c3..8add9103caa 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java @@ -200,10 +200,9 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo if (this == other) { return true; } - if (!(other instanceof AbstractRegexpMethodPointcut)) { + if (!(other instanceof AbstractRegexpMethodPointcut otherPointcut)) { return false; } - AbstractRegexpMethodPointcut otherPointcut = (AbstractRegexpMethodPointcut) other; return (Arrays.equals(this.patterns, otherPointcut.patterns) && Arrays.equals(this.excludedPatterns, otherPointcut.excludedPatterns)); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java b/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java index 8055ec98cb6..1260627ff3f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java @@ -284,8 +284,7 @@ public abstract class AopUtils { if (advisor instanceof IntroductionAdvisor) { return ((IntroductionAdvisor) advisor).getClassFilter().matches(targetClass); } - else if (advisor instanceof PointcutAdvisor) { - PointcutAdvisor pca = (PointcutAdvisor) advisor; + else if (advisor instanceof PointcutAdvisor pca) { return canApply(pca.getPointcut(), targetClass, hasIntroductions); } else { diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java index 4bbcaf33341..b73c40bd4c1 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java @@ -188,10 +188,9 @@ public class ComposablePointcut implements Pointcut, Serializable { if (this == other) { return true; } - if (!(other instanceof ComposablePointcut)) { + if (!(other instanceof ComposablePointcut otherPointcut)) { return false; } - ComposablePointcut otherPointcut = (ComposablePointcut) other; return (this.classFilter.equals(otherPointcut.classFilter) && this.methodMatcher.equals(otherPointcut.methodMatcher)); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java index 1c4dd8bf43f..788eae69a5f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java @@ -128,10 +128,9 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher if (this == other) { return true; } - if (!(other instanceof ControlFlowPointcut)) { + if (!(other instanceof ControlFlowPointcut that)) { return false; } - ControlFlowPointcut that = (ControlFlowPointcut) other; return (this.clazz.equals(that.clazz)) && ObjectUtils.nullSafeEquals(this.methodName, that.methodName); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java index ff2370a3223..5fefc059f36 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java @@ -155,10 +155,9 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil if (this == other) { return true; } - if (!(other instanceof DefaultIntroductionAdvisor)) { + if (!(other instanceof DefaultIntroductionAdvisor otherAdvisor)) { return false; } - DefaultIntroductionAdvisor otherAdvisor = (DefaultIntroductionAdvisor) other; return (this.advice.equals(otherAdvisor.advice) && this.interfaces.equals(otherAdvisor.interfaces)); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java index e55cf0b6d3b..a212e8983c4 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java @@ -61,9 +61,9 @@ public class DelegatePerTargetObjectIntroductionInterceptor extends Introduction */ private final Map delegateMap = new WeakHashMap<>(); - private Class defaultImplType; + private final Class defaultImplType; - private Class interfaceType; + private final Class interfaceType; public DelegatePerTargetObjectIntroductionInterceptor(Class defaultImplType, Class interfaceType) { diff --git a/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java b/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java index 23b4d9b78de..6fbd38279dc 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java @@ -146,10 +146,9 @@ public abstract class MethodMatchers { if (this == other) { return true; } - if (!(other instanceof UnionMethodMatcher)) { + if (!(other instanceof UnionMethodMatcher that)) { return false; } - UnionMethodMatcher that = (UnionMethodMatcher) other; return (this.mm1.equals(that.mm1) && this.mm2.equals(that.mm2)); } @@ -223,8 +222,7 @@ public abstract class MethodMatchers { } ClassFilter otherCf1 = ClassFilter.TRUE; ClassFilter otherCf2 = ClassFilter.TRUE; - if (other instanceof ClassFilterAwareUnionMethodMatcher) { - ClassFilterAwareUnionMethodMatcher cfa = (ClassFilterAwareUnionMethodMatcher) other; + if (other instanceof ClassFilterAwareUnionMethodMatcher cfa) { otherCf1 = cfa.cf1; otherCf2 = cfa.cf2; } @@ -312,10 +310,9 @@ public abstract class MethodMatchers { if (this == other) { return true; } - if (!(other instanceof IntersectionMethodMatcher)) { + if (!(other instanceof IntersectionMethodMatcher that)) { return false; } - IntersectionMethodMatcher that = (IntersectionMethodMatcher) other; return (this.mm1.equals(that.mm1) && this.mm2.equals(that.mm2)); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationClassFilter.java b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationClassFilter.java index 847f1bb8622..40530db7189 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationClassFilter.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationClassFilter.java @@ -72,10 +72,9 @@ public class AnnotationClassFilter implements ClassFilter { if (this == other) { return true; } - if (!(other instanceof AnnotationClassFilter)) { + if (!(other instanceof AnnotationClassFilter otherCf)) { return false; } - AnnotationClassFilter otherCf = (AnnotationClassFilter) other; return (this.annotationType.equals(otherCf.annotationType) && this.checkInherited == otherCf.checkInherited); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java index d734fbc0f14..f17a78f6ecb 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java @@ -125,10 +125,9 @@ public class AnnotationMatchingPointcut implements Pointcut { if (this == other) { return true; } - if (!(other instanceof AnnotationMatchingPointcut)) { + if (!(other instanceof AnnotationMatchingPointcut otherPointcut)) { return false; } - AnnotationMatchingPointcut otherPointcut = (AnnotationMatchingPointcut) other; return (this.classFilter.equals(otherPointcut.classFilter) && this.methodMatcher.equals(otherPointcut.methodMatcher)); } @@ -189,10 +188,9 @@ public class AnnotationMatchingPointcut implements Pointcut { if (this == obj) { return true; } - if (!(obj instanceof AnnotationCandidateClassFilter)) { + if (!(obj instanceof AnnotationCandidateClassFilter that)) { return false; } - AnnotationCandidateClassFilter that = (AnnotationCandidateClassFilter) obj; return this.annotationType.equals(that.annotationType); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java index 720c7b889bb..b65661bb4b7 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java @@ -92,10 +92,9 @@ public class AnnotationMethodMatcher extends StaticMethodMatcher { if (this == other) { return true; } - if (!(other instanceof AnnotationMethodMatcher)) { + if (!(other instanceof AnnotationMethodMatcher otherMm)) { return false; } - AnnotationMethodMatcher otherMm = (AnnotationMethodMatcher) other; return (this.annotationType.equals(otherMm.annotationType) && this.checkInherited == otherMm.checkInherited); } diff --git a/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java index 2ebcc216dce..cf3afa032c7 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java @@ -135,10 +135,9 @@ public final class EmptyTargetSource implements TargetSource, Serializable { if (this == other) { return true; } - if (!(other instanceof EmptyTargetSource)) { + if (!(other instanceof EmptyTargetSource otherTs)) { return false; } - EmptyTargetSource otherTs = (EmptyTargetSource) other; return (ObjectUtils.nullSafeEquals(this.targetClass, otherTs.targetClass) && this.isStatic == otherTs.isStatic); } diff --git a/spring-aop/src/main/java/org/springframework/aop/target/SingletonTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/SingletonTargetSource.java index 24ae9865a6d..52115fbf45f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/SingletonTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/SingletonTargetSource.java @@ -85,10 +85,9 @@ public class SingletonTargetSource implements TargetSource, Serializable { if (this == other) { return true; } - if (!(other instanceof SingletonTargetSource)) { + if (!(other instanceof SingletonTargetSource otherTargetSource)) { return false; } - SingletonTargetSource otherTargetSource = (SingletonTargetSource) other; return this.target.equals(otherTargetSource.target); }