[java-decompiler] IDEA-381628 fix PIEAE in ShowDecompiledClassAction#update()

PIEAE: PsiInvalidElementAccessException

GitOrigin-RevId: 359b1fc4c78c6ab41d8a09a150cae71cc4e84ec1
This commit is contained in:
Bartek Pacia
2025-11-03 12:39:05 +00:00
committed by intellij-monorepo-bot
parent 35637e49c6
commit bb3ed0c94b
@@ -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? {