rename isFunctionType -> isFunctionOrExtensionFunctionType

added isFunctionType, isExtensionFunctionType
This commit is contained in:
Svetlana Isakova
2012-12-27 18:24:11 +04:00
parent 21f6d1630d
commit a6bfa1ff6c
9 changed files with 25 additions and 16 deletions
@@ -127,7 +127,7 @@ public class FunctionDescriptorUtil {
@NotNull Visibility visibility
) {
assert KotlinBuiltIns.getInstance().isFunctionType(functionType);
assert KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(functionType);
functionDescriptor.initialize(KotlinBuiltIns.getInstance().getReceiverType(functionType),
expectedThisObject,
Collections.<TypeParameterDescriptorImpl>emptyList(),
@@ -142,7 +142,7 @@ public class FunctionDescriptorUtil {
}
public static FunctionDescriptor getInvokeFunction(@NotNull JetType functionType) {
assert KotlinBuiltIns.getInstance().isFunctionType(functionType);
assert KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(functionType);
ClassifierDescriptor classDescriptorForFunction = functionType.getConstructor().getDeclarationDescriptor();
assert classDescriptorForFunction instanceof ClassDescriptor;
@@ -79,7 +79,7 @@ public class ArgumentTypeResolver {
}
private static boolean isFunctionOrErrorType(@NotNull JetType supertype) {
return KotlinBuiltIns.getInstance().isFunctionType(supertype) || ErrorUtils.isErrorType(supertype);
return KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(supertype) || ErrorUtils.isErrorType(supertype);
}
public void checkTypesWithNoCallee(@NotNull ResolutionContext context) {
@@ -50,7 +50,6 @@ import java.util.*;
import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveMode;
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveMode.RESOLVE_FUNCTION_ARGUMENTS;
import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER;
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
@@ -231,7 +230,7 @@ public class CallResolver {
// Here we handle the case where the callee expression must be something of type function, e.g. (foo.bar())(1, 2)
JetType calleeType = expressionTypingServices.safeGetType(context.scope, calleeExpression, NO_EXPECTED_TYPE, context.dataFlowInfo, context.trace); // We are actually expecting a function, but there seems to be no easy way of expressing this
if (!KotlinBuiltIns.getInstance().isFunctionType(calleeType)) {
if (!KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(calleeType)) {
// checkTypesWithNoCallee(trace, scope, call);
if (!ErrorUtils.isErrorType(calleeType)) {
context.trace.report(CALLEE_NOT_A_FUNCTION.on(calleeExpression, calleeType));
@@ -178,7 +178,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
if (ErrorUtils.isErrorType(subjectType)) return;
if (constrainingType == PLACEHOLDER_FUNCTION_TYPE) {
if (!KotlinBuiltIns.getInstance().isFunctionType(subjectType)) {
if (!KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(subjectType)) {
errorConstraintPositions.add(constraintPosition);
}
return;
@@ -97,7 +97,8 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
if (bodyExpression == null) return null;
JetType expectedType = context.expectedType;
boolean functionTypeExpected = expectedType != NO_EXPECTED_TYPE && KotlinBuiltIns.getInstance().isFunctionType(expectedType);
boolean functionTypeExpected = expectedType != NO_EXPECTED_TYPE && KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(
expectedType);
SimpleFunctionDescriptorImpl functionDescriptor = createFunctionDescriptor(expression, context, functionTypeExpected);
JetType safeReturnType = computeReturnType(expression, context, functionDescriptor, functionTypeExpected);
@@ -107,7 +108,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
List<JetType> valueParametersTypes = DescriptorUtils.getValueParametersTypes(functionDescriptor.getValueParameters());
JetType resultType = KotlinBuiltIns.getInstance().getFunctionType(
Collections.<AnnotationDescriptor>emptyList(), receiver, valueParametersTypes, safeReturnType);
if (expectedType != NO_EXPECTED_TYPE && KotlinBuiltIns.getInstance().isFunctionType(expectedType)) {
if (expectedType != NO_EXPECTED_TYPE && KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(expectedType)) {
// all checks were done before
return JetTypeInfo.create(resultType, context.dataFlowInfo);
}
@@ -846,13 +846,21 @@ public class KotlinBuiltIns {
return builder.build();
}
public boolean isFunctionOrExtensionFunctionType(@NotNull JetType type) {
return isFunctionType(type) || isExtensionFunctionType(type);
}
public boolean isFunctionType(@NotNull JetType type) {
return setContainsClassOf(functionClassesSet, type) || setContainsClassOf(extensionFunctionClassesSet, type);
return setContainsClassOf(functionClassesSet, type);
}
public boolean isExtensionFunctionType(@NotNull JetType type) {
return setContainsClassOf(extensionFunctionClassesSet, type);
}
@Nullable
public JetType getReceiverType(@NotNull JetType type) {
assert isFunctionType(type) : type;
assert isFunctionOrExtensionFunctionType(type) : type;
if (setContainsClassOf(extensionFunctionClassesSet, type)) {
return type.getArguments().get(0).getType();
}
@@ -861,7 +869,7 @@ public class KotlinBuiltIns {
@NotNull
public List<ValueParameterDescriptor> getValueParameters(@NotNull FunctionDescriptor functionDescriptor, @NotNull JetType type) {
assert isFunctionType(type);
assert isFunctionOrExtensionFunctionType(type);
List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
List<TypeProjection> parameterTypes = getParameterTypeProjectionsFromFunctionType(type);
for (int i = 0; i < parameterTypes.size(); i++) {
@@ -876,14 +884,14 @@ public class KotlinBuiltIns {
@NotNull
public JetType getReturnTypeFromFunctionType(@NotNull JetType type) {
assert isFunctionType(type);
assert isFunctionOrExtensionFunctionType(type);
List<TypeProjection> arguments = type.getArguments();
return arguments.get(arguments.size() - 1).getType();
}
@NotNull
public List<TypeProjection> getParameterTypeProjectionsFromFunctionType(@NotNull JetType type) {
assert isFunctionType(type);
assert isFunctionOrExtensionFunctionType(type);
List<TypeProjection> arguments = type.getArguments();
int first = setContainsClassOf(extensionFunctionClassesSet, type) ? 1 : 0;
int last = arguments.size() - 2;
@@ -166,7 +166,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
else if (KotlinBuiltIns.getInstance().isUnit(type)) {
return KotlinBuiltIns.UNIT_ALIAS + (type.isNullable() ? "?" : "");
}
else if (KotlinBuiltIns.getInstance().isFunctionType(type)) {
else if (KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(type)) {
return renderFunctionType(type);
}
return renderDefaultType(type);
@@ -54,7 +54,7 @@ public class JetPluginUtil {
public static boolean checkTypeIsStandard(JetType type, Project project) {
if (KotlinBuiltIns.getInstance().isAny(type) || KotlinBuiltIns.getInstance().isNothingOrNullableNothing(type) || KotlinBuiltIns.getInstance().isUnit(type) ||
KotlinBuiltIns.getInstance().isTupleType(type) || KotlinBuiltIns.getInstance().isFunctionType(type)) {
KotlinBuiltIns.getInstance().isTupleType(type) || KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(type)) {
return true;
}
@@ -129,7 +129,8 @@ public final class DescriptorLookupConverter {
}
if (functionDescriptor.getValueParameters().size() == 1
&& KotlinBuiltIns.getInstance().isFunctionType(functionDescriptor.getValueParameters().get(0).getType())) {
&& KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(
functionDescriptor.getValueParameters().get(0).getType())) {
return PARAMS_BRACES_FUNCTION_HANDLER;
}