void (PsiStatement statement) { if (ControlFlowUtils.statementMayCompleteNormally(statement)) { return; } if (ControlFlowUtils.containsReturn(statement)) { return; } if (ControlFlowUtils.containsSystemExit(statement)) { return; } if (PsiTreeUtil.getParentOfType(statement, PsiSwitchExpression.class) != null && ControlFlowUtils.containsYield(statement)) { return; } if (myIgnoreInThreadTopLevel) { PsiElement parent = PsiTreeUtil.findFirstParent(statement, element -> element instanceof PsiMethod || element instanceof PsiLambdaExpression || element instanceof PsiAnonymousClass); if (parent instanceof PsiMethod method) { if (method.hasModifier(JvmModifier.PRIVATE)) { PsiClass aClass = method.getContainingClass(); boolean allUsagesAreInThreadStart = StreamEx.ofTree((PsiElement)aClass, element -> StreamEx.of(element.getChildren())) .filter(element -> { if (element instanceof PsiMethodCallExpression call) { return call.getMethodExpression().isReferenceTo(method); } if (element instanceof PsiMethodReferenceExpression methodReference) { return methodReference.isReferenceTo(method); } return false; }) .select(PsiExpression.class) .allMatch(inArgument -> { if (inArgument instanceof PsiMethodCallExpression) { return isArgumentInThreadConstructor(inArgument); } if (inArgument instanceof PsiMethodReferenceExpression) { return isInThreadConstructor(inArgument); } return false; }); if (allUsagesAreInThreadStart) return; } else { PsiClass maybeAnonymous = tryCast(method.getContainingClass(), PsiAnonymousClass.class); if (maybeAnonymous != null && "run".equals(method.getName()) && method.getParameterList().isEmpty()) { PsiExpression argument = tryCast(PsiUtil.skipParenthesizedExprUp(maybeAnonymous.getParent()), PsiExpression.class); if (isInThreadConstructor(argument)) return; } } } else if (parent instanceof PsiLambdaExpression) { if (isInThreadConstructor((PsiExpression)parent)) return; } } registerStatementError(statement); }