package org.tanc.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * class 对象信息打印
 * Created by tanc on 2017/4/12.
 */
public class ShowClass {

    public static void printAllMessage(Object o) {
        printFieldMessage(o);
        printConstructorMessage(o);
        printMethodMessage(o);
    }

    public static void printFieldMessage(Object o){
        Class cls = o.getClass();
        StringBuilder buffer = new StringBuilder();
        Field[] fields = cls.getDeclaredFields();
        for (Field field : fields) {
            buffer.append(Modifier.toString(field.getModifiers())).append(" ").append(field.getName()).append(";\n");
        }
        System.out.println(buffer.toString());
    }

    public static void printConstructorMessage(Object o) {
        Class cls = o.getClass();
        StringBuilder buffer = new StringBuilder();
        Constructor[] constructors = cls.getConstructors();
        for (Constructor constructor : constructors) {
            buffer.append(Modifier.toString(constructor.getModifiers())).append(" ").append(constructor.getName()).append("(");
            Class[] params = constructor.getParameterTypes();
            for (Class c : params) {
                buffer.append(c.getName()).append(",");
            }
            if (buffer.charAt(buffer.length() - 1) == ',') {
                buffer.deleteCharAt(buffer.length() - 1);
            }
            buffer.append(");\n");
        }
        System.out.println(buffer.toString());
    }

    public static void printMethodMessage(Object o) {
        Class cls = o.getClass();
        StringBuilder buffer = new StringBuilder();
        Method[] methods = cls.getMethods();
        for (Method method : methods) {
            buffer.append(Modifier.toString(method.getModifiers())).append(" ").append(method.getReturnType()).append(" ").append(method.getName()).append("(");
            Class[] params = method.getParameterTypes();
            for (Class c : params) {
                buffer.append(c.getName()).append(",");
            }
            if (buffer.charAt(buffer.length() - 1) == ',') {
                buffer.deleteCharAt(buffer.length() - 1);
            }
            buffer.append(");\n");
        }
        System.out.println(buffer.toString());
    }
}

@@ -242,16 +242,50 @@
 lass %7B%0A%0A
+    /**%0A     * %E6%89%93%E5%8D%B0%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1%E7%9A%84%E7%B1%BB%E4%BF%A1%E6%81%AF%0A     */%0A
     publ
@@ -423,32 +423,65 @@
 sage(o);%0A    %7D%0A%0A
+    /**%0A     * %E6%89%93%E5%8D%B0%E4%B8%80%E4%B8%AA%E7%B1%BB%E7%9A%84%E5%9F%9F%E4%BF%A1%E6%81%AF%0A     */%0A
     public stati
@@ -863,32 +863,68 @@
 ring());%0A    %7D%0A%0A
+    /**%0A     * %E6%89%93%E5%8D%B0%E4%B8%80%E4%B8%AA%E7%B1%BB%E7%9A%84%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%E4%BF%A1%E6%81%AF%0A     */%0A
     public stati
@@ -1692,24 +1692,58 @@
 ());%0A    %7D%0A%0A
+    /**%0A     * %E6%89%93%E5%8D%B0%E4%B8%80%E4%B8%AA%E7%B1%BB%E7%9A%84%E6%96%B9%E6%B3%95%E4%BF%A1%E6%81%AF%0A     */%0A
     public s

add information