boolean (PsiElement parent) { if (parent instanceof PsiLambdaExpression lambdaExpression) { final PsiClass thisClass = PsiTreeUtil.getParentOfType(lambdaExpression, PsiClass.class, true); if (thisClass == null || thisClass instanceof PsiAnonymousClass) { final PsiElement body = lambdaExpression.getBody(); if (body == null) return false; final boolean [] disabled = new boolean[1]; body.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitThisExpression(@NotNull PsiThisExpression expression) { disabled[0] = true; } @Override public void visitSuperExpression(@NotNull PsiSuperExpression expression) { disabled[0] = true; } }); if (disabled[0]) return false; } final PsiType functionalInterfaceType = lambdaExpression.getFunctionalInterfaceType(); if (functionalInterfaceType != null && LambdaUtil.isFunctionalType(functionalInterfaceType)) { final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType); if (interfaceMethod != null) { final PsiSubstitutor substitutor = LambdaUtil.getSubstitutor(interfaceMethod, PsiUtil.resolveGenericsClassInType(functionalInterfaceType)); for (PsiType type : interfaceMethod.getSignature(substitutor).getParameterTypes()) { if (!PsiTypesUtil.isDenotableType(type, parent)) { return false; } } final PsiType returnType = LambdaUtil.getFunctionalInterfaceReturnType(functionalInterfaceType); return PsiTypesUtil.isDenotableType(returnType, parent); } } } return false; }