我试图获得ClassTree对象的超类的完全限定名称。目前,我正在使用toString()-Method:

public class ClassScanner extends TreePathScanner<Object, Trees> {

    @Override
    public Object visitClass(ClassTree ct, Trees trees) {
        TreePath currentPath = getCurrentPath();
        TypeElement typeElement = (TypeElement) trees.getElement(currentPath);
        String s = typeElement.getSuperclass().toString();
        System.out.println(s);
        return super.visitClass(ct, trees);
    }
}


但这似乎不是未来的方法。另外,我必须自己提取名称,包,泛型...。有其他选择吗?

谢谢

最佳答案

怎么样

    Tree extendsClassTree = classTree.getExtendsClause();
    if (extendsClassTree != null) {
        superClassName = extendsClassTree.toString();
    } else {
        superClassName = "java.lang.Object";
    }


(从here借来的:))

10-08 11:09