Properly handle class reference

Previously, a condition on a class targeting an inner class would
generate an invalid String representation of it. Unfortunately, the
`toString` representation misses the `$` sign between the outer class
and the inner class name.

This commit post-processes the values to generate the appropriate
representation.

Closes gh-11282
pull/11378/head
Stephane Nicoll 7 years ago
parent 654fe9a31c
commit 846e642631

@ -166,17 +166,24 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
Object value = entry.getValue().getValue(); Object value = entry.getValue().getValue();
if (value instanceof List) { if (value instanceof List) {
for (AnnotationValue annotationValue : (List<AnnotationValue>) value) { for (AnnotationValue annotationValue : (List<AnnotationValue>) value) {
result.add(annotationValue.getValue()); result.add(processValue(annotationValue.getValue()));
} }
} }
else { else {
result.add(value); result.add(processValue(value));
} }
} }
} }
return result; return result;
} }
private Object processValue(Object value) {
if (value instanceof DeclaredType) {
return getQualifiedName(((DeclaredType) value).asElement());
}
return value;
}
private String getQualifiedName(Element element) { private String getQualifiedName(Element element) {
if (element != null) { if (element != null) {
TypeElement enclosingElement = getEnclosingTypeElement(element.asType()); TypeElement enclosingElement = getEnclosingTypeElement(element.asType());

@ -54,12 +54,12 @@ public class AutoConfigureAnnotationProcessorTests {
@Test @Test
public void annotatedClass() throws Exception { public void annotatedClass() throws Exception {
Properties properties = compile(TestClassConfiguration.class); Properties properties = compile(TestClassConfiguration.class);
System.out.println(properties);
assertThat(properties).hasSize(3); assertThat(properties).hasSize(3);
assertThat(properties).containsEntry( assertThat(properties).containsEntry(
"org.springframework.boot.autoconfigureprocessor." "org.springframework.boot.autoconfigureprocessor."
+ "TestClassConfiguration.ConditionalOnClass", + "TestClassConfiguration.ConditionalOnClass",
"java.io.InputStream,java.io.OutputStream"); "java.io.InputStream,org.springframework.boot.autoconfigureprocessor."
+ "TestClassConfiguration$Nested");
assertThat(properties).containsKey( assertThat(properties).containsKey(
"org.springframework.boot.autoconfigureprocessor.TestClassConfiguration"); "org.springframework.boot.autoconfigureprocessor.TestClassConfiguration");
assertThat(properties).containsKey( assertThat(properties).containsKey(

@ -16,15 +16,13 @@
package org.springframework.boot.autoconfigureprocessor; package org.springframework.boot.autoconfigureprocessor;
import java.io.OutputStream;
/** /**
* Test configuration with an annotated class. * Test configuration with an annotated class.
* *
* @author Madhura Bhave * @author Madhura Bhave
*/ */
@TestConfiguration @TestConfiguration
@TestConditionalOnClass(name = "java.io.InputStream", value = OutputStream.class) @TestConditionalOnClass(name = "java.io.InputStream", value = TestClassConfiguration.Nested.class)
public class TestClassConfiguration { public class TestClassConfiguration {
@TestAutoConfigureOrder @TestAutoConfigureOrder

Loading…
Cancel
Save