Search in sources :

Example 11 with MetadataReader

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

the class AnnotationMetadataTests method asmAnnotationMetadata.

@Test
public void asmAnnotationMetadata() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(AnnotatedComponent.class.getName());
    AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
    doTestAnnotationInfo(metadata);
    doTestMethodAnnotationInfo(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 12 with MetadataReader

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

the class AnnotationMetadataTests method asmAnnotationMetadataForInterface.

@Test
public void asmAnnotationMetadataForInterface() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(AnnotationMetadata.class.getName());
    AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
    doTestMetadataForInterfaceClass(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 13 with MetadataReader

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

the class AnnotationTypeFilterTests method testInheritedAnnotationFromInterfaceDoesNotMatch.

@Test
public void testInheritedAnnotationFromInterfaceDoesNotMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeSubClassOfSomeComponentInterface";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
    AnnotationTypeFilter filter = new AnnotationTypeFilter(InheritedAnnotation.class);
    // Must fail as annotation on interfaces should not be considered a match
    assertFalse(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
Also used : AnnotationTypeFilter(org.springframework.core.type.filter.AnnotationTypeFilter) 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 14 with MetadataReader

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

the class AnnotationTypeFilterTests method testInheritedAnnotationFromBaseClassDoesMatch.

@Test
public void testInheritedAnnotationFromBaseClassDoesMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeSubClassOfSomeComponent";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
    AnnotationTypeFilter filter = new AnnotationTypeFilter(InheritedAnnotation.class);
    assertTrue(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
Also used : AnnotationTypeFilter(org.springframework.core.type.filter.AnnotationTypeFilter) 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 15 with MetadataReader

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

the class AnnotationTypeFilterTests method testNonAnnotatedClassDoesntMatch.

@Test
public void testNonAnnotatedClassDoesntMatch() throws Exception {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeNonCandidateClass";
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
    AnnotationTypeFilter filter = new AnnotationTypeFilter(Component.class);
    assertFalse(filter.match(metadataReader, metadataReaderFactory));
    ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
Also used : AnnotationTypeFilter(org.springframework.core.type.filter.AnnotationTypeFilter) 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)37 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)27 SimpleMetadataReaderFactory (org.springframework.core.type.classreading.SimpleMetadataReaderFactory)24 Test (org.junit.Test)23 IOException (java.io.IOException)7 Resource (org.springframework.core.io.Resource)7 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)7 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)4 AnnotationMetadata (org.springframework.core.type.AnnotationMetadata)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 AspectJTypeFilter (org.springframework.core.type.filter.AspectJTypeFilter)2 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1