PsiMethod (@Nullable PsiElement element) { if (element == null) return null; if (element.getLanguage() != JavaLanguage.INSTANCE) return null; PsiMethod psiMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class, false); if (psiMethod != null && (element == psiMethod || element == psiMethod.getNameIdentifier() || PsiTreeUtil.isAncestor(psiMethod.getModifierList(), element, false) || PsiTreeUtil.isAncestor(psiMethod.getParameterList(), element, false))) { return psiMethod; } return null; }