Skip to content

Commit d6d169a

Browse files
committed
resolved package dependency tangles
1 parent 686ae8f commit d6d169a

File tree

5 files changed

+57
-78
lines changed

5 files changed

+57
-78
lines changed

org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package org.springframework.context.annotation;
1818

19-
import static org.springframework.context.annotation.ConfigurationClassUtils.isConfigurationCandidate;
20-
2119
import java.io.IOException;
20+
import java.lang.annotation.Annotation;
21+
import java.util.ArrayList;
2222
import java.util.Collections;
2323
import java.util.Comparator;
2424
import java.util.HashMap;
@@ -35,11 +35,10 @@
3535
import org.springframework.beans.factory.parsing.Problem;
3636
import org.springframework.beans.factory.parsing.ProblemReporter;
3737
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
38-
import org.springframework.core.annotation.AnnotationUtils;
3938
import org.springframework.core.env.Environment;
4039
import org.springframework.core.env.PropertySource;
4140
import org.springframework.core.io.ResourceLoader;
42-
import org.springframework.core.io.ResourcePropertySource;
41+
import org.springframework.core.io.support.ResourcePropertySource;
4342
import org.springframework.core.type.AnnotationMetadata;
4443
import org.springframework.core.type.MethodMetadata;
4544
import org.springframework.core.type.StandardAnnotationMetadata;
@@ -167,7 +166,7 @@ protected void doProcessConfigurationClass(ConfigurationClass configClass, Annot
167166
for (String memberClassName : metadata.getMemberClassNames()) {
168167
MetadataReader reader = this.metadataReaderFactory.getMetadataReader(memberClassName);
169168
AnnotationMetadata memberClassMetadata = reader.getAnnotationMetadata();
170-
if (isConfigurationCandidate(memberClassMetadata)) {
169+
if (ConfigurationClassUtils.isConfigurationCandidate(memberClassMetadata)) {
171170
processConfigurationClass(new ConfigurationClass(reader, null));
172171
}
173172
}
@@ -204,7 +203,7 @@ protected void doProcessConfigurationClass(ConfigurationClass configClass, Annot
204203

205204
// process any @Import annotations
206205
List<Map<String, Object>> allImportAttribs =
207-
AnnotationUtils.findAllAnnotationAttributes(Import.class, metadata.getClassName(), true, metadataReaderFactory);
206+
findAllAnnotationAttributes(Import.class, metadata.getClassName(), true);
208207
for (Map<String, Object> importAttribs : allImportAttribs) {
209208
processImport(configClass, (String[]) importAttribs.get("value"), true);
210209
}
@@ -229,6 +228,48 @@ protected void doProcessConfigurationClass(ConfigurationClass configClass, Annot
229228
}
230229
}
231230

231+
232+
/**
233+
* Return a list of attribute maps for all declarations of the given annotation
234+
* on the given annotated class using the given MetadataReaderFactory to introspect
235+
* annotation metadata. Meta-annotations are ordered first in the list, and if the
236+
* target annotation is declared directly on the class, its map of attributes will be
237+
* ordered last in the list.
238+
* @param targetAnnotation the annotation to search for, both locally and as a meta-annotation
239+
* @param annotatedClassName the class to inspect
240+
* @param classValuesAsString whether class attributes should be returned as strings
241+
*/
242+
private List<Map<String, Object>> findAllAnnotationAttributes(
243+
Class<? extends Annotation> targetAnnotation, String annotatedClassName,
244+
boolean classValuesAsString) throws IOException {
245+
246+
List<Map<String, Object>> allAttribs = new ArrayList<Map<String, Object>>();
247+
248+
MetadataReader reader = this.metadataReaderFactory.getMetadataReader(annotatedClassName);
249+
AnnotationMetadata metadata = reader.getAnnotationMetadata();
250+
String targetAnnotationType = targetAnnotation.getName();
251+
252+
for (String annotationType : metadata.getAnnotationTypes()) {
253+
if (annotationType.equals(targetAnnotationType)) {
254+
continue;
255+
}
256+
MetadataReader metaReader = this.metadataReaderFactory.getMetadataReader(annotationType);
257+
Map<String, Object> targetAttribs =
258+
metaReader.getAnnotationMetadata().getAnnotationAttributes(targetAnnotationType, classValuesAsString);
259+
if (targetAttribs != null) {
260+
allAttribs.add(targetAttribs);
261+
}
262+
}
263+
264+
Map<String, Object> localAttribs =
265+
metadata.getAnnotationAttributes(targetAnnotationType, classValuesAsString);
266+
if (localAttribs != null) {
267+
allAttribs.add(localAttribs);
268+
}
269+
270+
return allAttribs;
271+
}
272+
232273
private void processImport(ConfigurationClass configClass, String[] classesToImport, boolean checkForCircularImports) throws IOException {
233274
if (checkForCircularImports && this.importStack.contains(configClass)) {
234275
this.problemReporter.error(new CircularImportProblem(configClass, this.importStack, configClass.getMetadata()));

org.springframework.core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
import java.util.WeakHashMap;
2929

3030
import org.springframework.core.BridgeMethodResolver;
31-
import org.springframework.core.type.AnnotationMetadata;
32-
import org.springframework.core.type.classreading.MetadataReader;
33-
import org.springframework.core.type.classreading.MetadataReaderFactory;
34-
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
3531
import org.springframework.util.Assert;
3632

3733
/**
@@ -354,49 +350,6 @@ else if (value instanceof Class[]) {
354350
return attrs;
355351
}
356352

357-
/**
358-
* Return a list of attribute maps for all declarations of the given annotation
359-
* on the given annotated class using the given MetadataReaderFactory to introspect
360-
* annotation metadata. Meta-annotations are ordered first in the list, and if the
361-
* target annotation is declared directly on the class, its map of attributes will be
362-
* ordered last in the list.
363-
* @param targetAnnotation the annotation to search for, both locally and as a meta-annotation
364-
* @param annotatedClassName the class to inspect
365-
* @param classValuesAsString whether class attributes should be returned as strings
366-
* @param metadataReaderFactory factory used to create metadata readers for each type
367-
* @since 3.1
368-
*/
369-
public static List<Map<String, Object>> findAllAnnotationAttributes(
370-
Class<? extends Annotation> targetAnnotation, String annotatedClassName,
371-
boolean classValuesAsString, MetadataReaderFactory metadataReaderFactory) throws IOException {
372-
373-
List<Map<String, Object>> allAttribs = new ArrayList<Map<String, Object>>();
374-
375-
MetadataReader reader = metadataReaderFactory.getMetadataReader(annotatedClassName);
376-
AnnotationMetadata metadata = reader.getAnnotationMetadata();
377-
String targetAnnotationType = targetAnnotation.getName();
378-
379-
for (String annotationType : metadata.getAnnotationTypes()) {
380-
if (annotationType.equals(targetAnnotationType)) {
381-
continue;
382-
}
383-
MetadataReader metaReader = metadataReaderFactory.getMetadataReader(annotationType);
384-
Map<String, Object> targetAttribs =
385-
metaReader.getAnnotationMetadata().getAnnotationAttributes(targetAnnotationType, classValuesAsString);
386-
if (targetAttribs != null) {
387-
allAttribs.add(targetAttribs);
388-
}
389-
}
390-
391-
Map<String, Object> localAttribs =
392-
metadata.getAnnotationAttributes(targetAnnotationType, classValuesAsString);
393-
if (localAttribs != null) {
394-
allAttribs.add(localAttribs);
395-
}
396-
397-
return allAttribs;
398-
}
399-
400353
/**
401354
* Retrieve the <em>value</em> of the <code>&quot;value&quot;</code> attribute of a
402355
* single-element Annotation, given an annotation instance.

org.springframework.core/src/main/java/org/springframework/core/io/ResourcePropertySource.java renamed to org.springframework.core/src/main/java/org/springframework/core/io/support/ResourcePropertySource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.core.io;
17+
package org.springframework.core.io.support;
1818

1919
import java.io.IOException;
2020
import java.io.InputStream;
2121
import java.util.Properties;
2222

2323
import org.springframework.core.env.PropertiesPropertySource;
24-
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
24+
import org.springframework.core.io.Resource;
2525
import org.springframework.util.ClassUtils;
2626
import org.springframework.util.StringUtils;
2727

2828
/**
2929
* Subclass of {@link PropertiesPropertySource} that loads a {@link Properties}
30-
* object from a given {@link Resource} or resource location such as
30+
* object from a given {@link org.springframework.core.io.Resource} or resource location such as
3131
* {@code "classpath:/com/myco/foo.properties"} or {@code "file:/path/to/file.properties"}.
3232
*
3333
* @author Chris Beams

org.springframework.core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,6 @@ public void testFindAnnotationFromInterfaceOnSuper() throws Exception {
219219
assertNotNull(order);
220220
}
221221

222-
@Test
223-
public void findAllComponentAnnotationAttributes() throws IOException {
224-
List<Map<String,Object>> allAttribs =
225-
AnnotationUtils.findAllAnnotationAttributes(Component.class,
226-
HasLocalAndMetaComponentAnnotation.class.getName(), false,
227-
new SimpleMetadataReaderFactory());
228-
229-
Object value = null;
230-
for (Map<String, Object> attribs : allAttribs) {
231-
value = attribs.get("value");
232-
}
233-
234-
assertThat(allAttribs.size(), is(3));
235-
assertEquals("local", value);
236-
}
237222

238223
@Component(value="meta1")
239224
@Retention(RetentionPolicy.RUNTIME)

org.springframework.core/src/test/java/org/springframework/core/io/ResourcePropertySourceTests.java renamed to org.springframework.core/src/test/java/org/springframework/core/io/support/ResourcePropertySourceTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.core.io;
18-
19-
import static org.hamcrest.CoreMatchers.is;
20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertThat;
22-
import static org.junit.Assert.assertTrue;
17+
package org.springframework.core.io.support;
2318

2419
import java.io.IOException;
2520

26-
import org.easymock.internal.matchers.StartsWith;
2721
import org.junit.Test;
22+
2823
import org.springframework.core.env.PropertySource;
24+
import org.springframework.core.io.ByteArrayResource;
25+
import org.springframework.core.io.ClassPathResource;
26+
27+
import static org.hamcrest.CoreMatchers.*;
28+
import static org.junit.Assert.*;
2929

3030
/**
3131
* Unit tests for {@link ResourcePropertySource}.

0 commit comments

Comments
 (0)