Consider @Deprecated on field when determining property's deprecation
Fixes gh-17550
This commit is contained in:
parent
4fd7b68f71
commit
edcaee375f
|
@ -277,7 +277,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
||||||
String sourceType = this.typeUtils.getQualifiedName(element);
|
String sourceType = this.typeUtils.getQualifiedName(element);
|
||||||
String description = this.typeUtils.getJavaDoc(field);
|
String description = this.typeUtils.getJavaDoc(field);
|
||||||
Object defaultValue = fieldValues.get(name);
|
Object defaultValue = fieldValues.get(name);
|
||||||
boolean deprecated = isDeprecated(getter) || isDeprecated(setter) || isDeprecated(source);
|
boolean deprecated = isDeprecated(getter) || isDeprecated(setter) || isDeprecated(field)
|
||||||
|
|| isDeprecated(source);
|
||||||
this.metadataCollector.add(ItemMetadata.newProperty(prefix, name, dataType, sourceType, null,
|
this.metadataCollector.add(ItemMetadata.newProperty(prefix, name, dataType, sourceType, null,
|
||||||
description, defaultValue, deprecated ? getItemDeprecation(getter) : null));
|
description, defaultValue, deprecated ? getItemDeprecation(getter) : null));
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ import org.springframework.boot.configurationsample.method.InvalidMethodConfig;
|
||||||
import org.springframework.boot.configurationsample.method.MethodAndClassConfig;
|
import org.springframework.boot.configurationsample.method.MethodAndClassConfig;
|
||||||
import org.springframework.boot.configurationsample.method.SimpleMethodConfig;
|
import org.springframework.boot.configurationsample.method.SimpleMethodConfig;
|
||||||
import org.springframework.boot.configurationsample.simple.ClassWithNestedProperties;
|
import org.springframework.boot.configurationsample.simple.ClassWithNestedProperties;
|
||||||
|
import org.springframework.boot.configurationsample.simple.DeprecatedFieldSingleProperty;
|
||||||
import org.springframework.boot.configurationsample.simple.DeprecatedSingleProperty;
|
import org.springframework.boot.configurationsample.simple.DeprecatedSingleProperty;
|
||||||
import org.springframework.boot.configurationsample.simple.DescriptionProperties;
|
import org.springframework.boot.configurationsample.simple.DescriptionProperties;
|
||||||
import org.springframework.boot.configurationsample.simple.HierarchicalProperties;
|
import org.springframework.boot.configurationsample.simple.HierarchicalProperties;
|
||||||
|
@ -224,6 +225,15 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||||
.withDeprecation("renamed", "singledeprecated.new-name"));
|
.withDeprecation("renamed", "singledeprecated.new-name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void singleDeprecatedFieldProperty() {
|
||||||
|
Class<?> type = DeprecatedFieldSingleProperty.class;
|
||||||
|
ConfigurationMetadata metadata = compile(type);
|
||||||
|
assertThat(metadata).has(Metadata.withGroup("singlefielddeprecated").fromSource(type));
|
||||||
|
assertThat(metadata).has(Metadata.withProperty("singlefielddeprecated.name", String.class).fromSource(type)
|
||||||
|
.withDeprecation(null, null));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deprecatedOnUnrelatedSetter() {
|
public void deprecatedOnUnrelatedSetter() {
|
||||||
Class<?> type = DeprecatedUnrelatedMethodPojo.class;
|
Class<?> type = DeprecatedUnrelatedMethodPojo.class;
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.boot.configurationsample.simple;
|
||||||
|
|
||||||
|
import org.springframework.boot.configurationsample.ConfigurationProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration properties with a single deprecated element.
|
||||||
|
*
|
||||||
|
* @author Andy Wilkinson
|
||||||
|
*/
|
||||||
|
@ConfigurationProperties("singlefielddeprecated")
|
||||||
|
public class DeprecatedFieldSingleProperty {
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue