Search in sources :

Example 21 with MetadataReader

use of org.springframework.core.type.classreading.MetadataReader in project spring-boot by spring-projects.

the class AbstractConfigurationClassTests method findConfigurationClasses.

private Set<AnnotationMetadata> findConfigurationClasses() throws IOException {
    Set<AnnotationMetadata> configurationClasses = new HashSet<>();
    Resource[] resources = this.resolver.getResources("classpath*:" + getClass().getPackage().getName().replace('.', '/') + "/**/*.class");
    for (Resource resource : resources) {
        if (!isTestClass(resource)) {
            MetadataReader metadataReader = new SimpleMetadataReaderFactory().getMetadataReader(resource);
            AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
            if (annotationMetadata.getAnnotationTypes().contains(Configuration.class.getName())) {
                configurationClasses.add(annotationMetadata);
            }
        }
    }
    return configurationClasses;
}
Also used : SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) Configuration(org.springframework.context.annotation.Configuration) Resource(org.springframework.core.io.Resource) MetadataReader(org.springframework.core.type.classreading.MetadataReader) AnnotationMetadata(org.springframework.core.type.AnnotationMetadata) HashSet(java.util.HashSet)

Example 22 with MetadataReader

use of org.springframework.core.type.classreading.MetadataReader in project spring-framework by spring-projects.

the class AnnotationMetadataTests method multipleAnnotationsWithIdenticalAttributeNamesUsingAnnotationMetadataReadingVisitor.

/**
	 * https://jira.spring.io/browse/SPR-11649
	 */
@Test
public void multipleAnnotationsWithIdenticalAttributeNamesUsingAnnotationMetadataReadingVisitor() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(NamedAnnotationsClass.class.getName());
    AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
    assertMultipleAnnotationsWithIdenticalAttributeNames(metadata);
}
Also used : MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) MetadataReader(org.springframework.core.type.classreading.MetadataReader) Test(org.junit.Test)

Example 23 with MetadataReader

use of org.springframework.core.type.classreading.MetadataReader in project spring-framework by spring-projects.

the class AnnotationMetadataTests method composedAnnotationWithMetaAnnotationsWithIdenticalAttributeNamesUsingAnnotationMetadataReadingVisitor.

/**
	 * https://jira.spring.io/browse/SPR-11649
	 */
@Test
public void composedAnnotationWithMetaAnnotationsWithIdenticalAttributeNamesUsingAnnotationMetadataReadingVisitor() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(NamedComposedAnnotationClass.class.getName());
    AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
    assertMultipleAnnotationsWithIdenticalAttributeNames(metadata);
}
Also used : MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) MetadataReader(org.springframework.core.type.classreading.MetadataReader) Test(org.junit.Test)

Example 24 with MetadataReader

use of org.springframework.core.type.classreading.MetadataReader in project spring-framework by spring-projects.

the class AnnotationMetadataTests method asmAnnotationMetadataForAnnotation.

@Test
public void asmAnnotationMetadataForAnnotation() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(Component.class.getName());
    AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
    doTestMetadataForAnnotationClass(metadata);
}
Also used : MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) MetadataReader(org.springframework.core.type.classreading.MetadataReader) Component(org.springframework.stereotype.Component) Test(org.junit.Test)

Example 25 with MetadataReader

use of org.springframework.core.type.classreading.MetadataReader in project spring-framework by spring-projects.

the class AnnotationMetadataTests method metaAnnotationOverridesUsingAnnotationMetadataReadingVisitor.

@Test
public void metaAnnotationOverridesUsingAnnotationMetadataReadingVisitor() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(ComposedConfigurationWithAttributeOverridesClass.class.getName());
    AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
    assertMetaAnnotationOverrides(metadata);
}
Also used : MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) MetadataReader(org.springframework.core.type.classreading.MetadataReader) Test(org.junit.Test)

Aggregations

MetadataReader (org.springframework.core.type.classreading.MetadataReader)36 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)26 SimpleMetadataReaderFactory (org.springframework.core.type.classreading.SimpleMetadataReaderFactory)24 Test (org.junit.Test)23 IOException (java.io.IOException)7 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)7 Resource (org.springframework.core.io.Resource)6 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)5 AssignableTypeFilter (org.springframework.core.type.filter.AssignableTypeFilter)5 AnnotatedGenericBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)4 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)3 URL (java.net.URL)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)2 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)2 AnnotationMetadata (org.springframework.core.type.AnnotationMetadata)2 AspectJTypeFilter (org.springframework.core.type.filter.AspectJTypeFilter)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1