All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.linkkou.databulid.extension.asinglefield.annotation.ExcludeParsing Maven / Gradle / Ivy

package com.github.linkkou.databulid.extension.asinglefield.annotation;

import com.github.linkkou.databulid.utils.AnnotationUtils;
import com.sun.tools.javac.code.Attribute;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.VariableElement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 排除相关方法
 * @author lk
 * @version 1.0
 * @date 2020/9/15 08:51
 */
public class ExcludeParsing {

    public static List getExclude(VariableElement methodParameter) {
        final HashMap parametersAnnotation = AnnotationUtils.getParametersAnnotation(methodParameter);
        final AnnotationMirror annotationMirror = parametersAnnotation.get(Exclude.class.getName());
        return getExclude(annotationMirror);
    }

    /**
     * 注解解析
     *
     * @param annotationMirror 注解对象
     * @return list
     */
    private static List getExclude(final AnnotationMirror annotationMirror) {
        if (null != annotationMirror) {
            final HashMap annotationParameters1 = AnnotationUtils.getAnnotationParameters(annotationMirror);
            for (Map.Entry valueEntry : annotationParameters1.entrySet()) {
                if ("methodsName".equals(valueEntry.getKey())) {
                    final List annotationValueForArray = AnnotationUtils.getAnnotationValueForArray(valueEntry.getValue());
                    final List collect = annotationValueForArray.stream().map((x) -> {
                        return (String) (((Attribute.Constant) x).value);
                    }).collect(Collectors.toList());
                    return collect;
                }
            }
        }
        return new ArrayList<>();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy