Skip to content

Commit

Permalink
Declare Advisor#isPerInstance() as default method
Browse files Browse the repository at this point in the history
Includes INSTANCE constants on default factory classes.

Closes gh-30614
  • Loading branch information
jhoeller committed Jun 8, 2023
1 parent 2317bef commit e210f08
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 56 deletions.
7 changes: 5 additions & 2 deletions spring-aop/src/main/java/org/springframework/aop/Advisor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 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.
Expand Down Expand Up @@ -62,8 +62,11 @@ public interface Advisor {
* Typical Advisor implementations always return {@code true}.
* Use singleton/prototype bean definitions or appropriate programmatic
* proxy creation to ensure that Advisors have the correct lifecycle model.
* <p>As of 6.0.10, the default implementation returns {@code true}.
* @return whether this advice is associated with a particular target instance
*/
boolean isPerInstance();
default boolean isPerInstance() {
return true;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 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.
Expand Down Expand Up @@ -67,11 +67,6 @@ public int getOrder() {
}
}

@Override
public boolean isPerInstance() {
return true;
}

@Override
public Advice getAdvice() {
return this.advice;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 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.
Expand Down Expand Up @@ -91,11 +91,6 @@ public void validateInterfaces() throws IllegalArgumentException {
// Do nothing
}

@Override
public boolean isPerInstance() {
return true;
}

@Override
public Advice getAdvice() {
return this.advice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
@SuppressWarnings("serial")
public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializable {

/**
* Singleton instance of this class.
* @since 6.0.10
*/
public static final DefaultAdvisorChainFactory INSTANCE = new DefaultAdvisorChainFactory();


@Override
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(
Advised config, Method method, @Nullable Class<?> targetClass) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -48,6 +48,12 @@
*/
public class DefaultAopProxyFactory implements AopProxyFactory, Serializable {

/**
* Singleton instance of this class.
* @since 6.0.10
*/
public static final DefaultAopProxyFactory INSTANCE = new DefaultAopProxyFactory();

private static final long serialVersionUID = 7930414337282325166L;


Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -44,7 +44,7 @@ public class ProxyCreatorSupport extends AdvisedSupport {
* Create a new ProxyCreatorSupport instance.
*/
public ProxyCreatorSupport() {
this.aopProxyFactory = new DefaultAopProxyFactory();
this.aopProxyFactory = DefaultAopProxyFactory.INSTANCE;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -606,11 +606,6 @@ public Advice getAdvice() {
throw new UnsupportedOperationException("Cannot invoke methods: " + this.message);
}

@Override
public boolean isPerInstance() {
throw new UnsupportedOperationException("Cannot invoke methods: " + this.message);
}

@Override
public String toString() {
return this.message;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -58,22 +58,12 @@ public int getOrder() {
return Ordered.LOWEST_PRECEDENCE;
}

@Override
public boolean isPerInstance() {
return true;
}


@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof PointcutAdvisor otherAdvisor)) {
return false;
}
return (ObjectUtils.nullSafeEquals(getAdvice(), otherAdvisor.getAdvice()) &&
ObjectUtils.nullSafeEquals(getPointcut(), otherAdvisor.getPointcut()));
return (this == other || (other instanceof PointcutAdvisor otherAdvisor &&
ObjectUtils.nullSafeEquals(getAdvice(), otherAdvisor.getAdvice()) &&
ObjectUtils.nullSafeEquals(getPointcut(), otherAdvisor.getPointcut())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -134,11 +134,6 @@ public Advice getAdvice() {
return this.advice;
}

@Override
public boolean isPerInstance() {
return true;
}

@Override
public ClassFilter getClassFilter() {
return this;
Expand All @@ -152,13 +147,9 @@ public boolean matches(Class<?> clazz) {

@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof DefaultIntroductionAdvisor otherAdvisor)) {
return false;
}
return (this.advice.equals(otherAdvisor.advice) && this.interfaces.equals(otherAdvisor.interfaces));
return (this == other || (other instanceof DefaultIntroductionAdvisor otherAdvisor &&
this.advice.equals(otherAdvisor.advice) &&
this.interfaces.equals(otherAdvisor.interfaces)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 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.
Expand Down Expand Up @@ -77,11 +77,6 @@ public Advice getAdvice() {
return this.advice;
}

@Override
public boolean isPerInstance() {
return true;
}

@Override
public Pointcut getPointcut() {
return this;
Expand Down

0 comments on commit e210f08

Please sign in to comment.