PsiElement (PsiElement el) { if (el.getParent() instanceof PsiNewExpression) el = el.getParent(); el = findTopmostParentOfType(el, PsiMethodCallExpression.class); el = findTopmostParentOfType(el, PsiAssignmentExpression.class); el = findTopmostParentOfType(el, PsiDeclarationStatement.class); PsiElement parent = el.getParent(); while (parent instanceof PsiExpressionStatement || parent instanceof PsiReturnStatement) { el = parent; parent = el.getParent(); } return el; }