Object (@NotNull DataProvider dataProvider) { Object item = PlatformCoreDataKeys.SELECTED_ITEM.getData(dataProvider); PsiElement element = null; if (item instanceof PsiElement) { element = (PsiElement)item; } else if (item instanceof PsiAwareObject) { Project project = CommonDataKeys.PROJECT.getData(dataProvider); element = project == null ? null : ((PsiAwareObject)item).findElement(project); } else if (item instanceof PsiElementNavigationItem) { element = ((PsiElementNavigationItem)item).getTargetElement(); } else if (item instanceof VirtualFile) { Project project = CommonDataKeys.PROJECT.getData(dataProvider); element = project == null || !((VirtualFile)item).isValid() ? null : PsiManager.getInstance(project).findFile((VirtualFile)item); } else if (item instanceof Pointer<?>) { element = getElement((Pointer<?>)item); } return element != null && element.isValid() ? element : null; }