protected boolean tryAssignTypeArguments(List<LightweightTypeReference> typeArguments, FunctionTypeReference result) { for(LightweightTypeReference typeArgument: typeArguments) { result.addTypeArgument(typeArgument); LightweightTypeReference lowerBound = typeArgument.getLowerBoundSubstitute(); if (lowerBound instanceof AnyTypeReference) { return false; } result.addParameterType(lowerBound); } return true; } }
@Override protected void copyTypeArguments(ParameterizedTypeReference result, ITypeReferenceOwner owner) { super.copyTypeArguments(result, owner); FunctionTypeReference casted = (FunctionTypeReference) result; if (parameterTypes != null && !parameterTypes.isEmpty()) { for(LightweightTypeReference typeArgument: parameterTypes) { casted.addParameterType(typeArgument.copyInto(owner)); } } if (returnType != null) { casted.setReturnType(returnType.copyInto(owner)); } }
protected FunctionTypeReference processExpressionType(FunctionTypeReference incompleteClosureType, ITypeComputationResult expressionResult) { LightweightTypeReference expressionResultType = expressionResult.getReturnType(); if (expressionResultType == null || !expressionResultType.isPrimitiveVoid()) { FunctionTypeReference result = getFunctionTypeReference(false); LightweightTypeReference expectedReturnType = result.getTypeArguments().get(result.getTypeArguments().size() - 1); if (expressionResultType != null && !expressionResultType.isAny()) { result.setReturnType(expressionResultType); deferredBindTypeArgument(expectedReturnType, expressionResultType, BoundTypeArgumentSource.INFERRED); } else { LightweightTypeReference objectTypeReference = incompleteClosureType.getOwner().newReferenceToObject(); result.setReturnType(objectTypeReference); deferredBindTypeArgument(expectedReturnType, objectTypeReference, BoundTypeArgumentSource.INFERRED); } List<LightweightTypeReference> incompleteParameterTypes = incompleteClosureType.getParameterTypes(); for(int i = 0; i < incompleteParameterTypes.size(); i++) { result.addParameterType(incompleteParameterTypes.get(i)); } List<LightweightTypeReference> incompleteTypeArguments = incompleteClosureType.getTypeArguments(); List<LightweightTypeReference> resultTypeArguments = result.getTypeArguments(); for(int i = 0; i < incompleteTypeArguments.size(); i++) { deferredBindTypeArgument(resultTypeArguments.get(i), incompleteTypeArguments.get(i), BoundTypeArgumentSource.INFERRED); } return result; } else { incompleteClosureType.setReturnType(expressionResultType); return incompleteClosureType; } }
incompleteClosureType.addParameterType(closureParameterType); } else { typeAssigner.assignType(closureParameter, operationParameterType); incompleteClosureType.addParameterType(operationParameterType); LightweightTypeReference operationParameterType = operationParameterTypes.get(0); typeAssigner.assignType(implicitParameter, operationParameterType); incompleteClosureType.addParameterType(operationParameterType); ITypeComputationState result = typeAssigner.getForkedState(); return result;
protected void enhanceFunctionType(FunctionTypeReference reference, FunctionTypeReference result, Visiting visiting) { for(LightweightTypeReference parameterType: reference.getParameterTypes()) { result.addParameterType(visitTypeArgument(parameterType, visiting, true)); } for(LightweightTypeReference typeArgument: reference.getTypeArguments()) { result.addTypeArgument(visitTypeArgument(typeArgument, visiting)); } LightweightTypeReference returnType = reference.getReturnType(); if (returnType != null) { result.setReturnType(visitTypeArgument(returnType, visiting)); } }
resultClosureType.addParameterType(closureParameterType); if (validParameterTypes && !closureParameterType.isAssignableFrom(operationParameterType)) { validParameterTypes = false; resultClosureType.addParameterType(partiallyResolved); LightweightTypeReference lightweight = typeAssigner.toLightweightTypeReference(parameterType); typeAssigner.assignType(closureParameter, lightweight); resultClosureType.addParameterType(lightweight); } else { LightweightTypeReference objectType = typeAssigner.toLightweightTypeReference(getServices().getTypeReferences().getTypeForName(Object.class, closureParameter)); typeAssigner.assignType(closureParameter, objectType); resultClosureType.addParameterType(objectType);
private FunctionTypeReference createFunctionTypeRef( ITypeReferenceOwner owner, LightweightTypeReference functionType, List<LightweightTypeReference> parameterTypes, /* @Nullable */ LightweightTypeReference returnType, /* @Nullable */ LightweightTypeReference outer) { JvmType type = functionType.getType(); if (type == null) throw new IllegalArgumentException("type may not be null"); FunctionTypeReference result; if (outer == null) { result = owner.newFunctionTypeReference(type); } else { result = owner.newFunctionTypeReference(outer, type); } if (functionType instanceof ParameterizedTypeReference) { for(LightweightTypeReference typeArgument: ((ParameterizedTypeReference) functionType).getTypeArguments()) { result.addTypeArgument(typeArgument.copyInto(owner)); } } for(LightweightTypeReference parameterType: parameterTypes) { result.addParameterType(parameterType.copyInto(owner)); } if (returnType != null) { result.setReturnType(returnType.copyInto(owner)); } return result; }
if (lowerBound instanceof AnyTypeReference) return null; result.addParameterType(lowerBound);
protected LocalTypeSubstitutor.SubstitutionResult doSubstituteFunctionType(FunctionTypeReference reference, FunctionTypeReference result, boolean didSubstitute) { for(LightweightTypeReference parameterType: reference.getParameterTypes()) { SubstitutionResult visited = visitTypeArgument(parameterType, VarianceInfo.IN); didSubstitute = didSubstitute || visited.didSubstitute; result.addParameterType(visited.typeReference); } for(LightweightTypeReference typeArgument: reference.getTypeArguments()) { SubstitutionResult visited = visitTypeArgument(typeArgument, VarianceInfo.INVARIANT); didSubstitute = didSubstitute || visited.didSubstitute; result.addTypeArgument(visited.typeReference); } LightweightTypeReference returnType = reference.getReturnType(); if (returnType != null) { SubstitutionResult visited = visitTypeArgument(returnType, VarianceInfo.OUT); didSubstitute = didSubstitute || visited.didSubstitute; result.setReturnType(visited.typeReference); } return new SubstitutionResult(result, didSubstitute); }
LightweightTypeReference lowerBound = lightweight.getLowerBoundSubstitute(); LightweightTypeReference substituted = substitutor.substitute(lowerBound); result.addParameterType(substituted);
@Override public LightweightTypeReference doVisitFunctionTypeReference(XFunctionTypeRef reference) { JvmTypeReference equivalent = reference.getEquivalent(); if (equivalent == null) { return super.doVisitFunctionTypeReference(reference); } FunctionTypeReference result; // constructors used below to avoid subsequent checks for isInner which was supposed to be done by // the computation of the equivalent if (equivalent.eClass() == TypesPackage.Literals.JVM_INNER_TYPE_REFERENCE) { JvmParameterizedTypeReference outer = ((JvmInnerTypeReference) equivalent).getOuter(); LightweightTypeReference outerEquivalent = outer.accept(this); result = new InnerFunctionTypeReference(owner, outerEquivalent, reference.getType()); } else { result = new FunctionTypeReference(owner, reference.getType()); } if (equivalent instanceof JvmParameterizedTypeReference) { for(JvmTypeReference argument: ((JvmParameterizedTypeReference)equivalent).getArguments()) { result.addTypeArgument(visit(argument)); } } for(JvmTypeReference parameter: reference.getParamTypes()) { result.addParameterType(visit(parameter)); } if (reference.getReturnType() != null) { result.setReturnType(visit(reference.getReturnType())); } return result; }
result.addParameterType(parameterType); final WildcardTypeReference typeArgument = this.getOwner().newWildcardTypeReference(); typeArgument.setLowerBound(parameterType);