diff --git a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/ShowDecompiledClassAction.kt b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/ShowDecompiledClassAction.kt index 000bb7ac6c28..dc5b2ac5db56 100644 --- a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/ShowDecompiledClassAction.kt +++ b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/ShowDecompiledClassAction.kt @@ -38,8 +38,15 @@ class ShowDecompiledClassAction : AnAction() { private fun getPsiElement(e: AnActionEvent): PsiElement? { val project = e.project ?: return null - val editor = e.getData(CommonDataKeys.EDITOR) ?: return e.getData(CommonDataKeys.PSI_ELEMENT) - return PsiUtilBase.getPsiFileInEditor(editor, project)?.findElementAt(editor.caretModel.offset) + val editor = e.getData(CommonDataKeys.EDITOR) + val element = if (editor != null) { + PsiUtilBase.getPsiFileInEditor(editor, project)?.findElementAt(editor.caretModel.offset) + } + else { + e.getData(CommonDataKeys.PSI_ELEMENT) + } + if (element == null || !element.isValid) return null + return element } private fun getOriginalFile(psiElement: PsiElement?): VirtualFile? {