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
pull/9539/head
Stephane Nicoll 8 years ago
parent 2e2fde0dcd
commit acda4f905f

@ -124,6 +124,9 @@ public class ConfigurationMetadata {
if (deprecation.getReplacement() != null) {
matchingDeprecation.setReplacement(deprecation.getReplacement());
}
if (deprecation.getLevel() != null) {
matchingDeprecation.setLevel(deprecation.getLevel());
}
}
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2017 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.
@ -28,12 +28,20 @@ public class ItemDeprecation {
private String replacement;
private String level;
public ItemDeprecation() {
this(null, null);
}
public ItemDeprecation(String reason, String replacement) {
this(reason, replacement, null);
}
public ItemDeprecation(String reason, String replacement, String level) {
this.reason = reason;
this.replacement = replacement;
this.level = level;
}
public String getReason() {
@ -52,10 +60,19 @@ public class ItemDeprecation {
this.replacement = replacement;
}
public String getLevel() {
return this.level;
}
public void setLevel(String level) {
this.level = level;
}
@Override
public String toString() {
return "ItemDeprecation{" + "reason='" + this.reason + '\'' + ", "
+ "replacement='" + this.replacement + '\'' + '}';
+ "replacement='" + this.replacement + '\'' + ", "
+ "level='" + this.level + '\'' + '}';
}
@Override
@ -68,13 +85,15 @@ public class ItemDeprecation {
}
ItemDeprecation other = (ItemDeprecation) o;
return nullSafeEquals(this.reason, other.reason)
&& nullSafeEquals(this.replacement, other.replacement);
&& nullSafeEquals(this.replacement, other.replacement)
&& nullSafeEquals(this.level, other.level);
}
@Override
public int hashCode() {
int result = nullSafeHashCode(this.reason);
result = 31 * result + nullSafeHashCode(this.replacement);
result = 31 * result + nullSafeHashCode(this.level);
return result;
}

@ -67,6 +67,9 @@ class JsonConverter {
if (deprecation != null) {
jsonObject.put("deprecated", true); // backward compatibility
JSONObject deprecationJsonObject = new JSONObject();
if (deprecation.getLevel() != null) {
deprecationJsonObject.put("level", deprecation.getLevel());
}
if (deprecation.getReason() != null) {
deprecationJsonObject.put("reason", deprecation.getReason());
}

@ -108,6 +108,7 @@ public class JsonMarshaller {
if (object.has("deprecation")) {
JSONObject deprecationJsonObject = object.getJSONObject("deprecation");
ItemDeprecation deprecation = new ItemDeprecation();
deprecation.setLevel(deprecationJsonObject.optString("level", null));
deprecation.setReason(deprecationJsonObject.optString("reason", null));
deprecation
.setReplacement(deprecationJsonObject.optString("replacement", null));

@ -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();

@ -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() {

Loading…
Cancel
Save