boolean (final PsiType type, final PsiType baseMethodReturnType, final @Nullable PsiSubstitutor methodSubstitutor, final PsiElement context) { if (type instanceof PsiClassType) { final PsiClass resolvedClass = ((PsiClassType)type).resolve(); if (resolvedClass != null) { if (resolvedClass instanceof PsiAnonymousClass) { final PsiClass baseClass = ((PsiAnonymousClass)resolvedClass).getBaseClassType().resolve(); if (baseClass == null) { return false; } if (!LambdaUtil.isFunctionalClass(baseClass)) { return false; } PsiMethod superMethod = LambdaUtil.getFunctionalInterfaceMethod(baseClass); if (superMethod == null) { return false; } final PsiMethod[] methods = resolvedClass.findMethodsByName(superMethod.getName(), false); PsiMethod method = null; for (PsiMethod m : methods) { if (PsiSuperMethodUtil.isSuperMethod(m, superMethod)) { method = m; } } if (method == null) { return false; } final PsiType psiType = methodSubstitutor == null ? method.getReturnType() : methodSubstitutor.substitute(method.getReturnType()); return isSuitableLambdaRole(psiType, baseMethodReturnType, methodSubstitutor, context); } else { if (!LambdaUtil.isFunctionalClass(resolvedClass)) { return false; } return isSuitableLambdaRole(LambdaUtil.getFunctionalInterfaceReturnType(type), baseMethodReturnType, methodSubstitutor, context); } } } return false; }