Browse Source

Polishing

pull/25187/head
Juergen Hoeller 6 years ago
parent
commit
a4cc16051c
  1. 30
      spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java
  2. 2
      spring-context/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java
  3. 4
      spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexLoaderTests.java

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2020 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.
@ -57,6 +57,19 @@ public class CandidateComponentsIndex { @@ -57,6 +57,19 @@ public class CandidateComponentsIndex {
this.index = parseIndex(content);
}
private static MultiValueMap<String, Entry> parseIndex(List<Properties> content) {
MultiValueMap<String, Entry> index = new LinkedMultiValueMap<>();
for (Properties entry : content) {
entry.forEach((type, values) -> {
String[] stereotypes = ((String) values).split(",");
for (String stereotype : stereotypes) {
index.add(stereotype, new Entry((String) type));
}
});
}
return index;
}
/**
* Return the candidate types that are associated with the specified stereotype.
@ -76,21 +89,11 @@ public class CandidateComponentsIndex { @@ -76,21 +89,11 @@ public class CandidateComponentsIndex {
return Collections.emptySet();
}
private static MultiValueMap<String, Entry> parseIndex(List<Properties> content) {
MultiValueMap<String, Entry> index = new LinkedMultiValueMap<>();
for (Properties entry : content) {
entry.forEach((type, values) -> {
String[] stereotypes = ((String) values).split(",");
for (String stereotype : stereotypes) {
index.add(stereotype, new Entry((String) type));
}
});
}
return index;
}
private static class Entry {
private final String type;
private final String packageName;
Entry(String type) {
@ -106,7 +109,6 @@ public class CandidateComponentsIndex { @@ -106,7 +109,6 @@ public class CandidateComponentsIndex {
return this.type.startsWith(basePackage);
}
}
}
}

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

@ -301,7 +301,7 @@ public class ClassPathScanningCandidateComponentProviderTests { @@ -301,7 +301,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
}
@Test
public void testWithAspectAnnotationOnly() throws Exception {
public void testWithAspectAnnotationOnly() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AnnotationTypeFilter(Aspect.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);

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

@ -92,7 +92,7 @@ public class CandidateComponentsIndexLoaderTests { @@ -92,7 +92,7 @@ public class CandidateComponentsIndexLoaderTests {
}
@Test
public void loadIndexNoEntry() throws IOException {
public void loadIndexNoEntry() {
CandidateComponentsIndex index = CandidateComponentsIndexLoader.loadIndex(
CandidateComponentsTestClassLoader.index(getClass().getClassLoader(),
new ClassPathResource("empty-spring.components", getClass())));
@ -100,7 +100,7 @@ public class CandidateComponentsIndexLoaderTests { @@ -100,7 +100,7 @@ public class CandidateComponentsIndexLoaderTests {
}
@Test
public void loadIndexWithException() throws IOException {
public void loadIndexWithException() {
final IOException cause = new IOException("test exception");
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Unable to load indexes");

Loading…
Cancel
Save