PsiLocalVariable (@NotNull Editor editor, @NotNull PsiFile file) { SelectionModel selection = editor.getSelectionModel(); if (selection.hasSelection()) { return PsiTreeUtil.findElementOfClassAtRange(file, selection.getSelectionStart(), selection.getSelectionEnd(), PsiLocalVariable.class); } else { return PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PsiLocalVariable.class); } }