KtWhenExpression (@Nullable KtExpression expression) { KtWhenEntry whenEntry = PsiTreeUtil.getParentOfType(expression, KtWhenEntry.class, true); if (whenEntry == null) return null; KtExpression whenEntryExpression = whenEntry.getExpression(); if (whenEntryExpression == null) return null; if (!equalOrLastInBlock(whenEntryExpression, expression)) return null; return PsiTreeUtil.getParentOfType(whenEntry, KtWhenExpression.class, true); }