JsDescriptorUtils#(isExtension, isOverride, getContainingClass) -> DescriptorUtils#(*)
This commit is contained in:
@@ -129,6 +129,14 @@ public class DescriptorUtils {
|
||||
return descriptor.getContainingDeclaration() instanceof PackageFragmentDescriptor;
|
||||
}
|
||||
|
||||
public static boolean isExtension(@NotNull CallableDescriptor descriptor) {
|
||||
return (descriptor.getExtensionReceiverParameter() != null);
|
||||
}
|
||||
|
||||
public static boolean isOverride(@NotNull CallableMemberDescriptor descriptor) {
|
||||
return !descriptor.getOverriddenDescriptors().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true iff this is a top-level declaration or a class member with no expected "this" object (e.g. static members in Java,
|
||||
* values() and valueOf() methods of enum classes, etc.)
|
||||
@@ -185,6 +193,18 @@ public class DescriptorUtils {
|
||||
return module;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ClassDescriptor getContainingClass(@NotNull DeclarationDescriptor descriptor) {
|
||||
DeclarationDescriptor containing = descriptor.getContainingDeclaration();
|
||||
while (containing != null) {
|
||||
if (containing instanceof ClassDescriptor && !isClassObject(containing)) {
|
||||
return (ClassDescriptor) containing;
|
||||
}
|
||||
containing = containing.getContainingDeclaration();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isAncestor(
|
||||
@Nullable DeclarationDescriptor ancestor,
|
||||
@NotNull DeclarationDescriptor declarationDescriptor,
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.jetbrains.k2js.translate.utils.JsAstUtils;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils.descriptorToDeclaration;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isExtension;
|
||||
import static org.jetbrains.k2js.config.LibrarySourcesConfig.BUILTINS_JS_MODULE_NAME;
|
||||
import static org.jetbrains.k2js.translate.utils.AnnotationsUtils.*;
|
||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.*;
|
||||
@@ -220,6 +221,7 @@ public final class StaticContext {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Config getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
+3
-3
@@ -115,7 +115,7 @@ public class DelegationTranslator(
|
||||
val delegateRefName = context().getScopeForDescriptor(getterDescriptor).declareName(delegateName)
|
||||
val delegateRef = JsNameRef(delegateRefName, JsLiteral.THIS)
|
||||
|
||||
val returnExpression = if (JsDescriptorUtils.isExtension(descriptor)) {
|
||||
val returnExpression = if (DescriptorUtils.isExtension(descriptor)) {
|
||||
val getterName = context().getNameForDescriptor(getterDescriptor)
|
||||
val receiver = Namer.getReceiverParameterName()
|
||||
JsInvocation(JsNameRef(getterName, delegateRef), JsNameRef(receiver))
|
||||
@@ -125,7 +125,7 @@ public class DelegationTranslator(
|
||||
}
|
||||
|
||||
val jsFunction = simpleReturnFunction(context().getScopeForDescriptor(getterDescriptor.getContainingDeclaration()), returnExpression)
|
||||
if (JsDescriptorUtils.isExtension(descriptor)) {
|
||||
if (DescriptorUtils.isExtension(descriptor)) {
|
||||
val receiverName = jsFunction.getScope().declareName(Namer.getReceiverParameterName())
|
||||
jsFunction.getParameters().add(JsParameter(receiverName))
|
||||
}
|
||||
@@ -143,7 +143,7 @@ public class DelegationTranslator(
|
||||
val delegateRefName = context().getScopeForDescriptor(setterDescriptor).declareName(delegateName)
|
||||
val delegateRef = JsNameRef(delegateRefName, JsLiteral.THIS)
|
||||
|
||||
val setExpression = if (JsDescriptorUtils.isExtension(descriptor)) {
|
||||
val setExpression = if (DescriptorUtils.isExtension(descriptor)) {
|
||||
val setterName = context().getNameForDescriptor(setterDescriptor)
|
||||
val setterNameRef = JsNameRef(setterName, delegateRef)
|
||||
val extensionFunctionReceiverName = jsFunction.getScope().declareName(Namer.getReceiverParameterName())
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.k2js.translate.utils.JsDescriptorUtils
|
||||
import org.jetbrains.k2js.translate.context.Namer.*
|
||||
import org.jetbrains.k2js.translate.utils.ast.*
|
||||
import org.jetbrains.k2js.translate.utils.TranslationUtils.*
|
||||
import org.jetbrains.k2js.translate.utils.JsDescriptorUtils.isExtension
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils.isExtension
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
|
||||
|
||||
/**
|
||||
@@ -64,7 +64,7 @@ public fun MutableList<JsPropertyInitializer>.addGetterAndSetter(
|
||||
generateSetter: () -> JsPropertyInitializer
|
||||
) {
|
||||
val to: MutableList<JsPropertyInitializer>
|
||||
if (!JsDescriptorUtils.isExtension(descriptor)) {
|
||||
if (!isExtension(descriptor)) {
|
||||
to = SmartList<JsPropertyInitializer>()
|
||||
this.add(JsPropertyInitializer(context.getNameForDescriptor(descriptor).makeRef(), JsObjectLiteral(to, true)))
|
||||
}
|
||||
|
||||
+6
-3
@@ -17,7 +17,10 @@
|
||||
package org.jetbrains.k2js.translate.expression;
|
||||
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.*;
|
||||
import com.google.dart.compiler.backend.js.ast.JsFunction;
|
||||
import com.google.dart.compiler.backend.js.ast.JsName;
|
||||
import com.google.dart.compiler.backend.js.ast.JsParameter;
|
||||
import com.google.dart.compiler.backend.js.ast.JsPropertyInitializer;
|
||||
import com.google.dart.compiler.backend.js.ast.metadata.MetadataPackage;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -28,11 +31,11 @@ import org.jetbrains.jet.lang.descriptors.Modality;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody;
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.k2js.translate.context.AliasingContext;
|
||||
import org.jetbrains.k2js.translate.context.Namer;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.k2js.translate.utils.JsDescriptorUtils;
|
||||
import org.jetbrains.k2js.translate.utils.TranslationUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -142,6 +145,6 @@ public final class FunctionTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
private boolean isExtensionFunction() {
|
||||
return JsDescriptorUtils.isExtension(descriptor) && !(functionDeclaration instanceof JetFunctionLiteralExpression);
|
||||
return DescriptorUtils.isExtension(descriptor) && !(functionDeclaration instanceof JetFunctionLiteralExpression);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ object CallableReferenceTranslator {
|
||||
|
||||
private fun isConstructor(descriptor: CallableDescriptor): Boolean = descriptor is ConstructorDescriptor
|
||||
|
||||
private fun isExtension(descriptor: CallableDescriptor): Boolean = JsDescriptorUtils.isExtension(descriptor)
|
||||
private fun isExtension(descriptor: CallableDescriptor): Boolean = DescriptorUtils.isExtension(descriptor)
|
||||
|
||||
private fun isMember(descriptor: CallableDescriptor): Boolean = JsDescriptorUtils.getContainingDeclaration(descriptor) is ClassDescriptor
|
||||
|
||||
|
||||
@@ -23,11 +23,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.JetTestFunctionDetector;
|
||||
import org.jetbrains.k2js.translate.reference.ReferenceTranslator;
|
||||
import org.jetbrains.k2js.translate.utils.JsDescriptorUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -47,7 +47,7 @@ public final class JSTestGenerator {
|
||||
private static void doGenerateTestCalls(@NotNull List<FunctionDescriptor> functionDescriptors,
|
||||
@NotNull TranslationContext context, @NotNull JSTester jsTester) {
|
||||
for (FunctionDescriptor functionDescriptor : functionDescriptors) {
|
||||
ClassDescriptor classDescriptor = JsDescriptorUtils.getContainingClass(functionDescriptor);
|
||||
ClassDescriptor classDescriptor = DescriptorUtils.getContainingClass(functionDescriptor);
|
||||
if (classDescriptor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,9 +32,6 @@ import org.jetbrains.k2js.PredefinedAnnotation;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.getContainingClass;
|
||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.isOverride;
|
||||
|
||||
public final class AnnotationsUtils {
|
||||
|
||||
private AnnotationsUtils() {
|
||||
@@ -49,7 +46,7 @@ public final class AnnotationsUtils {
|
||||
|
||||
@Nullable
|
||||
private static String getAnnotationStringParameter(@NotNull DeclarationDescriptor declarationDescriptor,
|
||||
@NotNull PredefinedAnnotation annotation) {
|
||||
@NotNull PredefinedAnnotation annotation) {
|
||||
AnnotationDescriptor annotationDescriptor = getAnnotationByName(declarationDescriptor, annotation);
|
||||
assert annotationDescriptor != null;
|
||||
//TODO: this is a quick fix for unsupported default args problem
|
||||
@@ -68,7 +65,7 @@ public final class AnnotationsUtils {
|
||||
|
||||
@Nullable
|
||||
public static String getNameForAnnotatedObject(@NotNull DeclarationDescriptor declarationDescriptor,
|
||||
@NotNull PredefinedAnnotation annotation) {
|
||||
@NotNull PredefinedAnnotation annotation) {
|
||||
if (!hasAnnotation(declarationDescriptor, annotation)) {
|
||||
return null;
|
||||
}
|
||||
@@ -80,7 +77,7 @@ public final class AnnotationsUtils {
|
||||
List<DeclarationDescriptor> descriptors;
|
||||
|
||||
if (declarationDescriptor instanceof CallableMemberDescriptor &&
|
||||
isOverride((CallableMemberDescriptor) declarationDescriptor)) {
|
||||
DescriptorUtils.isOverride((CallableMemberDescriptor) declarationDescriptor)) {
|
||||
|
||||
Set<CallableMemberDescriptor> overriddenDeclarations =
|
||||
DescriptorUtils.getAllOverriddenDeclarations((CallableMemberDescriptor) declarationDescriptor);
|
||||
@@ -88,7 +85,7 @@ public final class AnnotationsUtils {
|
||||
descriptors = ContainerUtil.mapNotNull(overriddenDeclarations, new Function<CallableMemberDescriptor, DeclarationDescriptor>() {
|
||||
@Override
|
||||
public DeclarationDescriptor fun(CallableMemberDescriptor descriptor) {
|
||||
return isOverride(descriptor) ? null : descriptor;
|
||||
return DescriptorUtils.isOverride(descriptor) ? null : descriptor;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -145,7 +142,7 @@ public final class AnnotationsUtils {
|
||||
if (getAnnotationByName(descriptor, fqn) != null) {
|
||||
return true;
|
||||
}
|
||||
ClassDescriptor containingClass = getContainingClass(descriptor);
|
||||
ClassDescriptor containingClass = DescriptorUtils.getContainingClass(descriptor);
|
||||
return containingClass != null && hasAnnotationOrInsideAnnotatedClass(containingClass, fqn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,14 +96,6 @@ public final class JsDescriptorUtils {
|
||||
return containing;
|
||||
}
|
||||
|
||||
public static boolean isExtension(@NotNull CallableDescriptor descriptor) {
|
||||
return (descriptor.getExtensionReceiverParameter() != null);
|
||||
}
|
||||
|
||||
public static boolean isOverride(@NotNull CallableMemberDescriptor descriptor) {
|
||||
return !descriptor.getOverriddenDescriptors().isEmpty();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ReceiverParameterDescriptor getReceiverParameterForReceiver(@NotNull ReceiverValue receiverParameter) {
|
||||
DeclarationDescriptor declarationDescriptor = getDeclarationDescriptorForReceiver(receiverParameter);
|
||||
@@ -135,19 +127,6 @@ public final class JsDescriptorUtils {
|
||||
", declarationDescriptor = " + declarationDescriptor);
|
||||
}
|
||||
|
||||
//TODO: maybe we have similar routine
|
||||
@Nullable
|
||||
public static ClassDescriptor getContainingClass(@NotNull DeclarationDescriptor descriptor) {
|
||||
DeclarationDescriptor containing = descriptor.getContainingDeclaration();
|
||||
while (containing != null) {
|
||||
if (containing instanceof ClassDescriptor && !isClassObject(containing)) {
|
||||
return (ClassDescriptor) containing;
|
||||
}
|
||||
containing = containing.getContainingDeclaration();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FunctionDescriptor getOverriddenDescriptor(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
Set<? extends FunctionDescriptor> overriddenDescriptors = functionDescriptor.getOverriddenDescriptors();
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ManglingUtils {
|
||||
String suggestedName = descriptor.getName().asString();
|
||||
|
||||
if (descriptor instanceof FunctionDescriptor ||
|
||||
descriptor instanceof PropertyDescriptor && JsDescriptorUtils.isExtension((PropertyDescriptor) descriptor)
|
||||
descriptor instanceof PropertyDescriptor && DescriptorUtils.isExtension((PropertyDescriptor) descriptor)
|
||||
) {
|
||||
suggestedName = getMangledName((CallableMemberDescriptor) descriptor);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class ManglingUtils {
|
||||
private static boolean needsStableMangling(CallableMemberDescriptor descriptor) {
|
||||
// Use stable mangling for overrides because we use stable mangling when any function inside a overridable declaration
|
||||
// for avoid clashing names when inheritance.
|
||||
if (JsDescriptorUtils.isOverride(descriptor)) {
|
||||
if (DescriptorUtils.isOverride(descriptor)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
@@ -53,7 +54,7 @@ public final class TranslationUtils {
|
||||
public static JsPropertyInitializer translateFunctionAsEcma5PropertyDescriptor(@NotNull JsFunction function,
|
||||
@NotNull FunctionDescriptor descriptor,
|
||||
@NotNull TranslationContext context) {
|
||||
if (JsDescriptorUtils.isExtension(descriptor)) {
|
||||
if (DescriptorUtils.isExtension(descriptor)) {
|
||||
return translateExtensionFunctionAsEcma5DataDescriptor(function, descriptor, context);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.k2js.translate.context.Namer
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext
|
||||
import org.jetbrains.k2js.translate.utils.TranslationUtils.simpleReturnFunction
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
||||
|
||||
public val <T> ID: (T) -> T = { it }
|
||||
|
||||
@@ -43,7 +44,7 @@ public fun generateDelegateCall(
|
||||
val args = SmartList<JsExpression>()
|
||||
val functionScope = context.getScopeForDescriptor(fromDescriptor);
|
||||
|
||||
if (JsDescriptorUtils.isExtension(fromDescriptor)) {
|
||||
if (DescriptorUtils.isExtension(fromDescriptor)) {
|
||||
val extensionFunctionReceiverName = functionScope.declareName(Namer.getReceiverParameterName())
|
||||
parameters.add(JsParameter(extensionFunctionReceiverName))
|
||||
args.add(JsNameRef(extensionFunctionReceiverName))
|
||||
|
||||
Reference in New Issue
Block a user