PsiElement (@NotNull PsiElement result) { PsiElement anchor = PsiTreeUtil .getNonStrictParentOfType(result, PsiStatement.class, PsiLambdaExpression.class, PsiVariable.class, PsiNameValuePair.class); if (anchor instanceof PsiLambdaExpression && anchor != result) { anchor = ((PsiLambdaExpression)anchor).getBody(); } if (anchor instanceof PsiVariable && anchor.getParent() instanceof PsiDeclarationStatement) { anchor = anchor.getParent(); } if (anchor instanceof PsiStatement && (anchor.getParent() instanceof PsiIfStatement || anchor.getParent() instanceof PsiLoopStatement)) { anchor = anchor.getParent(); } return anchor == null ? result : anchor; }