use of org.springframework.boot.configurationprocessor.metadata.ItemMetadata in project spring-boot by spring-projects.
the class ConfigurationMetadataAnnotationProcessorTests method mergeExistingPropertyDescription.
@Test
public void mergeExistingPropertyDescription() throws Exception {
ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null, null, null, "A nice comparator.", null, null);
writeAdditionalMetadata(property);
ConfigurationMetadata metadata = compile(SimpleProperties.class);
assertThat(metadata).has(Metadata.withProperty("simple.comparator", "java.util.Comparator<?>").fromSource(SimpleProperties.class).withDescription("A nice comparator."));
assertThat(metadata.getItems()).hasSize(4);
}
use of org.springframework.boot.configurationprocessor.metadata.ItemMetadata in project spring-boot by spring-projects.
the class ConfigurationMetadataAnnotationProcessorTests method writePropertyDeprecation.
private void writePropertyDeprecation(ItemMetadata... items) throws Exception {
File additionalMetadataFile = createAdditionalMetadataFile();
JSONArray propertiesArray = new JSONArray();
for (ItemMetadata item : items) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", item.getName());
if (item.getType() != null) {
jsonObject.put("type", item.getType());
}
ItemDeprecation deprecation = item.getDeprecation();
if (deprecation != null) {
JSONObject deprecationJson = new JSONObject();
if (deprecation.getReason() != null) {
deprecationJson.put("reason", deprecation.getReason());
}
if (deprecation.getReplacement() != null) {
deprecationJson.put("replacement", deprecation.getReplacement());
}
jsonObject.put("deprecation", deprecationJson);
}
propertiesArray.put(jsonObject);
}
JSONObject additionalMetadata = new JSONObject();
additionalMetadata.put("properties", propertiesArray);
writeMetadata(additionalMetadataFile, additionalMetadata);
}
use of org.springframework.boot.configurationprocessor.metadata.ItemMetadata in project spring-boot by spring-projects.
the class ConfigurationMetadataAnnotationProcessorTests method mergeExistingPropertyDeprecation.
@Test
public void mergeExistingPropertyDeprecation() throws Exception {
ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null, null, null, null, null, new ItemDeprecation("Don't use this.", "simple.complex-comparator"));
writeAdditionalMetadata(property);
ConfigurationMetadata metadata = compile(SimpleProperties.class);
assertThat(metadata).has(Metadata.withProperty("simple.comparator", "java.util.Comparator<?>").fromSource(SimpleProperties.class).withDeprecation("Don't use this.", "simple.complex-comparator"));
assertThat(metadata.getItems()).hasSize(4);
}
use of org.springframework.boot.configurationprocessor.metadata.ItemMetadata in project spring-boot by spring-projects.
the class ConfigurationMetadataAnnotationProcessorTests method mergeExistingPropertyDefaultValue.
@Test
public void mergeExistingPropertyDefaultValue() throws Exception {
ItemMetadata property = ItemMetadata.newProperty("simple", "flag", null, null, null, null, true, null);
writeAdditionalMetadata(property);
ConfigurationMetadata metadata = compile(SimpleProperties.class);
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class).fromSource(SimpleProperties.class).withDescription("A simple flag.").withDeprecation(null, null).withDefaultValue(true));
assertThat(metadata.getItems()).hasSize(4);
}
use of org.springframework.boot.configurationprocessor.metadata.ItemMetadata in project spring-boot by spring-projects.
the class ConfigurationMetadataAnnotationProcessor method processExecutableElement.
private void processExecutableElement(String prefix, ExecutableElement element) {
if (element.getModifiers().contains(Modifier.PUBLIC) && (TypeKind.VOID != element.getReturnType().getKind())) {
Element returns = this.processingEnv.getTypeUtils().asElement(element.getReturnType());
if (returns instanceof TypeElement) {
ItemMetadata group = ItemMetadata.newGroup(prefix, this.typeUtils.getQualifiedName(returns), this.typeUtils.getQualifiedName(element.getEnclosingElement()), element.toString());
if (this.metadataCollector.hasSimilarGroup(group)) {
this.processingEnv.getMessager().printMessage(Kind.ERROR, "Duplicate `@ConfigurationProperties` definition for prefix '" + prefix + "'", element);
} else {
this.metadataCollector.add(group);
processTypeElement(prefix, (TypeElement) returns, element);
}
}
}
}
Aggregations