Skip to content

Commit 0de307b

Browse files
committed
Consistent equals/hashCode/toString implementations in AnnotationMatchingPointcut/ClassFilter/MethodMatcher
Issue: SPR-11275 Issue: SPR-11276
1 parent 26f1e05 commit 0de307b

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationClassFilter.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,4 +66,26 @@ public boolean matches(Class<?> clazz) {
6666
clazz.isAnnotationPresent(this.annotationType));
6767
}
6868

69+
@Override
70+
public boolean equals(Object other) {
71+
if (this == other) {
72+
return true;
73+
}
74+
if (!(other instanceof AnnotationClassFilter)) {
75+
return false;
76+
}
77+
AnnotationClassFilter otherCf = (AnnotationClassFilter) other;
78+
return (this.annotationType.equals(otherCf.annotationType) && this.checkInherited == otherCf.checkInherited);
79+
}
80+
81+
@Override
82+
public int hashCode() {
83+
return this.annotationType.hashCode();
84+
}
85+
86+
@Override
87+
public String toString() {
88+
return getClass().getName() + ": " + this.annotationType;
89+
}
90+
6991
}

spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222
import org.springframework.aop.MethodMatcher;
2323
import org.springframework.aop.Pointcut;
2424
import org.springframework.util.Assert;
25+
import org.springframework.util.ObjectUtils;
2526

2627
/**
2728
* Simple Pointcut that looks for a specific Java 5 annotation
@@ -100,6 +101,36 @@ public MethodMatcher getMethodMatcher() {
100101
return this.methodMatcher;
101102
}
102103

104+
@Override
105+
public boolean equals(Object other) {
106+
if (this == other) {
107+
return true;
108+
}
109+
if (!(other instanceof AnnotationMatchingPointcut)) {
110+
return false;
111+
}
112+
AnnotationMatchingPointcut that = (AnnotationMatchingPointcut) other;
113+
return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) &&
114+
ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher);
115+
}
116+
117+
@Override
118+
public int hashCode() {
119+
int code = 17;
120+
if (this.classFilter != null) {
121+
code = 37 * code + this.classFilter.hashCode();
122+
}
123+
if (this.methodMatcher != null) {
124+
code = 37 * code + this.methodMatcher.hashCode();
125+
}
126+
return code;
127+
}
128+
129+
@Override
130+
public String toString() {
131+
return "AnnotationMatchingPointcut: " + this.classFilter + ", " +this.methodMatcher;
132+
}
133+
103134

104135
/**
105136
* Factory method for an AnnotationMatchingPointcut that matches

spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -74,4 +74,9 @@ public int hashCode() {
7474
return this.annotationType.hashCode();
7575
}
7676

77+
@Override
78+
public String toString() {
79+
return getClass().getName() + ": " + this.annotationType;
80+
}
81+
7782
}

spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationAdvisor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected Pointcut buildPointcut(Set<Class<? extends Annotation>> asyncAnnotatio
143143
ComposablePointcut result = null;
144144
for (Class<? extends Annotation> asyncAnnotationType : asyncAnnotationTypes) {
145145
Pointcut cpc = new AnnotationMatchingPointcut(asyncAnnotationType, true);
146-
Pointcut mpc = new AnnotationMatchingPointcut(null, asyncAnnotationType);
146+
Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(asyncAnnotationType);
147147
if (result == null) {
148148
result = new ComposablePointcut(cpc).union(mpc);
149149
}

0 commit comments

Comments
 (0)