protected void initClosureType(FunctionTypeReference result, boolean isProcedure) { ITypeReferenceOwner owner = result.getOwner(); TypeParameterByUnboundSubstitutor substitutor = new TypeParameterByUnboundSubstitutor(Collections.<JvmTypeParameter, LightweightMergedBoundTypeArgument>emptyMap(), owner) { @Override protected UnboundTypeReference createUnboundTypeReference(JvmTypeParameter type) { UnboundTypeReference result = getExpectation().createUnboundTypeReference(getClosure(), type); return result; } }; JvmGenericType type = (JvmGenericType) result.getType(); List<JvmTypeParameter> typeParameters = type.getTypeParameters(); int max = type.getTypeParameters().size(); if (!isProcedure) max--; for(int i = 0; i < max; i++) { JvmTypeParameter typeParameter = typeParameters.get(i); LightweightTypeReference parameterType = owner.newParameterizedTypeReference(typeParameter); LightweightTypeReference substituted = substitutor.substitute(parameterType); result.addTypeArgument(substituted); } if (!isProcedure) { JvmTypeParameter typeParameter = typeParameters.get(max); LightweightTypeReference parameterType = owner.toLightweightTypeReference(typeParameter); LightweightTypeReference substituted = substitutor.substitute(parameterType); result.addTypeArgument(substituted); } }
for (JvmTypeParameter typeParameter : typeParameters) { LightweightTypeReference typeParameterReference = owner.newParameterizedTypeReference(typeParameter); LightweightTypeReference substituted = substitutor.substitute(typeParameterReference); result.addTypeArgument(substituted); LightweightTypeReference lightweight = owner.toLightweightTypeReference(parameter.getParameterType()); LightweightTypeReference lowerBound = lightweight.getLowerBoundSubstitute(); LightweightTypeReference substituted = substitutor.substitute(lowerBound); result.addParameterType(substituted); LightweightTypeReference substituted = substitutor.substitute(returnType); result.setReturnType(substituted); return result;