从TypeElement返回类型的合格名称(对于嵌套类,其中包含$符号的类型)。
//package com.nowjava; import javax.lang.model.element.NestingKind; import javax.lang.model.element.TypeElement; /** 来自 n o w j a v a . c o m**/ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; public class Main { /** * Return the qualified name of a type (those that contain a $ sign for * nested classes). * * @param tm * Represent the class * @return The class name */ public static String getClassName(TypeMirror tm) { if (tm.getKind().equals(TypeKind.DECLARED)) {/** from 时代Java**/ TypeElement el = (TypeElement) ((DeclaredType) tm).asElement(); return getClassName(el); } else { return tm.toString(); } } /** * Return the qualified name of a type (those that contain a $ sign for * nested classes). * * @param el * Represent the class * @return The class name */ public static String getClassName(TypeElement el) { if (el.getNestingKind() == NestingKind.TOP_LEVEL) {