Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
项羽过江东
spring-framework-source
提交
13e62d0b
spring-framework-source
项目概览
项羽过江东
/
spring-framework-source
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
spring-framework-source
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
13e62d0b
编写于
3月 25, 2021
作者:
J
Jinhui-Z
提交者:
Stephane Nicoll
8月 28, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce reverse on ClassFilter and MethodFilter
See gh-26725
上级
c9184188
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
132 addition
and
0 deletion
+132
-0
spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java
...in/java/org/springframework/aop/support/ClassFilters.java
+47
-0
spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java
.../java/org/springframework/aop/support/MethodMatchers.java
+63
-0
spring-aop/src/test/java/org/springframework/aop/support/ClassFiltersTests.java
...va/org/springframework/aop/support/ClassFiltersTests.java
+9
-0
spring-aop/src/test/java/org/springframework/aop/support/MethodMatchersTests.java
.../org/springframework/aop/support/MethodMatchersTests.java
+13
-0
未找到文件。
spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java
浏览文件 @
13e62d0b
...
@@ -85,6 +85,17 @@ public abstract class ClassFilters {
...
@@ -85,6 +85,17 @@ public abstract class ClassFilters {
return
new
IntersectionClassFilter
(
classFilters
);
return
new
IntersectionClassFilter
(
classFilters
);
}
}
/**
* reverse the given ClassFilter match.
* @param cf the ClassFilter
* @return a distinct ClassFilter that not matches classes
* of the given ClassFilter match
*/
public
static
ClassFilter
reversion
(
ClassFilter
cf
)
{
Assert
.
notNull
(
cf
,
"ClassFilter must not be null"
);
return
new
ReversionClassFilter
(
cf
);
}
/**
/**
* ClassFilter implementation for a union of the given ClassFilters.
* ClassFilter implementation for a union of the given ClassFilters.
...
@@ -167,4 +178,40 @@ public abstract class ClassFilters {
...
@@ -167,4 +178,40 @@ public abstract class ClassFilters {
}
}
/**
* ClassFilter implementation for an reversion of the given ClassFilter.
*/
@SuppressWarnings
(
"serial"
)
private
static
class
ReversionClassFilter
implements
ClassFilter
,
Serializable
{
private
final
ClassFilter
filter
;
ReversionClassFilter
(
ClassFilter
filter
)
{
this
.
filter
=
filter
;
}
@Override
public
boolean
matches
(
Class
<?>
clazz
)
{
return
!
this
.
filter
.
matches
(
clazz
);
}
@Override
public
boolean
equals
(
@Nullable
Object
other
)
{
return
(
this
==
other
||
(
other
instanceof
ReversionClassFilter
&&
this
.
filter
.
equals
(((
ReversionClassFilter
)
other
).
filter
)));
}
@Override
public
int
hashCode
()
{
return
37
*
this
.
filter
.
hashCode
();
}
@Override
public
String
toString
()
{
return
getClass
().
getName
()
+
": "
+
this
.
filter
;
}
}
}
}
spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java
浏览文件 @
13e62d0b
...
@@ -81,6 +81,16 @@ public abstract class MethodMatchers {
...
@@ -81,6 +81,16 @@ public abstract class MethodMatchers {
new
IntersectionIntroductionAwareMethodMatcher
(
mm1
,
mm2
)
:
new
IntersectionMethodMatcher
(
mm1
,
mm2
));
new
IntersectionIntroductionAwareMethodMatcher
(
mm1
,
mm2
)
:
new
IntersectionMethodMatcher
(
mm1
,
mm2
));
}
}
/**
* reverse the given MethodMatcher match.
* @param mm the MethodMatcher
* @return a distinct MethodMatcher that not matches methods
* of the given MethodMatcher match
*/
public
static
MethodMatcher
reversion
(
MethodMatcher
mm
)
{
return
new
ReversionMethodMatcher
(
mm
);
}
/**
/**
* Apply the given MethodMatcher to the given Method, supporting an
* Apply the given MethodMatcher to the given Method, supporting an
* {@link org.springframework.aop.IntroductionAwareMethodMatcher}
* {@link org.springframework.aop.IntroductionAwareMethodMatcher}
...
@@ -338,4 +348,57 @@ public abstract class MethodMatchers {
...
@@ -338,4 +348,57 @@ public abstract class MethodMatchers {
}
}
}
}
/**
* MethodMatcher implementation for an reversion of the given MethodMatcher.
*/
@SuppressWarnings
(
"serial"
)
private
static
class
ReversionMethodMatcher
implements
MethodMatcher
,
Serializable
{
protected
final
MethodMatcher
mm
;
public
ReversionMethodMatcher
(
MethodMatcher
mm
)
{
Assert
.
notNull
(
mm
,
"MethodMatcher must not be null"
);
this
.
mm
=
mm
;
}
@Override
public
boolean
matches
(
Method
method
,
Class
<?>
targetClass
)
{
return
!
this
.
mm
.
matches
(
method
,
targetClass
);
}
@Override
public
boolean
isRuntime
()
{
return
this
.
mm
.
isRuntime
();
}
@Override
public
boolean
matches
(
Method
method
,
Class
<?>
targetClass
,
Object
...
args
)
{
return
!
this
.
mm
.
matches
(
method
,
targetClass
,
args
);
}
@Override
public
boolean
equals
(
@Nullable
Object
other
)
{
if
(
this
==
other
)
{
return
true
;
}
if
(!(
other
instanceof
ReversionMethodMatcher
))
{
return
false
;
}
ReversionMethodMatcher
that
=
(
ReversionMethodMatcher
)
other
;
return
this
.
mm
.
equals
(
that
.
mm
);
}
@Override
public
int
hashCode
()
{
return
37
*
this
.
mm
.
hashCode
();
}
@Override
public
String
toString
()
{
return
getClass
().
getName
()
+
": "
+
this
.
mm
;
}
}
}
}
spring-aop/src/test/java/org/springframework/aop/support/ClassFiltersTests.java
浏览文件 @
13e62d0b
...
@@ -66,4 +66,13 @@ class ClassFiltersTests {
...
@@ -66,4 +66,13 @@ class ClassFiltersTests {
.
matches
(
"^.+IntersectionClassFilter: \\[.+RootClassFilter: .+Exception, .+RootClassFilter: .+NestedRuntimeException\\]$"
);
.
matches
(
"^.+IntersectionClassFilter: \\[.+RootClassFilter: .+Exception, .+RootClassFilter: .+NestedRuntimeException\\]$"
);
}
}
@Test
void
reversion
()
{
assertThat
(
exceptionFilter
.
matches
(
RuntimeException
.
class
)).
isTrue
();
ClassFilter
reversion
=
ClassFilters
.
reversion
(
exceptionFilter
);
assertThat
(
reversion
.
matches
(
RuntimeException
.
class
)).
isFalse
();
assertThat
(
reversion
.
toString
())
.
matches
(
"^.+ReversionClassFilter: .+RootClassFilter: .+Exception$"
);
}
}
}
spring-aop/src/test/java/org/springframework/aop/support/MethodMatchersTests.java
浏览文件 @
13e62d0b
...
@@ -111,6 +111,19 @@ public class MethodMatchersTests {
...
@@ -111,6 +111,19 @@ public class MethodMatchersTests {
assertThat
(
second
.
equals
(
first
)).
isTrue
();
assertThat
(
second
.
equals
(
first
)).
isTrue
();
}
}
@Test
public
void
testDynamicAndStaticMethodMatcherReversion
()
throws
Exception
{
MethodMatcher
getterMatcher
=
new
StartsWithMatcher
(
"get"
);
MethodMatcher
reversion
=
MethodMatchers
.
reversion
(
getterMatcher
);
assertThat
(
reversion
.
isRuntime
()).
as
(
"Reversion is a static matcher"
).
isFalse
();
assertThat
(
reversion
.
matches
(
ITESTBEAN_GETAGE
,
TestBean
.
class
)).
as
(
"Didn't matched getAge method"
).
isFalse
();
assertThat
(
reversion
.
matches
(
IOTHER_ABSQUATULATE
,
TestBean
.
class
)).
as
(
"Matched absquatulate method"
).
isTrue
();
reversion
=
MethodMatchers
.
reversion
(
new
TestDynamicMethodMatcherWhichDoesNotMatch
());
assertThat
(
reversion
.
isRuntime
()).
as
(
"Intersection is a dynamic matcher"
).
isTrue
();
assertThat
(
reversion
.
matches
(
ITESTBEAN_SETAGE
,
TestBean
.
class
)).
as
(
"Didn't matched setAge method"
).
isFalse
();
assertThat
(
reversion
.
matches
(
ITESTBEAN_SETAGE
,
TestBean
.
class
,
5
)).
as
(
"Matched setAge method"
).
isTrue
();
}
public
static
class
StartsWithMatcher
extends
StaticMethodMatcher
{
public
static
class
StartsWithMatcher
extends
StaticMethodMatcher
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录