Add support for deprecation level

This commit ensures that deprecation level set in manual metadata is
properly merged in the generated one.

Closes gh-9449
This commit is contained in:
Stephane Nicoll
2017-06-14 09:28:59 +02:00
parent 2e2fde0dcd
commit acda4f905f
6 changed files with 52 additions and 6 deletions

View File

@@ -542,13 +542,15 @@ public class ConfigurationMetadataAnnotationProcessorTests {
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"));
new ItemDeprecation("Don't use this.", "simple.complex-comparator",
"error"));
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"));
.withDeprecation("Don't use this.", "simple.complex-comparator",
"error"));
assertThat(metadata.getItems()).hasSize(4);
}
@@ -566,6 +568,19 @@ public class ConfigurationMetadataAnnotationProcessorTests {
assertThat(metadata.getItems()).hasSize(3);
}
@Test
public void mergeExistingPropertyDeprecationOverrideLevel() throws Exception {
ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null,
null, null, null, null, new ItemDeprecation(null, null, "error"));
writeAdditionalMetadata(property);
ConfigurationMetadata metadata = compile(DeprecatedSingleProperty.class);
assertThat(metadata).has(
Metadata.withProperty("singledeprecated.name", String.class.getName())
.fromSource(DeprecatedSingleProperty.class)
.withDeprecation("renamed", "singledeprecated.new-name", "error"));
assertThat(metadata.getItems()).hasSize(3);
}
@Test
public void mergeOfInvalidAdditionalMetadata() throws IOException {
File additionalMetadataFile = createAdditionalMetadataFile();

View File

@@ -202,9 +202,14 @@ public final class Metadata {
}
public MetadataItemCondition withDeprecation(String reason, String replacement) {
return withDeprecation(reason, replacement, null);
}
public MetadataItemCondition withDeprecation(String reason, String replacement,
String level) {
return new MetadataItemCondition(this.itemType, this.name, this.type,
this.sourceType, this.sourceMethod, this.description,
this.defaultValue, new ItemDeprecation(reason, replacement));
this.defaultValue, new ItemDeprecation(reason, replacement, level));
}
public MetadataItemCondition withNoDeprecation() {