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 processSimpleLombokTypes(String prefix, TypeElement element, TypeElementMembers members, Map<String, Object> fieldValues) { for (Map.Entry<String, VariableElement> entry : members.getFields().entrySet()) { String name = entry.getKey(); VariableElement field = entry.getValue(); if (!isLombokField(field, element)) { continue; } TypeMirror returnType = field.asType(); Element returnTypeElement = this.processingEnv.getTypeUtils() .asElement(returnType); boolean isExcluded = this.typeExcludeFilter.isExcluded(returnType); boolean isNested = isNested(returnTypeElement, field, element); boolean isCollection = this.typeUtils.isCollectionOrMap(returnType); boolean hasSetter = hasLombokSetter(field, element); if (!isExcluded && !isNested && (hasSetter || isCollection)) { String dataType = this.typeUtils.getType(returnType); String sourceType = this.typeUtils.getType(element); String description = this.typeUtils.getJavaDoc(field); Object defaultValue = fieldValues.get(name); boolean deprecated = isDeprecated(field) || isDeprecated(element); this.metadataCollector.add(ItemMetadata.newProperty(prefix, name, dataType, sourceType, null, description, defaultValue, (deprecated ? new ItemDeprecation() : null))); } } }
public MetadataItemCondition(ItemType itemType, String name, String type, Class<?> sourceType, String description, Object defaultValue, ItemDeprecation deprecation) { this.itemType = itemType; this.name = name; this.type = type; this.sourceType = sourceType; this.description = description; this.defaultValue = defaultValue; this.deprecation = deprecation; describedAs(createDescription()); }
@Test 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")); 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")); assertThat(metadata.getItems()).hasSize(4); }
@Test public void mergeExistingPropertyDeprecationOverride() throws Exception { ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null, null, null, null, null, new ItemDeprecation("Don't use this.", "single.name")); writeAdditionalMetadata(property); ConfigurationMetadata metadata = compile(DeprecatedSingleProperty.class); assertThat(metadata).has( Metadata.withProperty("singledeprecated.name", String.class.getName()) .fromSource(DeprecatedSingleProperty.class) .withDeprecation("Don't use this.", "single.name")); assertThat(metadata.getItems()).hasSize(3); }
@Test public void mergingOfAdditionalDeprecation() throws Exception { writePropertyDeprecation(ItemMetadata.newProperty("simple", "wrongName", "java.lang.String", null, null, null, null, new ItemDeprecation("Lame name.", "simple.the-name"))); ConfigurationMetadata metadata = compile(SimpleProperties.class); assertThat(metadata).has(Metadata.withProperty("simple.wrong-name", String.class) .withDeprecation("Lame name.", "simple.the-name")); }
private void writePropertyDeprecation(ItemMetadata... items) throws IOException { File additionalMetadataFile = createAdditionalMetadataFile(); JSONArray propertiesArray = new JSONArray(); for (ItemMetadata item : items) { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", item.getName()); if (item.getType() != null) { jsonObject.put("type", item.getType()); } ItemDeprecation deprecation = item.getDeprecation(); if (deprecation != null) { JSONObject deprecationJson = new JSONObject(); if (deprecation.getReason() != null) { deprecationJson.put("reason", deprecation.getReason()); } if (deprecation.getReplacement() != null) { deprecationJson.put("replacement", deprecation.getReplacement()); } jsonObject.put("deprecation", deprecationJson); } propertiesArray.put(jsonObject); } JSONObject additionalMetadata = new JSONObject(); additionalMetadata.put("properties", propertiesArray); writeMetadata(additionalMetadataFile, additionalMetadata); }
private void processLombokTypes(String prefix, TypeElement element, TypeElementMembers members, Map<String, Object> fieldValues) { for (Map.Entry<String, VariableElement> entry : members.getFields().entrySet()) { String name = entry.getKey(); VariableElement field = entry.getValue(); if (!isLombokField(field, element)) { continue; } TypeMirror returnType = field.asType(); Element returnTypeElement = this.processingEnv.getTypeUtils() .asElement(returnType); boolean isExcluded = this.typeExcludeFilter.isExcluded(returnType); boolean isNested = isNested(returnTypeElement, field, element); boolean isCollection = this.typeUtils.isCollectionOrMap(returnType); boolean hasSetter = hasLombokSetter(field, element); if (!isExcluded && !isNested && (hasSetter || isCollection)) { String dataType = this.typeUtils.getType(returnType); String sourceType = this.typeUtils.getType(element); String description = this.typeUtils.getJavaDoc(field); Object defaultValue = fieldValues.get(name); boolean deprecated = isDeprecated(field) || isDeprecated(element); this.metadataCollector.add(ItemMetadata.newProperty(prefix, name, dataType, sourceType, null, description, defaultValue, (deprecated ? new ItemDeprecation() : null))); } } }
@Test 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")); writeAdditionalMetadata(property); ConfigurationMetadata metadata = compile(SimpleProperties.class); assertThat(metadata, containsProperty("simple.comparator", "java.util.Comparator<?>") .fromSource(SimpleProperties.class) .withDeprecation("Don't use this.", "simple.complex-comparator")); assertThat(metadata.getItems().size(), is(4)); }
@Test public void mergeExistingPropertyDeprecationOverride() throws Exception { ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null, null, null, null, null, new ItemDeprecation("Don't use this.", "single.name")); writeAdditionalMetadata(property); ConfigurationMetadata metadata = compile(DeprecatedSingleProperty.class); assertThat(metadata, containsProperty("singledeprecated.name", String.class.getName()) .fromSource(DeprecatedSingleProperty.class) .withDeprecation("Don't use this.", "single.name")); assertThat(metadata.getItems().size(), is(3)); }
@Test public void mergingOfAdditionalDeprecation() throws Exception { writePropertyDeprecation(ItemMetadata.newProperty("simple", "wrongName", "java.lang.String", null, null, null, null, new ItemDeprecation("Lame name.", "simple.the-name"))); ConfigurationMetadata metadata = compile(SimpleProperties.class); assertThat(metadata, containsProperty("simple.wrong-name", String.class) .withDeprecation("Lame name.", "simple.the-name")); }
public ContainsItemMatcher(ItemType itemType, String name, String type, Class<?> sourceType, String description, Matcher<?> defaultValue, ItemDeprecation deprecation) { this.itemType = itemType; this.name = name; this.type = type; this.sourceType = sourceType; this.description = description; this.defaultValue = defaultValue; this.deprecation = deprecation; }
public MetadataItemCondition withDeprecation(String reason, String replacement) { return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.description, this.defaultValue, new ItemDeprecation(reason, replacement)); }
public ContainsItemMatcher withDeprecation(String reason, String replacement) { return new ContainsItemMatcher(this.itemType, this.name, this.type, this.sourceType, this.description, this.defaultValue, new ItemDeprecation(reason, replacement)); }