diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/impl/AnonymousFunctionDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/impl/AnonymousFunctionDescriptor.java new file mode 100644 index 00000000000..0ba01680c4f --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/impl/AnonymousFunctionDescriptor.java @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.descriptors.impl; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.resolve.name.Name; + +import java.util.List; + +public class AnonymousFunctionDescriptor extends SimpleFunctionDescriptorImpl { + public AnonymousFunctionDescriptor( + @NotNull DeclarationDescriptor containingDeclaration, + @NotNull List annotations, + @NotNull Kind kind + ) { + super(containingDeclaration, annotations, Name.special(""), kind); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java index 33203194794..d50e8702e03 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java @@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor; import org.jetbrains.jet.lang.descriptors.impl.NamespaceDescriptorParent; import org.jetbrains.jet.lang.psi.JetElement; import org.jetbrains.jet.lang.psi.JetFunction; @@ -264,6 +265,10 @@ public class DescriptorUtils { } } + public static boolean isFunctionLiteral(@NotNull FunctionDescriptor descriptor) { + return descriptor instanceof AnonymousFunctionDescriptor; + } + public static boolean isClassObject(@NotNull DeclarationDescriptor descriptor) { return descriptor instanceof ClassDescriptor && ((ClassDescriptor) descriptor).getKind() == ClassKind.CLASS_OBJECT; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java index c6d17629e2c..052ce5f1aa4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java @@ -28,7 +28,10 @@ import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.JetScope; -import org.jetbrains.jet.lang.types.*; +import org.jetbrains.jet.lang.types.DeferredType; +import org.jetbrains.jet.lang.types.ErrorUtils; +import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.lang.types.JetTypeInfo; import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.util.lazy.RecursionIntolerantLazyValueWithDefault; @@ -98,7 +101,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor { boolean functionTypeExpected = expectedType != NO_EXPECTED_TYPE && KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType( expectedType); - SimpleFunctionDescriptorImpl functionDescriptor = createFunctionDescriptor(expression, context, functionTypeExpected); + AnonymousFunctionDescriptor functionDescriptor = createFunctionDescriptor(expression, context, functionTypeExpected); JetType safeReturnType = computeReturnType(expression, context, functionDescriptor, functionTypeExpected); functionDescriptor.setReturnType(safeReturnType); @@ -114,15 +117,15 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor { } @NotNull - private static SimpleFunctionDescriptorImpl createFunctionDescriptor( + private static AnonymousFunctionDescriptor createFunctionDescriptor( @NotNull JetFunctionLiteralExpression expression, @NotNull ExpressionTypingContext context, boolean functionTypeExpected ) { JetFunctionLiteral functionLiteral = expression.getFunctionLiteral(); JetTypeReference receiverTypeRef = functionLiteral.getReceiverTypeRef(); - SimpleFunctionDescriptorImpl functionDescriptor = new SimpleFunctionDescriptorImpl( - context.scope.getContainingDeclaration(), Collections.emptyList(), Name.special(""), CallableMemberDescriptor.Kind.DECLARATION); + AnonymousFunctionDescriptor functionDescriptor = new AnonymousFunctionDescriptor( + context.scope.getContainingDeclaration(), Collections.emptyList(), CallableMemberDescriptor.Kind.DECLARATION); List valueParameterDescriptors = createValueParameterDescriptors(context, functionLiteral, functionDescriptor, functionTypeExpected);