PsiClassType (PsiType currentType, PsiClassType.ClassResolveResult currentTypeResolveResult, PsiClass targetClass) { final Map<PsiTypeParameter, PsiType> substitutionMap = currentTypeResolveResult.getSubstitutor().getSubstitutionMap(); final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(holder.getProject()); if (substitutionMap.size() == 1) { return elementFactory.createType(targetClass, ContainerUtil.getFirstItem(substitutionMap.values())); } else { LOG.assertTrue(substitutionMap.size() == 2); LOG.assertTrue(GuavaLambda.FUNCTION.getJavaAnalogueClassQName().equals(targetClass.getQualifiedName())); final PsiType returnType = LambdaUtil.getFunctionalInterfaceReturnType(currentType); final List<PsiType> types = new ArrayList<>(substitutionMap.values()); types.remove(returnType); final PsiType parameterType = types.get(0); return elementFactory.createType(targetClass, parameterType, returnType); } }