Polish contribution

Closes gh-7491
pull/7902/head
Stephane Nicoll 8 years ago
parent b3220985bb
commit f84fd19eaa

@ -191,7 +191,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
private void processTypeElement(String prefix, TypeElement element,
ExecutableElement source) {
TypeElementMembers members = new TypeElementMembers(this.processingEnv, this.fieldValuesParser, element);
TypeElementMembers members = new TypeElementMembers(this.processingEnv,
this.fieldValuesParser, element);
Map<String, Object> fieldValues = members.getFieldValues();
processSimpleTypes(prefix, element, source, members, fieldValues);
processSimpleLombokTypes(prefix, element, source, members, fieldValues);

@ -31,7 +31,6 @@ import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementFilter;
import javax.tools.Diagnostic;
import org.springframework.boot.configurationprocessor.fieldvalues.FieldValuesParser;
@ -65,7 +64,6 @@ class TypeElementMembers {
this.typeUtils = new TypeUtils(this.env);
this.fieldValuesParser = fieldValuesParser;
process(element);
processFieldValues(element);
}
private void process(TypeElement element) {
@ -77,6 +75,19 @@ class TypeElementMembers {
.fieldsIn(element.getEnclosedElements())) {
processField(field);
}
try {
Map<String, Object> fieldValues = this.fieldValuesParser
.getFieldValues(element);
for (Map.Entry<String, Object> entry : fieldValues.entrySet()) {
if (!this.fieldValues.containsKey(entry.getKey())) {
this.fieldValues.put(entry.getKey(), entry.getValue());
}
}
}
catch (Exception ex) {
// continue
}
Element superType = this.env.getTypeUtils().asElement(element.getSuperclass());
if (superType != null && superType instanceof TypeElement
&& !OBJECT_CLASS_NAME.equals(superType.toString())) {
@ -174,24 +185,6 @@ class TypeElementMembers {
return null;
}
private void processFieldValues(TypeElement element) {
try {
this.fieldValues.putAll(this.fieldValuesParser.getFieldValues(element));
}
catch (Exception ex) {
logWarning("Could not get values for type :" + element.getSimpleName().toString());
}
Element superType = this.env.getTypeUtils().asElement(element.getSuperclass());
if (superType != null && superType instanceof TypeElement && !Object.class.getName().equals(superType.toString())) {
processFieldValues((TypeElement) superType);
}
}
private void logWarning(String message) {
this.env.getMessager().printMessage(Diagnostic.Kind.WARNING, message);
}
public Map<String, Object> getFieldValues() {
return Collections.unmodifiableMap(this.fieldValues);
}

@ -352,6 +352,17 @@ public class ConfigurationMetadataAnnotationProcessorTests {
assertThat(metadata).isNotEqualTo(Metadata.withProperty("specific.foo"));
}
@Test
public void nestedClassChildProperties() throws Exception {
ConfigurationMetadata metadata = compile(ClassWithNestedProperties.class);
assertThat(metadata).has(Metadata.withGroup("nestedChildProps")
.fromSource(ClassWithNestedProperties.NestedChildClass.class));
assertThat(metadata).has(Metadata.withProperty("nestedChildProps.child-class-property", Integer.class)
.fromSource(ClassWithNestedProperties.NestedChildClass.class).withDefaultValue(20));
assertThat(metadata).has(Metadata.withProperty("nestedChildProps.parent-class-property", Integer.class)
.fromSource(ClassWithNestedProperties.NestedChildClass.class).withDefaultValue(10));
}
@Test
public void builderPojo() throws IOException {
ConfigurationMetadata metadata = compile(BuilderPojo.class);
@ -768,17 +779,6 @@ public class ConfigurationMetadataAnnotationProcessorTests {
}
}
@Test
public void nestedClassChildProperties() throws Exception {
ConfigurationMetadata metadata = compile(ClassWithNestedProperties.class);
assertThat(metadata).has(Metadata.withGroup("nestedChildProps")
.fromSource(ClassWithNestedProperties.NestedChildClass.class));
assertThat(metadata).has(Metadata.withProperty("nestedChildProps.child-class-property", Integer.class)
.fromSource(ClassWithNestedProperties.NestedChildClass.class).withDefaultValue(20));
assertThat(metadata).has(Metadata.withProperty("nestedChildProps.parent-class-property", Integer.class)
.fromSource(ClassWithNestedProperties.NestedChildClass.class).withDefaultValue(10));
}
private static class AdditionalMetadata {
}

Loading…
Cancel
Save