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

com.github.datalking.common.meta.StandardMethodMetadata Maven / Gradle / Ivy

package com.github.datalking.common.meta;

import com.github.datalking.util.AnnotationUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * 方法元数据 默认实现类
 *
 * @author yaoo on 4/13/18
 */
public class StandardMethodMetadata implements MethodMetadata {

    private final Method introspectedMethod;

    public StandardMethodMetadata(Method introspectedMethod) {
        this.introspectedMethod = introspectedMethod;
    }

    @Override
    public String getMethodName() {
        return this.introspectedMethod.getName();
    }

    @Override
    public String getDeclaringClassName() {
        return this.introspectedMethod.getDeclaringClass().getName();
    }

    @Override
    public String getReturnTypeName() {
        return this.introspectedMethod.getReturnType().getName();
    }

    @Override
    public Map getAnnotationAttributes(String annotationType) {

        Annotation[] anns = this.introspectedMethod.getAnnotations();

        for (Annotation ann : anns) {

            if (ann.annotationType().getName().equals(annotationType)) {
                return AnnotationUtils.getAnnotationAttributes(
                        ann, true, false);
//                        ann, true, nestedAnnotationsAsMap);
            }

            for (Annotation metaAnn : ann.annotationType().getAnnotations()) {
                if (metaAnn.annotationType().getName().equals(annotationType)) {
                    return AnnotationUtils.getAnnotationAttributes(
                            metaAnn, true, false);
//                            metaAnn, true, this.nestedAnnotationsAsMap);
                }
            }

        }

        return null;
    }

    @Override
    public String toString() {
        return "MethodMeta{" +
                "name=" + introspectedMethod.getName() +
                ", return type=" + introspectedMethod.getReturnType().getSimpleName() +
                '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy