use of org.springframework.boot.configurationprocessor.metadata.ItemDeprecation in project spring-boot by spring-projects.
the class ConfigurationMetadataAnnotationProcessor method processSimpleLombokTypes.
private void processSimpleLombokTypes(String prefix, TypeElement element, ExecutableElement source, TypeElementMembers members, Map<String, Object> fieldValues) {
for (Map.Entry<String, VariableElement> entry : members.getFields().entrySet()) {
String name = entry.getKey();
VariableElement field = entry.getValue();
if (!isLombokField(field, element)) {
continue;
}
TypeMirror returnType = field.asType();
Element returnTypeElement = this.processingEnv.getTypeUtils().asElement(returnType);
boolean isExcluded = this.typeExcludeFilter.isExcluded(returnType);
boolean isNested = isNested(returnTypeElement, field, element);
boolean isCollection = this.typeUtils.isCollectionOrMap(returnType);
boolean hasSetter = hasLombokSetter(field, element);
if (!isExcluded && !isNested && (hasSetter || isCollection)) {
String dataType = this.typeUtils.getType(returnType);
String sourceType = this.typeUtils.getQualifiedName(element);
String description = this.typeUtils.getJavaDoc(field);
Object defaultValue = fieldValues.get(name);
boolean deprecated = isDeprecated(field) || isDeprecated(source);
this.metadataCollector.add(ItemMetadata.newProperty(prefix, name, dataType, sourceType, null, description, defaultValue, (deprecated ? new ItemDeprecation() : null)));
}
}
}
use of org.springframework.boot.configurationprocessor.metadata.ItemDeprecation in project spring-boot by spring-projects.
the class ConfigurationMetadataAnnotationProcessor method getItemDeprecation.
private ItemDeprecation getItemDeprecation(ExecutableElement getter) {
AnnotationMirror annotation = getAnnotation(getter, deprecatedConfigurationPropertyAnnotation());
String reason = null;
String replacement = null;
if (annotation != null) {
Map<String, Object> elementValues = getAnnotationElementValues(annotation);
reason = (String) elementValues.get("reason");
replacement = (String) elementValues.get("replacement");
}
return new ItemDeprecation(("".equals(reason) ? null : reason), ("".equals(replacement) ? null : replacement));
}
use of org.springframework.boot.configurationprocessor.metadata.ItemDeprecation in project spring-boot by spring-projects.
the class ConfigurationMetadataAnnotationProcessorTests method mergingOfAdditionalDeprecation.
@Test
public void mergingOfAdditionalDeprecation() throws Exception {
writePropertyDeprecation(ItemMetadata.newProperty("simple", "wrongName", "java.lang.String", null, null, null, null, new ItemDeprecation("Lame name.", "simple.the-name")));
ConfigurationMetadata metadata = compile(SimpleProperties.class);
assertThat(metadata).has(Metadata.withProperty("simple.wrong-name", String.class).withDeprecation("Lame name.", "simple.the-name"));
}
use of org.springframework.boot.configurationprocessor.metadata.ItemDeprecation 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.ItemDeprecation 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);
}
Aggregations