Move util backend function isNamedFun && isNamedFunOrLambda to frontend

This commit is contained in:
Stanislav Erokhin
2015-02-24 15:36:06 +03:00
parent fa9ca54e78
commit 6fb8af1dda
11 changed files with 88 additions and 46 deletions
@@ -0,0 +1,35 @@
/*
* Copyright 2010-2015 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.kotlin.descriptors.impl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.descriptors.SourceElement;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.name.Name;
public class FunctionExpressionDescriptor extends SimpleFunctionDescriptorImpl {
public FunctionExpressionDescriptor(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull Annotations annotations,
@NotNull Name name,
@NotNull Kind kind,
@NotNull SourceElement source
) {
super(containingDeclaration, null, annotations, name, kind, source);
}
}
@@ -22,6 +22,8 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor;
import org.jetbrains.kotlin.descriptors.impl.FunctionExpressionDescriptor;
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.FqNameUnsafe;
import org.jetbrains.kotlin.name.Name;
@@ -236,10 +238,21 @@ public class DescriptorUtils {
return false;
}
public static boolean isFunctionLiteral(@NotNull FunctionDescriptor descriptor) {
public static boolean isFunctionLiteral(@Nullable DeclarationDescriptor descriptor) {
return descriptor instanceof AnonymousFunctionDescriptor;
}
public static boolean isLocalFunction(@Nullable DeclarationDescriptor descriptor) {
if (descriptor != null && descriptor.getClass() == SimpleFunctionDescriptorImpl.class) {
return ((SimpleFunctionDescriptorImpl) descriptor).getVisibility() == Visibilities.LOCAL;
}
return false;
}
public static boolean isFunctionExpression(@Nullable DeclarationDescriptor descriptor) {
return descriptor instanceof FunctionExpressionDescriptor;
}
public static boolean isDefaultObject(@Nullable DeclarationDescriptor descriptor) {
return isKindOf(descriptor, ClassKind.OBJECT) && ((ClassDescriptor) descriptor).isDefaultObject();
}