boolean (@NotNull PsiSwitchExpression switchExpression, @NotNull PsiElement scope) { class YieldFinder extends JavaRecursiveElementWalkingVisitor { private boolean hasYield; @Override public void visitYieldStatement(@NotNull PsiYieldStatement statement) { if (statement.findEnclosingExpression() == switchExpression) { hasYield = true; stopWalking(); } } // do not go inside to save time: declarations cannot contain yield that points to outer switch expression @Override public void visitDeclarationStatement(@NotNull PsiDeclarationStatement statement) {} // do not go inside to save time: expressions cannot contain yield that points to outer switch expression @Override public void visitExpression(@NotNull PsiExpression expression) {} } YieldFinder finder = new YieldFinder(); scope.accept(finder); return finder.hasYield; }