JS backend: Use new CallTranslator for build main and test calls
This commit is contained in:
@@ -38,7 +38,7 @@ import org.jetbrains.k2js.translate.declaration.PackageDeclarationTranslator;
|
||||
import org.jetbrains.k2js.translate.expression.ExpressionVisitor;
|
||||
import org.jetbrains.k2js.translate.expression.FunctionTranslator;
|
||||
import org.jetbrains.k2js.translate.expression.PatternTranslator;
|
||||
import org.jetbrains.k2js.translate.reference.CallBuilder;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
import org.jetbrains.k2js.translate.test.JSTestGenerator;
|
||||
import org.jetbrains.k2js.translate.test.JSTester;
|
||||
import org.jetbrains.k2js.translate.utils.JsAstUtils;
|
||||
@@ -46,6 +46,7 @@ import org.jetbrains.k2js.translate.utils.dangerous.DangerousData;
|
||||
import org.jetbrains.k2js.translate.utils.dangerous.DangerousTranslator;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.plugin.JetMainDetector.getMainFunction;
|
||||
@@ -174,9 +175,7 @@ public final class Translation {
|
||||
return null;
|
||||
}
|
||||
FunctionDescriptor functionDescriptor = getFunctionDescriptor(context.bindingContext(), mainFunction);
|
||||
return CallBuilder.build(context)
|
||||
.args(new JsArrayLiteral(toStringLiteralList(arguments, context.program())))
|
||||
.descriptor(functionDescriptor)
|
||||
.translate().makeStmt();
|
||||
JsArrayLiteral argument = new JsArrayLiteral(toStringLiteralList(arguments, context.program()));
|
||||
return ReferencePackage.buildFakeCall(context, functionDescriptor, Collections.singletonList(argument), null).makeStmt();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,22 @@ fun TranslationContext.buildSet(resolvedCall: ResolvedCall<out VariableDescripto
|
||||
return variableAccessCases.translate(variableAccessInfo)
|
||||
}
|
||||
|
||||
fun TranslationContext.buildFakeCall(functionDescriptor: FunctionDescriptor, args: List<JsExpression>, thisObject: JsExpression?): JsExpression {
|
||||
val fakeCallInfo = object: CallInfo {
|
||||
override val context: TranslationContext = this@buildFakeCall
|
||||
override val resolvedCall: ResolvedCall<out CallableDescriptor>
|
||||
get() {
|
||||
throw UnsupportedOperationException("Resolved call for direct call unsupported")
|
||||
}
|
||||
override val callableDescriptor: CallableDescriptor = functionDescriptor
|
||||
override val thisObject: JsExpression? = thisObject
|
||||
override val receiverObject: JsExpression? = null
|
||||
override val nullableReceiverForSafeCall: JsExpression? = null
|
||||
}
|
||||
val fakeFunctionInfo = FunctionCallInfo(fakeCallInfo, CallArgumentTranslator.ArgumentsInfo(args, false, null));
|
||||
return DefaultCallCase(fakeFunctionInfo).translate()
|
||||
}
|
||||
|
||||
private fun TranslationContext.buildCall(resolvedCall: ResolvedCall<out FunctionDescriptor>, receiver1: JsExpression?, receiver2: JsExpression?): JsExpression {
|
||||
if (resolvedCall is VariableAsFunctionResolvedCall) {
|
||||
assert(receiver2 == null, "receiver2 for VariableAsFunctionResolvedCall must be null") // TODO: add debug info
|
||||
|
||||
@@ -25,11 +25,12 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.JetTestFunctionDetector;
|
||||
import org.jetbrains.k2js.translate.reference.CallBuilder;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
import org.jetbrains.k2js.translate.reference.ReferenceTranslator;
|
||||
import org.jetbrains.k2js.translate.utils.JsDescriptorUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
//TODO: use method object instead of static functions
|
||||
@@ -59,7 +60,7 @@ public final class JSTestGenerator {
|
||||
@NotNull ClassDescriptor classDescriptor, @NotNull JSTester tester) {
|
||||
JsExpression expression = ReferenceTranslator.translateAsFQReference(classDescriptor, context);
|
||||
JsNew testClass = new JsNew(expression);
|
||||
JsExpression functionToTestCall = CallBuilder.build(context).descriptor(functionDescriptor).receiver(testClass).translate();
|
||||
JsExpression functionToTestCall = ReferencePackage.buildFakeCall(context, functionDescriptor, Collections.<JsExpression>emptyList(), testClass);
|
||||
JsStringLiteral testName = context.program().getStringLiteral(classDescriptor.getName() + "." + functionDescriptor.getName());
|
||||
tester.constructTestMethodInvocation(functionToTestCall, testName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user