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

vite.rxbus.compiler.TestPrinter Maven / Gradle / Ivy

The newest version!
package vite.rxbus.compiler;

import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror;

/**
 * Created by trs on 17-5-25.
 */

public class TestPrinter {

    public static void print(String title, Element e) {
        File file = new File("./simple.txt");
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        FileWriter writer = null;
        try {
            writer = new FileWriter(file, true);
            writer.write(title + "\n");
            writer.write("element:" + e.toString() + "\n");
            writer.write("simple name:" + e.getSimpleName() + "\n");
            writer.write("kind:" + e.getKind() + "\n");
            writer.write("Modifiers:" + e.getModifiers() + "\n");
            writer.write("AsType:" + e.asType() + "\n");
            writer.write("EnclosingElement:" + e.getEnclosingElement() + "\n");
            writer.write("EnclosedElement:" + e.getEnclosedElements() + "\n");
            writer.write("AnnotationMirrors:" + e.getAnnotationMirrors() + "\n");
            writer.write("================================\n\n");
        } catch (IOException e1) {
            e1.printStackTrace();
        } finally {
            if (writer != null)
                try {
                    writer.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
        }
    }

    public static void printExecutableElement(ExecutableElement e) {
        File file = new File("./simpleExecutable.txt");
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        FileWriter writer = null;
        try {
            writer = new FileWriter(file, true);
            writer.write("element:" + e.toString() + "\n");
            writer.write("simple name:" + e.getSimpleName() + "\n");
            writer.write("kind:" + e.getKind() + "\n");
            writer.write("Modifiers:" + e.getModifiers() + "\n");
            writer.write("AsType:" + e.asType() + "\n");
            writer.write("EnclosingElement:" + e.getEnclosingElement() + "\n");
            writer.write("EnclosedElement:" + e.getEnclosedElements() + "\n");
            writer.write("AnnotationMirrors:" + e.getAnnotationMirrors() + "\n");
            writer.write("DefaultValue:" + e.getDefaultValue() + "\n");
            writer.write("Parameters:" + e.getParameters() + "\n");
            writer.write("ReturnType:" + e.getReturnType() + "\n");
            writer.write("ThrownTypes:" + e.getThrownTypes() + "\n");
            writer.write("isVarArgs:" + e.isVarArgs() + "\n");

            List parameters = (List) e.getParameters();
            for (VariableElement ve : parameters) {
                writer.write("VariableElement - element:" + ve.toString() + "\n");
                writer.write("VariableElement - simple name:" + ve.getSimpleName() + "\n");
                writer.write("VariableElement - kind:" + ve.getKind() + "\n");
                writer.write("VariableElement - Modifiers:" + ve.getModifiers() + "\n");
                writer.write("VariableElement - AsType:" + ve.asType() + "\n");

                TypeMirror typeMirror = ve.asType();
                writer.write("VariableElement - typeMirror Kind- :" + typeMirror.getKind() + "\n");
                writer.write("VariableElement - typeMirror String - :" + typeMirror.toString() + "\n");

                if (typeMirror != null) {
                    Element typeElement = Util.TypeUtils.asElement(typeMirror);
                    if (typeElement != null) {
                        writer.write("VariableElement - asElement - element:" + typeElement.toString() + "\n");
                        writer.write("VariableElement - asElement - simple name:" + typeElement.getSimpleName() + "\n");
                        writer.write("VariableElement - asElement - kind:" + typeElement.getKind() + "\n");
                        writer.write("VariableElement - asElement - Modifiers:" + typeElement.getModifiers() + "\n");
                        writer.write("VariableElement - asElement - AsType:" + typeElement.asType() + "\n");
                        writer.write("VariableElement - asElement - EnclosingElement:" + typeElement.getEnclosingElement() + "\n");
                        writer.write("VariableElement - asElement - EnclosedElement:" + typeElement.getEnclosedElements() + "\n");
                        writer.write("VariableElement - asElement - AnnotationMirrors:" + typeElement.getAnnotationMirrors() + "\n");
                    }
                }

                writer.write("VariableElement - EnclosingElement:" + ve.getEnclosingElement() + "\n");
                writer.write("VariableElement - EnclosedElement:" + ve.getEnclosedElements() + "\n");
                writer.write("VariableElement - AnnotationMirrors:" + ve.getAnnotationMirrors() + "\n");
                writer.write("VariableElement - ConstantValue:" + ve.getConstantValue() + "\n");
            }
            writer.write("================================\n\n");
        } catch (IOException e1) {
            e1.printStackTrace();
        } finally {
            if (writer != null)
                try {
                    writer.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy