Also flag deprecated properties in a @Deprecated class

Previously, any property defined in a @Deprecated class were not marked
as deprecated as only the getter or field was inspected for the
annotation.

An additional check on the class has been added to handle this case.

Fixes gh-2014
This commit is contained in:
Stephane Nicoll 2014-11-27 15:27:12 +01:00
parent 1a5916665c
commit 5b231e600b
3 changed files with 69 additions and 1 deletions

View File

@ -186,7 +186,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
String description = this.typeUtils.getJavaDoc(field);
Object defaultValue = fieldValues.get(name);
boolean deprecated = hasDeprecateAnnotation(getter)
|| hasDeprecateAnnotation(setter);
|| hasDeprecateAnnotation(setter)
|| hasDeprecateAnnotation(element);
this.metadata.add(ItemMetadata.newProperty(prefix, name, dataType,
sourceType, null, description, defaultValue, deprecated));
}

View File

@ -30,6 +30,7 @@ import org.springframework.boot.configurationsample.method.EmptyTypeMethodConfig
import org.springframework.boot.configurationsample.method.InvalidMethodConfig;
import org.springframework.boot.configurationsample.method.MethodAndClassConfig;
import org.springframework.boot.configurationsample.method.SimpleMethodConfig;
import org.springframework.boot.configurationsample.simple.DeprecatedProperties;
import org.springframework.boot.configurationsample.simple.HierarchicalProperties;
import org.springframework.boot.configurationsample.simple.NotAnnotated;
import org.springframework.boot.configurationsample.simple.SimpleCollectionProperties;
@ -144,6 +145,22 @@ public class ConfigurationMetadataAnnotationProcessorTests {
.fromSource(HierarchicalProperties.class));
}
@Test
public void deprecatedProperties() throws Exception {
ConfigurationMetadata metadata = compile(DeprecatedProperties.class);
assertThat(metadata, containsGroup("deprecated").fromSource(DeprecatedProperties.class));
assertThat(
metadata,
containsProperty("deprecated.name", String.class)
.fromSource(DeprecatedProperties.class)
.withDeprecated());
assertThat(
metadata,
containsProperty("deprecated.description", String.class)
.fromSource(DeprecatedProperties.class)
.withDeprecated());
}
@Test
public void parseCollectionConfig() throws Exception {
ConfigurationMetadata metadata = compile(SimpleCollectionProperties.class);

View File

@ -0,0 +1,50 @@
/*
* Copyright 2012-2014 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
*
* http://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;
/**
* Deprecated configuration properties.
*
* @author Stephane Nicoll
*/
@Deprecated
@ConfigurationProperties(prefix = "deprecated")
public class DeprecatedProperties {
private String name;
private String description;
public String getName() {
Flf return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}