Utilities in JsDescriptorUtils.
Adapted from https://github.com/develar/kotlin/commit/a9e0a42fb1347fa8e21c86b5a073ef8a7c873da0.
This commit is contained in:
@@ -19,11 +19,19 @@ package org.jetbrains.k2js.translate.utils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -145,6 +153,35 @@ public final class JsDescriptorUtils {
|
||||
!isDefaultAccessor(propertyDescriptor.getSetter());
|
||||
}
|
||||
|
||||
public static boolean isStandardDeclaration(@NotNull DeclarationDescriptor descriptor) {
|
||||
NamespaceDescriptor namespace = getContainingNamespace(descriptor);
|
||||
if (namespace == null) {
|
||||
return false;
|
||||
}
|
||||
return namespace.equals(JetStandardLibrary.getInstance().getLibraryScope().getContainingDeclaration());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static NamespaceDescriptor getContainingNamespace(@NotNull DeclarationDescriptor descriptor) {
|
||||
return DescriptorUtils.getParentOfType(descriptor, NamespaceDescriptor.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Name getNameIfStandardType(@NotNull JetExpression expression, @NotNull TranslationContext context) {
|
||||
JetType type = context.bindingContext().get(BindingContext.EXPRESSION_TYPE, expression);
|
||||
return type != null ? getNameIfStandardType(type) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Name getNameIfStandardType(@NotNull JetType type) {
|
||||
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
if (descriptor != null && descriptor.getContainingDeclaration() == JetStandardClasses.STANDARD_CLASSES_NAMESPACE) {
|
||||
return descriptor.getName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static DeclarationDescriptor getDeclarationDescriptorForExtensionCallReceiver(
|
||||
@NotNull ResolvedCall<? extends CallableDescriptor> resolvedCall
|
||||
|
||||
Reference in New Issue
Block a user