Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
带水的鱼儿
spring-framework
提交
1bc23678
S
spring-framework
项目概览
带水的鱼儿
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1bc23678
编写于
6月 23, 2021
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
300fed97
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
48 addition
and
52 deletion
+48
-52
spring-context/src/main/java/org/springframework/context/annotation/BeanMethod.java
...va/org/springframework/context/annotation/BeanMethod.java
+2
-2
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java
...pringframework/context/annotation/ConfigurationClass.java
+21
-21
spring-context/src/test/java/org/springframework/context/annotation/BeanMethodPolymorphismTests.java
...ework/context/annotation/BeanMethodPolymorphismTests.java
+3
-3
spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java
...springframework/core/type/StandardAnnotationMetadata.java
+3
-3
spring-core/src/test/java/org/springframework/core/type/AbstractClassMetadataMemberClassTests.java
...work/core/type/AbstractClassMetadataMemberClassTests.java
+17
-21
spring-core/src/test/java/org/springframework/core/type/classreading/AnnotationMetadataReadingVisitorTests.java
...e/classreading/AnnotationMetadataReadingVisitorTests.java
+2
-2
未找到文件。
spring-context/src/main/java/org/springframework/context/annotation/BeanMethod.java
浏览文件 @
1bc23678
...
...
@@ -33,7 +33,7 @@ import org.springframework.core.type.MethodMetadata;
*/
final
class
BeanMethod
extends
ConfigurationMethod
{
public
BeanMethod
(
MethodMetadata
metadata
,
ConfigurationClass
configurationClass
)
{
BeanMethod
(
MethodMetadata
metadata
,
ConfigurationClass
configurationClass
)
{
super
(
metadata
,
configurationClass
);
}
...
...
@@ -55,7 +55,7 @@ final class BeanMethod extends ConfigurationMethod {
private
class
NonOverridableMethodError
extends
Problem
{
public
NonOverridableMethodError
()
{
NonOverridableMethodError
()
{
super
(
String
.
format
(
"@Bean method '%s' must not be private or final; change the method's modifiers to continue"
,
getMetadata
().
getMethodName
()),
getResourceLocation
());
}
...
...
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java
浏览文件 @
1bc23678
/*
* Copyright 2002-20
19
the original author or authors.
* Copyright 2002-20
21
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.
...
...
@@ -36,7 +36,7 @@ import org.springframework.util.ClassUtils;
/**
* Represents a user-defined {@link Configuration @Configuration} class.
* Includes a set of {@link Bean} methods, including all such methods
*
<p>
Includes a set of {@link Bean} methods, including all such methods
* defined in the ancestry of the class, in a 'flattened-out' manner.
*
* @author Chris Beams
...
...
@@ -74,7 +74,7 @@ final class ConfigurationClass {
* @param beanName must not be {@code null}
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass)
*/
public
ConfigurationClass
(
MetadataReader
metadataReader
,
String
beanName
)
{
ConfigurationClass
(
MetadataReader
metadataReader
,
String
beanName
)
{
Assert
.
notNull
(
beanName
,
"Bean name must not be null"
);
this
.
metadata
=
metadataReader
.
getAnnotationMetadata
();
this
.
resource
=
metadataReader
.
getResource
();
...
...
@@ -89,7 +89,7 @@ final class ConfigurationClass {
* @param importedBy the configuration class importing this one or {@code null}
* @since 3.1.1
*/
public
ConfigurationClass
(
MetadataReader
metadataReader
,
@Nullable
ConfigurationClass
importedBy
)
{
ConfigurationClass
(
MetadataReader
metadataReader
,
@Nullable
ConfigurationClass
importedBy
)
{
this
.
metadata
=
metadataReader
.
getAnnotationMetadata
();
this
.
resource
=
metadataReader
.
getResource
();
this
.
importedBy
.
add
(
importedBy
);
...
...
@@ -101,7 +101,7 @@ final class ConfigurationClass {
* @param beanName name of the {@code @Configuration} class bean
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass)
*/
public
ConfigurationClass
(
Class
<?>
clazz
,
String
beanName
)
{
ConfigurationClass
(
Class
<?>
clazz
,
String
beanName
)
{
Assert
.
notNull
(
beanName
,
"Bean name must not be null"
);
this
.
metadata
=
AnnotationMetadata
.
introspect
(
clazz
);
this
.
resource
=
new
DescriptiveResource
(
clazz
.
getName
());
...
...
@@ -116,7 +116,7 @@ final class ConfigurationClass {
* @param importedBy the configuration class importing this one (or {@code null})
* @since 3.1.1
*/
public
ConfigurationClass
(
Class
<?>
clazz
,
@Nullable
ConfigurationClass
importedBy
)
{
ConfigurationClass
(
Class
<?>
clazz
,
@Nullable
ConfigurationClass
importedBy
)
{
this
.
metadata
=
AnnotationMetadata
.
introspect
(
clazz
);
this
.
resource
=
new
DescriptiveResource
(
clazz
.
getName
());
this
.
importedBy
.
add
(
importedBy
);
...
...
@@ -128,7 +128,7 @@ final class ConfigurationClass {
* @param beanName name of the {@code @Configuration} class bean
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass)
*/
public
ConfigurationClass
(
AnnotationMetadata
metadata
,
String
beanName
)
{
ConfigurationClass
(
AnnotationMetadata
metadata
,
String
beanName
)
{
Assert
.
notNull
(
beanName
,
"Bean name must not be null"
);
this
.
metadata
=
metadata
;
this
.
resource
=
new
DescriptiveResource
(
metadata
.
getClassName
());
...
...
@@ -136,19 +136,19 @@ final class ConfigurationClass {
}
public
AnnotationMetadata
getMetadata
()
{
AnnotationMetadata
getMetadata
()
{
return
this
.
metadata
;
}
public
Resource
getResource
()
{
Resource
getResource
()
{
return
this
.
resource
;
}
public
String
getSimpleName
()
{
String
getSimpleName
()
{
return
ClassUtils
.
getShortName
(
getMetadata
().
getClassName
());
}
public
void
setBeanName
(
String
beanName
)
{
void
setBeanName
(
String
beanName
)
{
this
.
beanName
=
beanName
;
}
...
...
@@ -171,7 +171,7 @@ final class ConfigurationClass {
* Merge the imported-by declarations from the given configuration class into this one.
* @since 4.0.5
*/
public
void
mergeImportedBy
(
ConfigurationClass
otherConfigClass
)
{
void
mergeImportedBy
(
ConfigurationClass
otherConfigClass
)
{
this
.
importedBy
.
addAll
(
otherConfigClass
.
importedBy
);
}
...
...
@@ -181,35 +181,35 @@ final class ConfigurationClass {
* @since 4.0.5
* @see #isImported()
*/
public
Set
<
ConfigurationClass
>
getImportedBy
()
{
Set
<
ConfigurationClass
>
getImportedBy
()
{
return
this
.
importedBy
;
}
public
void
addBeanMethod
(
BeanMethod
method
)
{
void
addBeanMethod
(
BeanMethod
method
)
{
this
.
beanMethods
.
add
(
method
);
}
public
Set
<
BeanMethod
>
getBeanMethods
()
{
Set
<
BeanMethod
>
getBeanMethods
()
{
return
this
.
beanMethods
;
}
public
void
addImportedResource
(
String
importedResource
,
Class
<?
extends
BeanDefinitionReader
>
readerClass
)
{
void
addImportedResource
(
String
importedResource
,
Class
<?
extends
BeanDefinitionReader
>
readerClass
)
{
this
.
importedResources
.
put
(
importedResource
,
readerClass
);
}
public
void
addImportBeanDefinitionRegistrar
(
ImportBeanDefinitionRegistrar
registrar
,
AnnotationMetadata
importingClassMetadata
)
{
void
addImportBeanDefinitionRegistrar
(
ImportBeanDefinitionRegistrar
registrar
,
AnnotationMetadata
importingClassMetadata
)
{
this
.
importBeanDefinitionRegistrars
.
put
(
registrar
,
importingClassMetadata
);
}
public
Map
<
ImportBeanDefinitionRegistrar
,
AnnotationMetadata
>
getImportBeanDefinitionRegistrars
()
{
Map
<
ImportBeanDefinitionRegistrar
,
AnnotationMetadata
>
getImportBeanDefinitionRegistrars
()
{
return
this
.
importBeanDefinitionRegistrars
;
}
public
Map
<
String
,
Class
<?
extends
BeanDefinitionReader
>>
getImportedResources
()
{
Map
<
String
,
Class
<?
extends
BeanDefinitionReader
>>
getImportedResources
()
{
return
this
.
importedResources
;
}
public
void
validate
(
ProblemReporter
problemReporter
)
{
void
validate
(
ProblemReporter
problemReporter
)
{
// A configuration class may not be final (CGLIB limitation) unless it declares proxyBeanMethods=false
Map
<
String
,
Object
>
attributes
=
this
.
metadata
.
getAnnotationAttributes
(
Configuration
.
class
.
getName
());
if
(
attributes
!=
null
&&
(
Boolean
)
attributes
.
get
(
"proxyBeanMethods"
))
{
...
...
@@ -244,7 +244,7 @@ final class ConfigurationClass {
*/
private
class
FinalConfigurationProblem
extends
Problem
{
public
FinalConfigurationProblem
()
{
FinalConfigurationProblem
()
{
super
(
String
.
format
(
"@Configuration class '%s' may not be final. Remove the final modifier to continue."
,
getSimpleName
()),
new
Location
(
getResource
(),
getMetadata
()));
}
...
...
spring-context/src/test/java/org/springframework/context/annotation/BeanMethodPolymorphismTests.java
浏览文件 @
1bc23678
/*
* Copyright 2002-20
19
the original author or authors.
* Copyright 2002-20
21
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.
...
...
@@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests regarding overloading and overriding of bean methods.
* Related to SPR-6618.
*
<p>
Related to SPR-6618.
*
* @author Chris Beams
* @author Phillip Webb
...
...
@@ -41,7 +41,7 @@ public class BeanMethodPolymorphismTests {
@Test
public
void
beanMethodDetectedOnSuperClass
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
Config
.
class
);
ctx
.
getBean
(
"testBean"
,
TestBean
.
class
);
assertThat
(
ctx
.
getBean
(
"testBean"
,
TestBean
.
class
)).
isNotNull
(
);
}
@Test
...
...
spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java
浏览文件 @
1bc23678
/*
* Copyright 2002-202
0
the original author or authors.
* Copyright 2002-202
1
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,12 +165,12 @@ public class StandardAnnotationMetadata extends StandardClassMetadata implements
return
annotatedMethods
!=
null
?
annotatedMethods
:
Collections
.
emptySet
();
}
private
boolean
isAnnotatedMethod
(
Method
method
,
String
annotationName
)
{
private
static
boolean
isAnnotatedMethod
(
Method
method
,
String
annotationName
)
{
return
!
method
.
isBridge
()
&&
method
.
getAnnotations
().
length
>
0
&&
AnnotatedElementUtils
.
isAnnotated
(
method
,
annotationName
);
}
static
AnnotationMetadata
from
(
Class
<?>
introspectedClass
)
{
return
new
StandardAnnotationMetadata
(
introspectedClass
,
true
);
}
...
...
spring-core/src/test/java/org/springframework/core/type/AbstractClassMetadataMemberClassTests.java
浏览文件 @
1bc23678
/*
* Copyright 2002-20
19
the original author or authors.
* Copyright 2002-20
21
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.
...
...
@@ -20,7 +20,6 @@ import org.junit.jupiter.api.Test;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Abstract base class for testing implementations of
* {@link ClassMetadata#getMemberClassNames()}.
...
...
@@ -30,48 +29,45 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public
abstract
class
AbstractClassMetadataMemberClassTests
{
p
ublic
abstract
ClassMetadata
getClassMetadataFor
(
Class
<?>
clazz
);
p
rotected
abstract
ClassMetadata
getClassMetadataFor
(
Class
<?>
clazz
);
@Test
void
withNoMemberClasses
()
{
ClassMetadata
metadata
=
getClassMetadataFor
(
L0_a
.
class
);
String
[]
nestedClasses
=
metadata
.
getMemberClassNames
();
assertThat
(
nestedClasses
).
isEqualTo
(
new
String
[]{});
}
public
static
class
L0_a
{
assertThat
(
nestedClasses
).
isEmpty
();
}
@Test
void
withPublicMemberClasses
()
{
ClassMetadata
metadata
=
getClassMetadataFor
(
L0_b
.
class
);
String
[]
nestedClasses
=
metadata
.
getMemberClassNames
();
assertThat
(
nestedClasses
).
isEqualTo
(
new
String
[]{
L0_b
.
L1
.
class
.
getName
()}
);
assertThat
(
nestedClasses
).
containsOnly
(
L0_b
.
L1
.
class
.
getName
()
);
}
public
static
class
L0_b
{
public
static
class
L1
{
}
}
@Test
void
withNonPublicMemberClasses
()
{
ClassMetadata
metadata
=
getClassMetadataFor
(
L0_c
.
class
);
String
[]
nestedClasses
=
metadata
.
getMemberClassNames
();
assertThat
(
nestedClasses
).
isEqualTo
(
new
String
[]{
L0_c
.
L1
.
class
.
getName
()});
}
public
static
class
L0_c
{
private
static
class
L1
{
}
assertThat
(
nestedClasses
).
containsOnly
(
L0_c
.
L1
.
class
.
getName
());
}
@Test
void
againstMemberClass
()
{
ClassMetadata
metadata
=
getClassMetadataFor
(
L0_b
.
L1
.
class
);
String
[]
nestedClasses
=
metadata
.
getMemberClassNames
();
assertThat
(
nestedClasses
).
isEqualTo
(
new
String
[]{});
assertThat
(
nestedClasses
).
isEmpty
();
}
public
static
class
L0_a
{
}
public
static
class
L0_b
{
public
static
class
L1
{
}
}
public
static
class
L0_c
{
private
static
class
L1
{
}
}
}
spring-core/src/test/java/org/springframework/core/type/classreading/AnnotationMetadataReadingVisitorTests.java
浏览文件 @
1bc23678
...
...
@@ -65,8 +65,8 @@ class AnnotationMetadataReadingVisitorTests extends AbstractAnnotationMetadataTe
@Override
@Test
public
void
getAnnotationsReturnsDirectAnnotations
()
{
assertThatExceptionOfType
(
UnsupportedOperationException
.
class
)
.
isThrownBy
(
super
::
getAnnotationsReturnsDirectAnnotations
);
assertThatExceptionOfType
(
UnsupportedOperationException
.
class
)
.
isThrownBy
(
super
::
getAnnotationsReturnsDirectAnnotations
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录