@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); } };
return flags; LightweightTypeReference leftReturnType = left.getReturnType(); LightweightTypeReference rightReturnType = right.getReturnType(); if (leftReturnType!=rightReturnType && (leftReturnType == null || rightReturnType == null)) { return flags;
if (parameterized instanceof FunctionTypeReference && !(parameterReference instanceof WildcardTypeReference)) { FunctionTypeReference functionType = (FunctionTypeReference) parameterized; if (i == typeParameters.size() - 1 && parameterReference.equals(functionType.getReturnType())) { WildcardTypeReference wildcard = owner.newWildcardTypeReference(); wildcard.addUpperBound(parameterReference);
@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 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)); } }
LightweightTypeReference expectedReturnType = expectedClosureType.getReturnType(); if (expectedReturnType == null) { throw new IllegalStateException("expected return type may not be null"); if (resultClosureType.getReturnType() == null) throw new IllegalStateException("Closure has no return type assigned"); if (!validParameterTypes || flags == ConformanceFlags.INCOMPATIBLE) {
LightweightTypeReference expressionResultType = expressionResult.getReturnType(); if (expressionResultType == null || expressionResultType instanceof AnyTypeReference) { LightweightTypeReference returnType = expectedClosureType.getReturnType(); if (returnType == null) throw new IllegalStateException("return type shall not be null"); LightweightTypeReference expectedReturnType = expectedClosureType.getReturnType(); if (expectedReturnType == null) throw new IllegalStateException("expected return type may not be null");
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 returnType = expectedClosureType.getReturnType(); if (returnType.getKind() == LightweightTypeReference.KIND_UNBOUND_TYPE_REFERENCE) { skippedHandle = ((UnboundTypeReference) returnType).getHandle();
private LightweightTypeReference findRealReturnType(XExpression expression) { if (expression == null) return null; JvmIdentifiableElement logicalContainer = getLogicalContainerProvider().getLogicalContainer(expression); if (logicalContainer instanceof JvmOperation) { return getLightweightType(logicalContainer); } if (expression instanceof XClosure) { IResolvedTypes resolvedTypes = batchTypeResolver.resolveTypes(expression); LightweightTypeReference type = resolvedTypes.getExpectedType(expression); if (type == null) { type = resolvedTypes.getActualType(expression); } if (type == null) { return null; } FunctionTypeReference functionType = type.tryConvertToFunctionTypeReference(false); if (functionType != null) { return functionType.getReturnType(); } return null; } XExpression containerExpression = EcoreUtil2.getContainerOfType(expression.eContainer(), XExpression.class); if (containerExpression == null) { LightweightTypeReference returnType = getLightweightReturnType(expression); return returnType; } return findRealReturnType(containerExpression); }
appendable.increaseIndentation().increaseIndentation(); appendable.newLine().append("public "); LightweightTypeReference returnType = functionTypeReference.getReturnType(); if (returnType == null) throw new IllegalStateException("Could not find return type");
final FunctionTypeReference fctRef = returnType.tryConvertToFunctionTypeReference(true); if (fctRef != null) { returnType = fctRef.getReturnType(); } else { returnType = null;