Fix regression for nested AnnotationAttributes.annotationType() result

See gh-22738
This commit is contained in:
Juergen Hoeller
2019-04-09 09:40:53 +02:00
parent 0a03d8e248
commit dc14ea86eb
2 changed files with 47 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2019 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.
@@ -20,6 +20,7 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Arrays;
import org.junit.Test;
@@ -81,7 +82,7 @@ public class ImportAwareTests {
}
@Test
public void importRegistrar() throws Exception {
public void importRegistrar() {
ImportedRegistrar.called = false;
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ImportingRegistrarConfig.class);
@@ -91,7 +92,7 @@ public class ImportAwareTests {
}
@Test
public void importRegistrarWithImport() throws Exception {
public void importRegistrarWithImport() {
ImportedRegistrar.called = false;
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ImportingRegistrarConfigWithImport.class);
@@ -120,6 +121,11 @@ public class ImportAwareTests {
((StandardAnnotationMetadata) importMetadata).getIntrospectedClass());
}
@Test
public void importAwareWithAnnotationAttributes() {
new AnnotationConfigApplicationContext(ApplicationConfiguration.class);
}
@Configuration
@Import(ImportedConfig.class)
@@ -290,4 +296,41 @@ public class ImportAwareTests {
}
}
@Configuration
@EnableFeature(policies = {
@EnableFeature.FeaturePolicy(name = "one"),
@EnableFeature.FeaturePolicy(name = "two")
})
public static class ApplicationConfiguration {
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import(FeatureConfiguration.class)
public @interface EnableFeature {
FeaturePolicy[] policies() default {};
@interface FeaturePolicy {
String name();
}
}
@Configuration
public static class FeatureConfiguration implements ImportAware {
@Override
public void setImportMetadata(AnnotationMetadata annotationMetadata) {
AnnotationAttributes enableFeatureAttributes =
AnnotationAttributes.fromMap(annotationMetadata.getAnnotationAttributes(EnableFeature.class.getName()));
assertEquals(EnableFeature.class, enableFeatureAttributes.annotationType());
Arrays.stream(enableFeatureAttributes.getAnnotationArray("policies")).forEach(featurePolicyAttributes ->
assertEquals(EnableFeature.FeaturePolicy.class, featurePolicyAttributes.annotationType()));
}
}
}

View File

@@ -168,7 +168,7 @@ abstract class AbstractMergedAnnotation<A extends Annotation> implements MergedA
@Override
public AnnotationAttributes asAnnotationAttributes(Adapt... adaptations) {
return asMap(mergedAnnotation -> new AnnotationAttributes(getType()), adaptations);
return asMap(mergedAnnotation -> new AnnotationAttributes(mergedAnnotation.getType()), adaptations);
}
@Override