集册 Java实例教程 从TypeElement获取类名

从TypeElement获取类名

欢马劈雪     最近更新时间:2020-01-02 10:19:05

736
从TypeElement获取类名


//package com.nowjava;

import javax.lang.model.element.Element;
/*来 自 n o w j a v a . c o m*/

import javax.lang.model.element.PackageElement;

import javax.lang.model.element.TypeElement;


public class Main {

    public static String getClassName(TypeElement element) {

        Element currElement = element;

        String result = element.getSimpleName().toString();

        while (currElement.getEnclosingElement() != null) {

            currElement = currElement.getEnclosingElement();

            if (currElement instanceof TypeElement) {

                result = currElement.getSimpleName() + "$" + result;

            } else if (currElement instanceof PackageElement) {

                if (!"".equals(currElement.getSimpleName())) {

                    result = ((PackageElement) c
展开阅读全文