List all subclasses with fully qualified names

后端 未结 4 704
北海茫月
北海茫月 2021-01-13 08:18

I would like to get a list of all subclasses of a given class with their fully qualified names. I wanted to copy it from Eclipse and paste into a text file like this:

<
4条回答
  •  情话喂你
    2021-01-13 08:33

    The method in the Hierarchy view which does build the hierarchy tree is in the org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyLifeCycle:

    private ITypeHierarchy createTypeHierarchy(IJavaElement element, IProgressMonitor pm) throws JavaModelException {
        if (element.getElementType() == IJavaElement.TYPE) {
            IType type= (IType) element;
            if (fIsSuperTypesOnly) {
                return type.newSupertypeHierarchy(pm);
            } else {
                return type.newTypeHierarchy(pm);
            }
        } else {
    

    Which uses org.eclipse.jdt.internal.core.SourceType class

    /**
     * @see IType
     */
    public ITypeHierarchy newTypeHierarchy(IJavaProject project, IProgressMonitor monitor) throws JavaModelException {
        return newTypeHierarchy(project, DefaultWorkingCopyOwner.PRIMARY, monitor);
    }
    

    So if you can get a IJavaElement, you can check those classes to emulate the same result.

    It uses a org.eclipse.jdt.internal.core.CreateTypeHierarchyOperation

提交回复
热议问题