从选定的文件中获取类

时间:2014-12-11 11:36:20

标签: eclipse class plugins get selected

我开发Eclipse插件,我想迭代所选子类的所有超类,因为我搜索一个已知的超类。

public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
if (currentSelection instanceof IStructuredSelection) {
            final IStructuredSelection selection = (IStructuredSelection) currentSelection;
            obj = selection.getFirstElement();
            if (obj instanceof IResource) {
                file = (IFile) ((IResource) obj).getAdapter(IFile.class);
            } else if (obj instanceof IJavaElement) {
                file = (IFile) ((IJavaElement) obj).getResource().getAdapter(IFile.class);
            }
        } else if (currentSelection instanceof TextSelection) {
            final IEditorInput activeEditorInput = HandlerUtil.getActiveEditorInput(event);
            file = (IFile) activeEditorInput.getAdapter(IFile.class);
        }
}

file变量是包含该类的文件。我想从所选项目中获取课程。获得课程后我会使用

getSuperclass()

方法,而我找到了正确的超类。

0 个答案:

没有答案