Search in sources :

Example 1 with ItemDeprecation

use of org.springframework.boot.configurationprocessor.metadata.ItemDeprecation in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessor method processSimpleLombokTypes.

private void processSimpleLombokTypes(String prefix, TypeElement element, ExecutableElement source, 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.getQualifiedName(element);
            String description = this.typeUtils.getJavaDoc(field);
            Object defaultValue = fieldValues.get(name);
            boolean deprecated = isDeprecated(field) || isDeprecated(source);
            this.metadataCollector.add(ItemMetadata.newProperty(prefix, name, dataType, sourceType, null, description, defaultValue, (deprecated ? new ItemDeprecation() : null)));
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) ItemDeprecation(org.springframework.boot.configurationprocessor.metadata.ItemDeprecation) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) VariableElement(javax.lang.model.element.VariableElement) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with ItemDeprecation

use of org.springframework.boot.configurationprocessor.metadata.ItemDeprecation in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessor method getItemDeprecation.

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));
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) ItemDeprecation(org.springframework.boot.configurationprocessor.metadata.ItemDeprecation)

Example 3 with ItemDeprecation

use of org.springframework.boot.configurationprocessor.metadata.ItemDeprecation in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessorTests method mergingOfAdditionalDeprecation.

@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"));
}
Also used : ItemDeprecation(org.springframework.boot.configurationprocessor.metadata.ItemDeprecation) ConfigurationMetadata(org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata) Test(org.junit.Test)

Example 4 with ItemDeprecation

use of org.springframework.boot.configurationprocessor.metadata.ItemDeprecation in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessorTests method writePropertyDeprecation.

private void writePropertyDeprecation(ItemMetadata... items) throws Exception {
    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);
}
Also used : JSONObject(org.json.JSONObject) ItemDeprecation(org.springframework.boot.configurationprocessor.metadata.ItemDeprecation) JSONArray(org.json.JSONArray) File(java.io.File) ItemMetadata(org.springframework.boot.configurationprocessor.metadata.ItemMetadata)

Example 5 with ItemDeprecation

use of org.springframework.boot.configurationprocessor.metadata.ItemDeprecation in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessorTests method mergeExistingPropertyDeprecation.

@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);
}
Also used : ItemDeprecation(org.springframework.boot.configurationprocessor.metadata.ItemDeprecation) ConfigurationMetadata(org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata) ItemMetadata(org.springframework.boot.configurationprocessor.metadata.ItemMetadata) Test(org.junit.Test)

Aggregations

ItemDeprecation (org.springframework.boot.configurationprocessor.metadata.ItemDeprecation)6 Test (org.junit.Test)3 ConfigurationMetadata (org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata)3 ItemMetadata (org.springframework.boot.configurationprocessor.metadata.ItemMetadata)3 File (java.io.File)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 TypeElement (javax.lang.model.element.TypeElement)1 VariableElement (javax.lang.model.element.VariableElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1