Commit 32efff3f authored by Stephane Nicoll's avatar Stephane Nicoll

Avoid creating a nested group for an Enum

Previously, an Enum that is defined as an inner class of a
@ConfigurationProperties pojo was wrongly detected as an nested group.

This case is now handled explicitly and covered by a test.

Fixes gh-1971
parent 5f673c9e
...@@ -34,6 +34,7 @@ import javax.lang.model.SourceVersion; ...@@ -34,6 +34,7 @@ import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier; import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
...@@ -207,7 +208,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor ...@@ -207,7 +208,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
if (returnType != null && returnType instanceof TypeElement if (returnType != null && returnType instanceof TypeElement
&& annotation == null) { && annotation == null) {
TypeElement returns = (TypeElement) returnType; TypeElement returns = (TypeElement) returnType;
if (this.typeUtils.isEnclosedIn(returnType, element) || isNested) { if ((this.typeUtils.isEnclosedIn(returnType, element) && returnType.getKind() != ElementKind.ENUM)
|| isNested) {
String nestedPrefix = ConfigurationMetadata String nestedPrefix = ConfigurationMetadata
.nestedPrefix(prefix, name); .nestedPrefix(prefix, name);
this.metadata.add(ItemMetadata.newGroup(nestedPrefix, this.metadata.add(ItemMetadata.newGroup(nestedPrefix,
......
...@@ -243,6 +243,8 @@ public class ConfigurationMetadataAnnotationProcessorTests { ...@@ -243,6 +243,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
assertThat(metadata, containsGroup("config.third").ofType(SimplePojo.class) assertThat(metadata, containsGroup("config.third").ofType(SimplePojo.class)
.fromSource(InnerClassProperties.class)); .fromSource(InnerClassProperties.class));
assertThat(metadata, containsProperty("config.third.value")); assertThat(metadata, containsProperty("config.third.value"));
assertThat(metadata, containsProperty("config.fourth").ofType(InnerClassProperties.Fourth.class));
assertThat(metadata, not(containsGroup("config.fourth")));
} }
@Test @Test
......
...@@ -34,6 +34,8 @@ public class InnerClassProperties { ...@@ -34,6 +34,8 @@ public class InnerClassProperties {
@NestedConfigurationProperty @NestedConfigurationProperty
private final SimplePojo third = new SimplePojo(); private final SimplePojo third = new SimplePojo();
private Fourth fourth;
public Foo getFirst() { public Foo getFirst() {
return this.first; return this.first;
} }
...@@ -50,6 +52,14 @@ public class InnerClassProperties { ...@@ -50,6 +52,14 @@ public class InnerClassProperties {
return this.third; return this.third;
} }
public Fourth getFourth() {
return fourth;
}
public void setFourth(Fourth fourth) {
this.fourth = fourth;
}
public static class Foo { public static class Foo {
private String name; private String name;
...@@ -83,4 +93,9 @@ public class InnerClassProperties { ...@@ -83,4 +93,9 @@ public class InnerClassProperties {
} }
public static enum Fourth {
YES,
NO
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment