From 846e642631aeac6acf62fc84c6d78f5b98eee200 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 7 Dec 2017 09:35:13 -0800 Subject: [PATCH] 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 --- .../AutoConfigureAnnotationProcessor.java | 11 +++++++++-- .../AutoConfigureAnnotationProcessorTests.java | 4 ++-- .../TestClassConfiguration.java | 4 +--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java b/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java index 87f650496e..134d6c04e8 100644 --- a/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java @@ -166,17 +166,24 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor { Object value = entry.getValue().getValue(); if (value instanceof List) { for (AnnotationValue annotationValue : (List) value) { - result.add(annotationValue.getValue()); + result.add(processValue(annotationValue.getValue())); } } else { - result.add(value); + result.add(processValue(value)); } } } return result; } + private Object processValue(Object value) { + if (value instanceof DeclaredType) { + return getQualifiedName(((DeclaredType) value).asElement()); + } + return value; + } + private String getQualifiedName(Element element) { if (element != null) { TypeElement enclosingElement = getEnclosingTypeElement(element.asType()); diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessorTests.java b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessorTests.java index 7336153480..e69cdedf42 100644 --- a/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessorTests.java +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessorTests.java @@ -54,12 +54,12 @@ public class AutoConfigureAnnotationProcessorTests { @Test public void annotatedClass() throws Exception { Properties properties = compile(TestClassConfiguration.class); - System.out.println(properties); assertThat(properties).hasSize(3); assertThat(properties).containsEntry( "org.springframework.boot.autoconfigureprocessor." + "TestClassConfiguration.ConditionalOnClass", - "java.io.InputStream,java.io.OutputStream"); + "java.io.InputStream,org.springframework.boot.autoconfigureprocessor." + + "TestClassConfiguration$Nested"); assertThat(properties).containsKey( "org.springframework.boot.autoconfigureprocessor.TestClassConfiguration"); assertThat(properties).containsKey( diff --git a/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestClassConfiguration.java b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestClassConfiguration.java index 7ca07f4323..3bc346b1ec 100644 --- a/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestClassConfiguration.java +++ b/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestClassConfiguration.java @@ -16,15 +16,13 @@ package org.springframework.boot.autoconfigureprocessor; -import java.io.OutputStream; - /** * Test configuration with an annotated class. * * @author Madhura Bhave */ @TestConfiguration -@TestConditionalOnClass(name = "java.io.InputStream", value = OutputStream.class) +@TestConditionalOnClass(name = "java.io.InputStream", value = TestClassConfiguration.Nested.class) public class TestClassConfiguration { @TestAutoConfigureOrder