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
This commit is contained in:
@@ -34,6 +34,7 @@ import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.AnnotationValue;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
@@ -207,7 +208,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
if (returnType != null && returnType instanceof TypeElement
|
||||
&& annotation == null) {
|
||||
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
|
||||
.nestedPrefix(prefix, name);
|
||||
this.metadata.add(ItemMetadata.newGroup(nestedPrefix,
|
||||
|
||||
@@ -243,6 +243,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
assertThat(metadata, containsGroup("config.third").ofType(SimplePojo.class)
|
||||
.fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata, containsProperty("config.third.value"));
|
||||
assertThat(metadata, containsProperty("config.fourth").ofType(InnerClassProperties.Fourth.class));
|
||||
assertThat(metadata, not(containsGroup("config.fourth")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -34,6 +34,8 @@ public class InnerClassProperties {
|
||||
@NestedConfigurationProperty
|
||||
private final SimplePojo third = new SimplePojo();
|
||||
|
||||
private Fourth fourth;
|
||||
|
||||
public Foo getFirst() {
|
||||
return this.first;
|
||||
}
|
||||
@@ -50,6 +52,14 @@ public class InnerClassProperties {
|
||||
return this.third;
|
||||
}
|
||||
|
||||
public Fourth getFourth() {
|
||||
return fourth;
|
||||
}
|
||||
|
||||
public void setFourth(Fourth fourth) {
|
||||
this.fourth = fourth;
|
||||
}
|
||||
|
||||
public static class Foo {
|
||||
|
||||
private String name;
|
||||
@@ -83,4 +93,9 @@ public class InnerClassProperties {
|
||||
|
||||
}
|
||||
|
||||
public static enum Fourth {
|
||||
YES,
|
||||
NO
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user