TailType (PsiElement position) { PsiElement scope = position; while (true) { if (scope instanceof PsiFile || scope instanceof PsiClassInitializer) { return TailTypes.noneType(); } if (scope instanceof PsiMethod method) { if (method.isConstructor() || PsiTypes.voidType().equals(method.getReturnType())) { return TailTypes.semicolonType(); } return TailTypes.humbleSpaceBeforeWordType(); } if (scope instanceof PsiLambdaExpression lambda) { final PsiType returnType = LambdaUtil.getFunctionalInterfaceReturnType(lambda); if (PsiTypes.voidType().equals(returnType)) { return TailTypes.semicolonType(); } return TailTypes.humbleSpaceBeforeWordType(); } scope = scope.getParent(); } }