@Override public JvmOperation getOperation() { JvmOperation result = functionTypes.findImplementingOperation(getExpectedClosureType()); if (result == null) { throw new IllegalStateException(); } return result; }
/** * Returns the equivalent {@link FunctionTypeReference} if this reference * points to a {@link Functions function} or {@link Procedures procedure}. * Otherwise returns <code>null</code>. This is the externalized and thereby * exchangeable implementation of {@link ParameterizedTypeReference#getAsFunctionTypeReference()}. * @see #tryConvertToFunctionTypeReference(ParameterizedTypeReference, boolean) */ /* @Nullable */ public FunctionTypeReference getAsFunctionTypeReference(ParameterizedTypeReference typeReference) { FunctionTypeKind functionTypeKind = getFunctionTypeKind(typeReference); if (functionTypeKind == FunctionTypeKind.PROCEDURE) { return getAsProcedureOrNull(typeReference); } else if (functionTypeKind == FunctionTypeKind.FUNCTION) { return getAsFunctionOrNull(typeReference); } return null; }
/** * {@inheritDoc} * * @see FunctionTypes#getAsFunctionTypeReference(ParameterizedTypeReference) */ @Override /* @Nullable */ public FunctionTypeReference getAsFunctionTypeReference() { FunctionTypes functionTypes = getServices().getFunctionTypes(); return functionTypes.getAsFunctionTypeReference(this); }
JvmOperation operation = findImplementingOperation(typeReference); if (operation == null) return null; LightweightTypeReference declaredReturnType = owner.toLightweightTypeReference(operation.getReturnType()); if (rawType) { FunctionTypeReference result = createRawFunctionTypeRef(owner, operation, operation.getParameters().size(), declaredReturnType.isPrimitiveVoid()); TypeParameterByConstraintSubstitutor substitutor = new TypeParameterByConstraintSubstitutor( Collections.<JvmTypeParameter, LightweightMergedBoundTypeArgument>emptyMap(), owner); return result; List<JvmTypeParameter> allTypeParameters = collectAllTypeParameters(typeReference, operation); ActualTypeArgumentCollector typeArgumentCollector = new UnboundTypeParameterAwareTypeArgumentCollector(allTypeParameters, BoundTypeArgumentSource.CONSTRAINT, owner); Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> typeParameterMapping = getFunctionTypeParameterMapping( typeReference, operation, typeArgumentCollector, owner); Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mergedTypeParameterMapping = Maps.newLinkedHashMap(); FunctionTypeReference result = createFunctionTypeRef(owner, typeReference, parameterTypes, returnType.getUpperBoundSubstitute(), typeReference.getOuter()); return result;
@Override public FunctionTypeKind getFunctionTypeKind() { FunctionTypes functionTypes = getServices().getFunctionTypes(); return functionTypes.getFunctionTypeKind(this); }
protected AbstractClosureTypeHelper getClosureWithoutExpectationHelper() { if (functionTypes.isFunctionAndProcedureAvailable(expectation.getReferenceOwner())) return createClosureWithoutExpectationHelper(); return createUnknownClosureTypeHelper(); }
/** * @noreference This method is not intended to be referenced by clients. */ protected FunctionTypeReference getFunctionTypeReference(boolean isProcedure) { XClosure closure = getClosure(); ITypeReferenceOwner referenceOwner = getExpectation().getReferenceOwner(); if (closure.isExplicitSyntax()) { int parameters = closure.getDeclaredFormalParameters().size(); FunctionTypeReference result = functionTypes.createRawFunctionTypeRef(referenceOwner, closure, parameters, isProcedure); initClosureType(result, isProcedure); return result; } else { FunctionTypeReference result = functionTypes.createRawFunctionTypeRef(referenceOwner, closure, 1, isProcedure); initClosureType(result, isProcedure); return result; } }
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; }
public JvmOperation findImplementingOperation(LightweightTypeReference functionType) { // avoid to trigger resolution of currently unbound type arguments // since the computation of this' lambdas type may enhance the information // about the given unbound type if (functionType.getKind() == LightweightTypeReference.KIND_UNBOUND_TYPE_REFERENCE && !functionType.isResolved()) { JvmOperation result = findImplementingOperation((UnboundTypeReference)functionType); if (result != null) { return result; } } List<JvmType> rawTypes = functionType.getRawTypes(); JvmOperation result = findImplementingOperation(rawTypes); return result; }
protected JvmOperation findImplementingOperation(LightweightTypeReference closureType) { return getTypeComputationServices().getFunctionTypes().findImplementingOperation(closureType); }
private JvmOperation findImplementingOperation(UnboundTypeReference unboundTypeReference) { List<LightweightBoundTypeArgument> hints = unboundTypeReference.getAllHints(); for(LightweightBoundTypeArgument hint: hints) { LightweightTypeReference hintReference = hint.getTypeReference(); if (hintReference != null && (hint.getSource() == BoundTypeArgumentSource.INFERRED || hint.getSource() == BoundTypeArgumentSource.INFERRED_EXPECTATION)) { List<JvmType> rawTypes = hintReference.getRawTypes(); JvmOperation result = findImplementingOperation(rawTypes); if (result != null) { return result; } } } return null; }
/** * This method is only public for testing purpose. * * @noreference This method is not intended to be referenced by clients. */ public void selectStrategy() { LightweightTypeReference expectedType = expectation.getExpectedType(); if (expectedType == null) { strategy = getClosureWithoutExpectationHelper(); } else { JvmOperation operation = functionTypes.findImplementingOperation(expectedType); JvmType type = expectedType.getType(); int closureParameterSize; if (closure.isExplicitSyntax()) { closureParameterSize = closure.getDeclaredFormalParameters().size(); } else if (operation != null) { closureParameterSize = operation.getParameters().size(); } else { closureParameterSize = 1; } if (operation == null || operation.getParameters().size() != closureParameterSize || type == null) { strategy = getClosureWithoutExpectationHelper(); } else { strategy = createClosureWithExpectationHelper(operation); } } }
if (declaredType != null && !declaredType.isType(Object.class)) { CommonTypeComputationServices services = getState().getReferenceOwner().getServices(); JvmOperation operation = services.getFunctionTypes().findImplementingOperation(declaredType); if (operation == null) { return false;
return; } else { JvmOperation operation = getServices().getFunctionTypes().findImplementingOperation(type); if (operation == null) { error("There is no context to infer the closure's argument types from. Consider typing the arguments or use the closures in a more specific context.",