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

com.xiongyingqi.utils.code.CodeAnnotation Maven / Gradle / Ivy

There is a newer version: 0.1.10
Show newest version
package com.xiongyingqi.utils.code;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * 注解帮助类
 * Created by 瑛琪xiongyingqi.com on 2014/3/31 0031.
 */
public class CodeAnnotation {
    private Map, Class> toAddAnnotationsByExistsAnnotation;
    private Map, Map> toAddAnnotationProperties;

    /**
     * 为已经存在的注解新增参数列表
     *
     * @param clazz
     * @param parameters
     * @return
     */
    public CodeAnnotation addAnnotationProperties(Class clazz, Map parameters) {
        return this;
    }


    /**
     * 为已经存在的注解方法、类、属性、参数等新增注解
     *
     * @param existsAnnotation 已经存在的Annotation
     * @param newAnnotation    新增的Annotation
     * @return
     */
    public CodeAnnotation addAnnotationByExistsAnnotation(Class existsAnnotation, Class newAnnotation) {

        return this;
    }

    public static void main(String[] args) throws IllegalAccessException, InstantiationException {
        Class clazz = SuppressWarnings.class;
        System.out.println(clazz.isAnnotation());
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            System.out.println(field);
        }

        Method[] methods = clazz.getDeclaredMethods();
        for (Method method : methods) {
            if (method.getName().equals("value")) {
                Object instance = clazz.newInstance();
                try {
                    Object re = method.invoke(instance);
                    System.out.println(re);
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(method);
        }


    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy