Skip to content

Commit 73fadd8

Browse files
committed
Polishing
1 parent 127e879 commit 73fadd8

File tree

5 files changed

+23
-30
lines changed

5 files changed

+23
-30
lines changed

spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -57,6 +57,19 @@ public class CandidateComponentsIndex {
5757
this.index = parseIndex(content);
5858
}
5959

60+
private static MultiValueMap<String, Entry> parseIndex(List<Properties> content) {
61+
MultiValueMap<String, Entry> index = new LinkedMultiValueMap<>();
62+
for (Properties entry : content) {
63+
entry.forEach((type, values) -> {
64+
String[] stereotypes = ((String) values).split(",");
65+
for (String stereotype : stereotypes) {
66+
index.add(stereotype, new Entry((String) type));
67+
}
68+
});
69+
}
70+
return index;
71+
}
72+
6073

6174
/**
6275
* Return the candidate types that are associated with the specified stereotype.
@@ -76,21 +89,11 @@ public Set<String> getCandidateTypes(String basePackage, String stereotype) {
7689
return Collections.emptySet();
7790
}
7891

79-
private static MultiValueMap<String, Entry> parseIndex(List<Properties> content) {
80-
MultiValueMap<String, Entry> index = new LinkedMultiValueMap<>();
81-
for (Properties entry : content) {
82-
entry.forEach((type, values) -> {
83-
String[] stereotypes = ((String) values).split(",");
84-
for (String stereotype : stereotypes) {
85-
index.add(stereotype, new Entry((String) type));
86-
}
87-
});
88-
}
89-
return index;
90-
}
9192

9293
private static class Entry {
94+
9395
private final String type;
96+
9497
private final String packageName;
9598

9699
Entry(String type) {
@@ -106,7 +109,6 @@ public boolean match(String basePackage) {
106109
return this.type.startsWith(basePackage);
107110
}
108111
}
109-
110112
}
111113

112114
}

spring-context/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public void testWithComponentAnnotationOnly() {
300300
}
301301

302302
@Test
303-
public void testWithAspectAnnotationOnly() throws Exception {
303+
public void testWithAspectAnnotationOnly() {
304304
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
305305
provider.addIncludeFilter(new AnnotationTypeFilter(Aspect.class));
306306
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);

spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexLoaderTests.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727
import static org.assertj.core.api.Assertions.assertThat;
2828
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
2929

30-
31-
32-
33-
34-
3530
/**
3631
* Tests for {@link CandidateComponentsIndexLoader}.
3732
*
@@ -92,15 +87,15 @@ public void loadIndexNoSpringComponentsResource() {
9287
}
9388

9489
@Test
95-
public void loadIndexNoEntry() throws IOException {
90+
public void loadIndexNoEntry() {
9691
CandidateComponentsIndex index = CandidateComponentsIndexLoader.loadIndex(
9792
CandidateComponentsTestClassLoader.index(getClass().getClassLoader(),
9893
new ClassPathResource("empty-spring.components", getClass())));
9994
assertThat(index).isNull();
10095
}
10196

10297
@Test
103-
public void loadIndexWithException() throws IOException {
98+
public void loadIndexWithException() {
10499
final IOException cause = new IOException("test exception");
105100
assertThatIllegalStateException().isThrownBy(() -> {
106101
CandidateComponentsTestClassLoader classLoader = new CandidateComponentsTestClassLoader(getClass().getClassLoader(), cause);

spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexTests.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525

2626
import static org.assertj.core.api.Assertions.assertThat;
2727

28-
29-
30-
31-
3228
/**
3329
* Tests for {@link CandidateComponentsIndex}.
3430
*

spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadata.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -140,12 +140,12 @@ public Set<String> getAnnotationTypes() {
140140
@Override
141141
public Set<MethodMetadata> getAnnotatedMethods(String annotationName) {
142142
Set<MethodMetadata> annotatedMethods = null;
143-
for (int i = 0; i < this.annotatedMethods.length; i++) {
144-
if (this.annotatedMethods[i].isAnnotated(annotationName)) {
143+
for (MethodMetadata annotatedMethod : this.annotatedMethods) {
144+
if (annotatedMethod.isAnnotated(annotationName)) {
145145
if (annotatedMethods == null) {
146146
annotatedMethods = new LinkedHashSet<>(4);
147147
}
148-
annotatedMethods.add(this.annotatedMethods[i]);
148+
annotatedMethods.add(annotatedMethod);
149149
}
150150
}
151151
return annotatedMethods != null ? annotatedMethods : Collections.emptySet();

0 commit comments

Comments
 (0)