@Override protected void doVisitFunctionTypeReference(FunctionTypeReference reference, StringBuilder param) { param.append("("); List<LightweightTypeReference> parameterTypes = reference.getParameterTypes(); for(int i = 0; i < parameterTypes.size(); i++) { if (i != 0) { param.append(", "); } parameterTypes.get(i).accept(this, param); } param.append(")=>"); if (reference.getReturnType() != null) { reference.getReturnType().accept(this, param); } else { param.append("./."); } }
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; }
@Override protected void doVisitMatchingTypeParameters(ParameterizedTypeReference actual, ParameterizedTypeReference declaration) { if (actual.isFunctionType() ^ declaration.isFunctionType() /* one or the other is a function type but not both */) { FunctionTypeReference actualFunctionType = actual.tryConvertToFunctionTypeReference(false); if (actualFunctionType != null) { FunctionTypeReference declarationFunctionType = declaration.tryConvertToFunctionTypeReference(false); if (declarationFunctionType != null) { List<LightweightTypeReference> actualParameterTypes = actualFunctionType.getParameterTypes(); List<LightweightTypeReference> declarationParameterTypes = declarationFunctionType.getParameterTypes(); int max = Math.min(actualParameterTypes.size(), declarationParameterTypes.size()); for(int i = 0; i < max; i++) { LightweightTypeReference actualParameterType = actualParameterTypes.get(i); LightweightTypeReference declarationParameterType = declarationParameterTypes.get(i); outerVisit(declarationParameterType, actualParameterType, declaration, VarianceInfo.IN, VarianceInfo.IN); } LightweightTypeReference actualReturnType = actualFunctionType.getReturnType(); LightweightTypeReference declarationReturnType = declarationFunctionType.getReturnType(); if (actualReturnType != null && declarationReturnType != null) { outerVisit(declarationReturnType, actualReturnType, declaration, VarianceInfo.OUT, VarianceInfo.OUT); } return; } } } super.doVisitMatchingTypeParameters(actual, declaration); } };
if ((flags & ALLOW_FUNCTION_CONVERSION) == 0 || (flags & AS_TYPE_ARGUMENT) != 0) return doIsConformant((ParameterizedTypeReference)left, (ParameterizedTypeReference)right, flags); List<LightweightTypeReference> leftParameterTypes = left.getParameterTypes(); List<LightweightTypeReference> rightParameterTypes = right.getParameterTypes(); if (leftParameterTypes.size() != rightParameterTypes.size()) { return flags;
wildcard.addUpperBound(parameterReference); parameterReferences.add(wildcard); } else if (functionType.getParameterTypes().contains(parameterReference)) { WildcardTypeReference wildcard = owner.newWildcardExtendsObject(); wildcard.setLowerBound(parameterReference);
boolean _isFunctionType = light.isFunctionType(); if (_isFunctionType) { final int numParameters = light.getAsFunctionTypeReference().getParameterTypes().size(); if ((numParameters == 1)) { info.brackets = "[]";
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; } }
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)); } }
@Override protected void doVisitFunctionTypeReference(final FunctionTypeReference reference) { boolean _isJava = this.appender.isJava(); if (_isJava) { this.doVisitParameterizedTypeReference(reference); } else { this.appender.append("("); this.appendCommaSeparated(reference.getParameterTypes()); this.appender.append(")=>"); LightweightTypeReference _returnType = reference.getReturnType(); boolean _tripleEquals = (_returnType == null); if (_tripleEquals) { this.appender.append("void"); } else { reference.getReturnType().accept(this); } } }
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); }
protected ITypeComputationState assignParameters(ITypeAssigner typeAssigner) { List<LightweightTypeReference> operationParameterTypes = expectedClosureType.getParameterTypes(); XClosure closure = getClosure(); List<JvmFormalParameter> closureParameters;
JvmFormalParameter p = params.get(i); final String name = p.getName(); appendable.append(functionTypeReference.getParameterTypes().get(i)); appendable.append(" ").append(name);