Set<String> (@Nullable PsiSwitchBlock block, PsiElement position) { HashSet<String> labels = new HashSet<>(); if (block == null) { return labels; } PsiCodeBlock body = block.getBody(); if (body == null) { return labels; } int offset = position.getTextRange().getStartOffset(); for (PsiStatement statement : body.getStatements()) { if (!(statement instanceof PsiSwitchLabelStatementBase labelStatement)) continue; if (labelStatement.isDefaultCase()) { labels.add(PsiKeyword.DEFAULT); continue; } if (labelStatement.getGuardExpression() != null) { continue; } PsiCaseLabelElementList list = labelStatement.getCaseLabelElementList(); if (list == null) { continue; } for (PsiCaseLabelElement element : list.getElements()) { if (element instanceof PsiExpression expr && ExpressionUtils.isNullLiteral(expr)) { labels.add(PsiKeyword.NULL); continue; } if (element instanceof PsiDefaultCaseLabelElement) { labels.add(PsiKeyword.DEFAULT); } if (element.getTextRange().getStartOffset() >= offset) { break; } PsiType patternType = JavaPsiPatternUtil.getPatternType(element); if (patternType != null && JavaPsiPatternUtil.isUnconditionalForType(element, patternType)) { PsiClass psiClass = PsiUtil.resolveClassInClassTypeOnly(patternType); if (psiClass == null) { continue; } labels.add(psiClass.getQualifiedName()); } } } return labels; }