Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Apr 27, 2020
1 parent 127e879 commit 73fadd8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -76,21 +89,11 @@ public Set<String> getCandidateTypes(String basePackage, String stereotype) {
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) {
Expand All @@ -106,7 +109,6 @@ public boolean match(String basePackage) {
return this.type.startsWith(basePackage);
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public void testWithComponentAnnotationOnly() {
}

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;






/**
* Tests for {@link CandidateComponentsIndexLoader}.
*
Expand Down Expand Up @@ -92,15 +87,15 @@ public void loadIndexNoSpringComponentsResource() {
}

@Test
public void loadIndexNoEntry() throws IOException {
public void loadIndexNoEntry() {
CandidateComponentsIndex index = CandidateComponentsIndexLoader.loadIndex(
CandidateComponentsTestClassLoader.index(getClass().getClassLoader(),
new ClassPathResource("empty-spring.components", getClass())));
assertThat(index).isNull();
}

@Test
public void loadIndexWithException() throws IOException {
public void loadIndexWithException() {
final IOException cause = new IOException("test exception");
assertThatIllegalStateException().isThrownBy(() -> {
CandidateComponentsTestClassLoader classLoader = new CandidateComponentsTestClassLoader(getClass().getClassLoader(), cause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@

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





/**
* Tests for {@link CandidateComponentsIndex}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -140,12 +140,12 @@ public Set<String> getAnnotationTypes() {
@Override
public Set<MethodMetadata> getAnnotatedMethods(String annotationName) {
Set<MethodMetadata> annotatedMethods = null;
for (int i = 0; i < this.annotatedMethods.length; i++) {
if (this.annotatedMethods[i].isAnnotated(annotationName)) {
for (MethodMetadata annotatedMethod : this.annotatedMethods) {
if (annotatedMethod.isAnnotated(annotationName)) {
if (annotatedMethods == null) {
annotatedMethods = new LinkedHashSet<>(4);
}
annotatedMethods.add(this.annotatedMethods[i]);
annotatedMethods.add(annotatedMethod);
}
}
return annotatedMethods != null ? annotatedMethods : Collections.emptySet();
Expand Down

0 comments on commit 73fadd8

Please sign in to comment.