PsiElement (List<? extends PsiElement> containers, PsiElement element) { int i = containers.indexOf(element) + 1; if (i < containers.size()) { return containers.get(i); } PsiElement lastItem = ContainerUtil.getLastItem(containers); LOG.assertTrue(lastItem instanceof PsiLambdaExpression); PsiElement parent = PsiTreeUtil.getParentOfType(lastItem, PsiStatement.class, PsiField.class, PsiLambdaExpression.class); if (parent instanceof PsiLambdaExpression) return parent; return parent != null ? parent.getParent() : lastItem.getParent(); }