Add @DeprecatedConfigurationProperties annotation
Add a new @DeprecatedConfigurationProperties annotation which can be used by the `ConfigurationMetadataAnnotationProcessor` to generating meta-data deprecated blocks. Fixes gh-3543
This commit is contained in:
@@ -69,6 +69,9 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
static final String NESTED_CONFIGURATION_PROPERTY_ANNOTATION = "org.springframework.boot."
|
||||
+ "context.properties.NestedConfigurationProperty";
|
||||
|
||||
static final String DEPRECATED_CONFIGURATION_PROPERTY_ANNOTATION = "org.springframework.boot."
|
||||
+ "context.properties.DeprecatedConfigurationProperty";
|
||||
|
||||
static final String LOMBOK_DATA_ANNOTATION = "lombok.Data";
|
||||
|
||||
static final String LOMBOK_GETTER_ANNOTATION = "lombok.Getter";
|
||||
@@ -93,6 +96,10 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
return NESTED_CONFIGURATION_PROPERTY_ANNOTATION;
|
||||
}
|
||||
|
||||
protected String deprecatedConfigurationPropertyAnnotation() {
|
||||
return DEPRECATED_CONFIGURATION_PROPERTY_ANNOTATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceVersion getSupportedSourceVersion() {
|
||||
return SourceVersion.latestSupported();
|
||||
@@ -207,16 +214,29 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
String sourceType = this.typeUtils.getType(element);
|
||||
String description = this.typeUtils.getJavaDoc(field);
|
||||
Object defaultValue = fieldValues.get(name);
|
||||
boolean deprecated = hasDeprecateAnnotation(getter)
|
||||
|| hasDeprecateAnnotation(setter)
|
||||
|| hasDeprecateAnnotation(element);
|
||||
boolean deprecated = isDeprecated(getter) || isDeprecated(setter)
|
||||
|| isDeprecated(element);
|
||||
this.metadataCollector.add(ItemMetadata.newProperty(prefix, name,
|
||||
dataType, sourceType, null, description, defaultValue,
|
||||
(deprecated ? new ItemDeprecation() : null)));
|
||||
(deprecated ? getItemDeprecation(getter) : null)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
private void processLombokTypes(String prefix, TypeElement element,
|
||||
TypeElementMembers members, Map<String, Object> fieldValues) {
|
||||
for (Map.Entry<String, VariableElement> entry : members.getFields().entrySet()) {
|
||||
@@ -237,8 +257,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
String sourceType = this.typeUtils.getType(element);
|
||||
String description = this.typeUtils.getJavaDoc(field);
|
||||
Object defaultValue = fieldValues.get(name);
|
||||
boolean deprecated = hasDeprecateAnnotation(field)
|
||||
|| hasDeprecateAnnotation(element);
|
||||
boolean deprecated = isDeprecated(field) || isDeprecated(element);
|
||||
this.metadataCollector.add(ItemMetadata.newProperty(prefix, name,
|
||||
dataType, sourceType, null, description, defaultValue,
|
||||
(deprecated ? new ItemDeprecation() : null)));
|
||||
@@ -291,8 +310,9 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||
&& returnType.getKind() != ElementKind.ENUM;
|
||||
}
|
||||
|
||||
private boolean hasDeprecateAnnotation(Element element) {
|
||||
return hasAnnotation(element, "java.lang.Deprecated");
|
||||
private boolean isDeprecated(Element element) {
|
||||
return hasAnnotation(element, "java.lang.Deprecated")
|
||||
|| hasAnnotation(element, deprecatedConfigurationPropertyAnnotation());
|
||||
}
|
||||
|
||||
private boolean hasAnnotation(Element element, String type) {
|
||||
|
||||
Reference in New Issue
Block a user