protected void prepareResultType() { resultClosureType = expectedClosureType.getOwner().newFunctionTypeReference(expectedClosureType.getType()); for (LightweightTypeReference argument : expectedClosureType.getTypeArguments()) { resultClosureType.addTypeArgument(argument); } }
@Override protected LocalTypeSubstitutor.SubstitutionResult doVisitFunctionTypeReference(FunctionTypeReference reference, VarianceInfo varianceInfo) { FunctionTypeReference result = owner.newFunctionTypeReference(reference.getType()); return doSubstituteFunctionType(reference, result, false); }
@Override public String getJavaIdentifier() { return getAsStringNoFunctionType(getType().getIdentifier(), JavaIdentifierFunction.INSTANCE); }
@Override protected FunctionTypeReference doCopyInto(ITypeReferenceOwner owner) { FunctionTypeReference result = new FunctionTypeReference(owner, getType()); copyTypeArguments(result, owner); return result; }
protected int doIsConformant(FunctionTypeReference left, FunctionTypeReference right, int flags) { if (left.getType() == right.getType()) { return flags | SUCCESS; } if ((flags & ALLOW_FUNCTION_CONVERSION) == 0) return flags; // function types can be converted to native function types which will be raw assignable if their // number of parameters matches and the function type kind if (left.getParameterTypes().size() == right.getParameterTypes().size()) { LightweightTypeReference leftReturnType = left.getReturnType(); LightweightTypeReference rightReturnType = right.getReturnType(); if (leftReturnType == rightReturnType) { return flags | SUCCESS; } if (leftReturnType != null && rightReturnType != null && leftReturnType.isPrimitiveVoid() == rightReturnType.isPrimitiveVoid()) { return flags | SUCCESS; } } return flags; }
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); } }
@Override protected LightweightTypeReference doVisitFunctionTypeReference(FunctionTypeReference reference, Visiting visiting) { if (reference.isResolved() && reference.isOwnedBy(getOwner())) return reference; FunctionTypeReference result = getOwner().newFunctionTypeReference(reference.getType()); enhanceFunctionType(reference, result, visiting); return result; }
@Override public JvmTypeReference toTypeReference() { XFunctionTypeRef result = getOwner().getServices().getXtypeFactory().createXFunctionTypeRef(); result.setType(getType()); result.setEquivalent(getEquivalentTypeReference()); if (parameterTypes != null) { for(LightweightTypeReference parameterType: parameterTypes) { result.getParamTypes().add(parameterType.toTypeReference()); } } if (returnType != null) { result.setReturnType(returnType.toTypeReference()); } return result; }
final FunctionTypeReference fctRef = closureType0.tryConvertToFunctionTypeReference(true); if (fctRef != null) { closureType = Utils.toLightweightTypeReference(fctRef.getType(), this.typeServices).getRawTypeReference();