JS backend: Move CallTranslator to new package & create CallTranslator object
This commit is contained in:
+2
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.translate.reference
|
||||
package org.jetbrains.k2js.translate.callTranslator
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
|
||||
@@ -34,6 +34,7 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils
|
||||
import com.google.dart.compiler.backend.js.ast.JsNameRef
|
||||
import org.jetbrains.k2js.translate.utils.JsAstUtils
|
||||
import org.jetbrains.k2js.translate.context.Namer
|
||||
import org.jetbrains.k2js.translate.reference.CallArgumentTranslator
|
||||
|
||||
|
||||
trait CallInfo {
|
||||
+2
-1
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.k2js.translate.reference
|
||||
package org.jetbrains.k2js.translate.callTranslator
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
|
||||
import org.jetbrains.k2js.translate.utils.AnnotationsUtils
|
||||
@@ -26,6 +26,7 @@ import org.jetbrains.k2js.translate.context.Namer
|
||||
import com.google.dart.compiler.backend.js.ast.JsNameRef
|
||||
import org.jetbrains.k2js.translate.utils.JsAstUtils
|
||||
import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind.*
|
||||
import org.jetbrains.k2js.translate.reference.CallType
|
||||
|
||||
|
||||
val CallInfo.callableDescriptor: CallableDescriptor
|
||||
+48
-29
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.translate.reference
|
||||
package org.jetbrains.k2js.translate.callTranslator
|
||||
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||
@@ -32,31 +32,47 @@ import org.jetbrains.k2js.translate.context.Namer
|
||||
import org.jetbrains.k2js.translate.utils.ErrorReportingUtils
|
||||
import org.jetbrains.k2js.translate.utils.AnnotationsUtils
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils
|
||||
import org.jetbrains.k2js.translate.reference.CallArgumentTranslator
|
||||
|
||||
object CallTranslator {
|
||||
fun translate(context: TranslationContext,
|
||||
resolvedCall: ResolvedCall<out FunctionDescriptor>,
|
||||
receiverOrThisObject: JsExpression? = null
|
||||
): JsExpression {
|
||||
return translateCall(context, resolvedCall, ExplicitReceivers(receiverOrThisObject))
|
||||
}
|
||||
|
||||
fun TranslationContext.buildCall(resolvedCall: ResolvedCall<out FunctionDescriptor>, receiverOrThisObject: JsExpression? = null): JsExpression {
|
||||
return buildCall(resolvedCall, ExplicitReceivers(receiverOrThisObject))
|
||||
}
|
||||
fun translateGet(context: TranslationContext,
|
||||
resolvedCall: ResolvedCall<out VariableDescriptor>,
|
||||
receiverOrThisObject: JsExpression? = null
|
||||
): JsExpression {
|
||||
val variableAccessInfo = VariableAccessInfo(context.getCallInfo(resolvedCall, receiverOrThisObject), null);
|
||||
return variableAccessInfo.translateVariableAccess()
|
||||
}
|
||||
|
||||
fun TranslationContext.buildGet(resolvedCall: ResolvedCall<out VariableDescriptor>, receiverOrThisObject: JsExpression? = null): JsExpression {
|
||||
val variableAccessInfo = VariableAccessInfo(getCallInfo(resolvedCall, receiverOrThisObject), null);
|
||||
return variableAccessInfo.translateVariableAccess()
|
||||
}
|
||||
fun translateSet(context: TranslationContext,
|
||||
resolvedCall: ResolvedCall<out VariableDescriptor>,
|
||||
value: JsExpression,
|
||||
receiverOrThisObject: JsExpression? = null
|
||||
): JsExpression {
|
||||
val variableAccessInfo = VariableAccessInfo(context.getCallInfo(resolvedCall, receiverOrThisObject), value);
|
||||
return variableAccessInfo.translateVariableAccess()
|
||||
}
|
||||
|
||||
fun TranslationContext.buildSet(resolvedCall: ResolvedCall<out VariableDescriptor>, value: JsExpression, receiverOrThisObject: JsExpression? = null): JsExpression {
|
||||
val variableAccessInfo = VariableAccessInfo(getCallInfo(resolvedCall, receiverOrThisObject), value);
|
||||
return variableAccessInfo.translateVariableAccess()
|
||||
}
|
||||
|
||||
fun TranslationContext.buildFakeCall(functionDescriptor: FunctionDescriptor, args: List<JsExpression>, thisObject: JsExpression?): JsExpression {
|
||||
val argumentsInfo = CallArgumentTranslator.ArgumentsInfo(args, false, null);
|
||||
val functionName = getNameForDescriptor(functionDescriptor)
|
||||
val isNative = AnnotationsUtils.isNativeObject(functionDescriptor)
|
||||
val hasSpreadOperator = false
|
||||
if (thisObject != null) {
|
||||
return DefaultFunctionCallCase.buildDefaultCallWithThisObject(argumentsInfo, thisObject, functionName, isNative, hasSpreadOperator)
|
||||
} else {
|
||||
return DefaultFunctionCallCase.buildDefaultCallWithoutReceiver(this, argumentsInfo, functionDescriptor, functionName, isNative, hasSpreadOperator)
|
||||
fun buildCall(context: TranslationContext,
|
||||
functionDescriptor: FunctionDescriptor,
|
||||
args: List<JsExpression>,
|
||||
thisObject: JsExpression?
|
||||
): JsExpression {
|
||||
val argumentsInfo = CallArgumentTranslator.ArgumentsInfo(args, false, null);
|
||||
val functionName = context.getNameForDescriptor(functionDescriptor)
|
||||
val isNative = AnnotationsUtils.isNativeObject(functionDescriptor)
|
||||
val hasSpreadOperator = false
|
||||
if (thisObject != null) {
|
||||
return DefaultFunctionCallCase.buildDefaultCallWithThisObject(argumentsInfo, thisObject, functionName, isNative, hasSpreadOperator)
|
||||
} else {
|
||||
return DefaultFunctionCallCase.buildDefaultCallWithoutReceiver(context, argumentsInfo, functionDescriptor, functionName, isNative, hasSpreadOperator)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,23 +80,26 @@ private fun ResolvedCall<out CallableDescriptor>.expectedReceivers(): Boolean {
|
||||
return this.getExplicitReceiverKind() != NO_EXPLICIT_RECEIVER
|
||||
}
|
||||
|
||||
private fun TranslationContext.buildCall(resolvedCall: ResolvedCall<out FunctionDescriptor>, explicitReceivers: ExplicitReceivers): JsExpression {
|
||||
private fun translateCall(context: TranslationContext,
|
||||
resolvedCall: ResolvedCall<out FunctionDescriptor>,
|
||||
explicitReceivers: ExplicitReceivers
|
||||
): JsExpression {
|
||||
if (resolvedCall is VariableAsFunctionResolvedCall) {
|
||||
assert(explicitReceivers.receiverObject == null, "VariableAsFunctionResolvedCall must have one receiver")
|
||||
val variableCall = resolvedCall.getVariableCall()
|
||||
if (variableCall.expectedReceivers()) {
|
||||
val newReceiver = buildGet(variableCall, explicitReceivers.receiverOrThisObject)
|
||||
return buildCall(resolvedCall.getFunctionCall(), ExplicitReceivers(newReceiver))
|
||||
val newReceiver = CallTranslator.translateGet(context, variableCall, explicitReceivers.receiverOrThisObject)
|
||||
return translateCall(context, resolvedCall.getFunctionCall(), ExplicitReceivers(newReceiver))
|
||||
} else {
|
||||
val thisObject = buildGet(variableCall, null)
|
||||
val thisObject = CallTranslator.translateGet(context, variableCall, null)
|
||||
if (explicitReceivers.receiverOrThisObject == null)
|
||||
return buildCall(resolvedCall.getFunctionCall(), ExplicitReceivers(thisObject))
|
||||
return translateCall(context, resolvedCall.getFunctionCall(), ExplicitReceivers(thisObject))
|
||||
else
|
||||
return buildCall(resolvedCall.getFunctionCall(), ExplicitReceivers(thisObject, explicitReceivers.receiverOrThisObject))
|
||||
return translateCall(context, resolvedCall.getFunctionCall(), ExplicitReceivers(thisObject, explicitReceivers.receiverOrThisObject))
|
||||
}
|
||||
}
|
||||
|
||||
val functionCallInfo = getCallInfo(resolvedCall, explicitReceivers)
|
||||
val functionCallInfo = context.getCallInfo(resolvedCall, explicitReceivers)
|
||||
return functionCallInfo.translateFunctionCall()
|
||||
}
|
||||
|
||||
+2
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.translate.reference
|
||||
package org.jetbrains.k2js.translate.callTranslator
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression
|
||||
import com.google.dart.compiler.backend.js.ast.JsNameRef
|
||||
@@ -35,6 +35,7 @@ import org.jetbrains.k2js.translate.utils.PsiUtils
|
||||
import com.google.dart.compiler.backend.js.ast.JsLiteral
|
||||
import com.google.dart.compiler.backend.js.ast.JsName
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext
|
||||
import org.jetbrains.k2js.translate.reference.CallArgumentTranslator
|
||||
|
||||
public fun addReceiverToArgs(receiver: JsExpression, arguments: List<JsExpression>) : List<JsExpression> {
|
||||
if (arguments.isEmpty())
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.translate.reference
|
||||
package org.jetbrains.k2js.translate.callTranslator
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression
|
||||
import com.google.dart.compiler.backend.js.ast.JsNameRef
|
||||
+3
-3
@@ -25,11 +25,11 @@ import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.expression.FunctionTranslator;
|
||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.k2js.translate.general.Translation;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
import org.jetbrains.k2js.translate.utils.JsDescriptorUtils;
|
||||
import org.jetbrains.k2js.translate.utils.TranslationUtils;
|
||||
|
||||
@@ -141,7 +141,7 @@ public final class PropertyTranslator extends AbstractTranslator {
|
||||
JsExpression value;
|
||||
ResolvedCall<FunctionDescriptor> delegatedCall = bindingContext().get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, getterDescriptor);
|
||||
if (delegatedCall != null) {
|
||||
value = ReferencePackage.buildCall(context(), delegatedCall, getDelegateNameRef(getPropertyName()));
|
||||
value = CallTranslator.instance$.translate(context(), delegatedCall, getDelegateNameRef(getPropertyName()));
|
||||
} else {
|
||||
value = backingFieldReference(context(), this.descriptor);
|
||||
}
|
||||
@@ -171,7 +171,7 @@ public final class PropertyTranslator extends AbstractTranslator {
|
||||
ResolvedCall<FunctionDescriptor> delegatedCall = bindingContext().get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL,
|
||||
setterDescriptor);
|
||||
if (delegatedCall != null) {
|
||||
setExpression = ReferencePackage.buildCall(contextWithAliased, delegatedCall, getDelegateNameRef(getPropertyName()));
|
||||
setExpression = CallTranslator.instance$.translate(contextWithAliased, delegatedCall, getDelegateNameRef(getPropertyName()));
|
||||
} else {
|
||||
setExpression = assignmentToBackingField(contextWithAliased, descriptor, defaultParameterRef);
|
||||
}
|
||||
|
||||
+2
-2
@@ -29,9 +29,9 @@ import org.jetbrains.jet.lang.psi.JetMultiDeclarationEntry;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -78,7 +78,7 @@ public class MultiDeclarationTranslator extends AbstractTranslator {
|
||||
for (JetMultiDeclarationEntry entry : multiDeclaration.getEntries()) {
|
||||
ResolvedCall<FunctionDescriptor> entryInitCall = context().bindingContext().get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
|
||||
assert entryInitCall != null : "Entry init call must be not null";
|
||||
JsExpression entryInitializer = ReferencePackage.buildCall(context(), entryInitCall, multiObjNameRef);
|
||||
JsExpression entryInitializer = CallTranslator.instance$.translate(context(), entryInitCall, multiObjNameRef);
|
||||
|
||||
VariableDescriptor descriptor = BindingContextUtils.getNotNull( context().bindingContext(), BindingContext.VARIABLE, entry);
|
||||
JsName name = context().getNameForDescriptor(descriptor);
|
||||
|
||||
+2
-2
@@ -24,9 +24,9 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetForExpression;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.Translation;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.*;
|
||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.getLoopRange;
|
||||
@@ -73,6 +73,6 @@ public final class IteratorForTranslator extends ForTranslator {
|
||||
@NotNull
|
||||
private JsExpression translateMethodInvocation(@Nullable JsExpression receiver,
|
||||
@NotNull ResolvedCall<FunctionDescriptor> resolvedCall) {
|
||||
return ReferencePackage.buildCall(context(), resolvedCall, receiver);
|
||||
return CallTranslator.instance$.translate(context(), resolvedCall, receiver);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.jetbrains.k2js.facade.exceptions.MainFunctionNotFoundException;
|
||||
import org.jetbrains.k2js.facade.exceptions.TranslationException;
|
||||
import org.jetbrains.k2js.facade.exceptions.TranslationInternalException;
|
||||
import org.jetbrains.k2js.facade.exceptions.UnsupportedFeatureException;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.context.Namer;
|
||||
import org.jetbrains.k2js.translate.context.StaticContext;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
@@ -38,7 +39,6 @@ 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.ReferencePackage;
|
||||
import org.jetbrains.k2js.translate.test.JSTestGenerator;
|
||||
import org.jetbrains.k2js.translate.test.JSTester;
|
||||
import org.jetbrains.k2js.translate.utils.JsAstUtils;
|
||||
@@ -176,6 +176,6 @@ public final class Translation {
|
||||
}
|
||||
FunctionDescriptor functionDescriptor = getFunctionDescriptor(context.bindingContext(), mainFunction);
|
||||
JsArrayLiteral argument = new JsArrayLiteral(toStringLiteralList(arguments, context.program()));
|
||||
return ReferencePackage.buildFakeCall(context, functionDescriptor, Collections.singletonList(argument), null).makeStmt();
|
||||
return CallTranslator.instance$.buildCall(context, functionDescriptor, Collections.singletonList(argument), null).makeStmt();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -19,8 +19,8 @@ package org.jetbrains.k2js.translate.intrinsic.functions.basic;
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallInfo;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.reference.CallInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
+1
-1
@@ -30,11 +30,11 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallInfo;
|
||||
import org.jetbrains.k2js.translate.context.Namer;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.intrinsic.functions.basic.FunctionIntrinsic;
|
||||
import org.jetbrains.k2js.translate.intrinsic.functions.patterns.NamePredicate;
|
||||
import org.jetbrains.k2js.translate.reference.CallInfo;
|
||||
import org.jetbrains.k2js.translate.utils.AnnotationsUtils;
|
||||
import org.jetbrains.k2js.translate.utils.BindingUtils;
|
||||
import org.jetbrains.k2js.translate.utils.JsDescriptorUtils;
|
||||
|
||||
+2
-2
@@ -27,10 +27,10 @@ import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.jet.lexer.JetToken;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.k2js.translate.intrinsic.operation.BinaryOperationIntrinsic;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
import org.jetbrains.k2js.translate.utils.TranslationUtils;
|
||||
|
||||
import static org.jetbrains.k2js.translate.operation.AssignmentTranslator.isAssignmentOperator;
|
||||
@@ -128,7 +128,7 @@ public final class BinaryOperationTranslator extends AbstractTranslator {
|
||||
@NotNull
|
||||
private JsExpression translateAsOverloadedBinaryOperation() {
|
||||
ResolvedCall<? extends FunctionDescriptor> resolvedCall = getFunctionResolvedCall(bindingContext(), expression.getOperationReference());
|
||||
JsExpression result = ReferencePackage.buildCall(context(), resolvedCall, getReceiver());
|
||||
JsExpression result = CallTranslator.instance$.translate(context(), resolvedCall, getReceiver());
|
||||
return mayBeWrapWithNegation(result);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetBinaryExpression;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
import org.jetbrains.k2js.translate.utils.BindingUtils;
|
||||
|
||||
public final class OverloadedAssignmentTranslator extends AssignmentTranslator {
|
||||
@@ -57,6 +57,6 @@ public final class OverloadedAssignmentTranslator extends AssignmentTranslator {
|
||||
|
||||
@NotNull
|
||||
private JsExpression overloadedMethodInvocation() {
|
||||
return ReferencePackage.buildCall(context(), resolvedCall, accessTranslator.translateAsGet());
|
||||
return CallTranslator.instance$.translate(context(), resolvedCall, accessTranslator.translateAsGet());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetUnaryExpression;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
import org.jetbrains.k2js.translate.utils.BindingUtils;
|
||||
|
||||
public final class OverloadedIncrementTranslator extends IncrementTranslator {
|
||||
@@ -40,7 +40,7 @@ public final class OverloadedIncrementTranslator extends IncrementTranslator {
|
||||
@Override
|
||||
@NotNull
|
||||
protected JsExpression operationExpression(@NotNull JsExpression receiver) {
|
||||
return ReferencePackage.buildCall(context(), resolvedCall, receiver);
|
||||
return CallTranslator.instance$.translate(context(), resolvedCall, receiver);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,8 +24,8 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetUnaryExpression;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
import org.jetbrains.k2js.translate.utils.TranslationUtils;
|
||||
|
||||
import static org.jetbrains.k2js.translate.general.Translation.translateAsExpression;
|
||||
@@ -57,7 +57,7 @@ public final class UnaryOperationTranslator {
|
||||
}
|
||||
|
||||
ResolvedCall<? extends FunctionDescriptor> resolvedCall = getFunctionResolvedCall(context.bindingContext(), expression.getOperationReference());
|
||||
return ReferencePackage.buildCall(context, resolvedCall, baseExpression);
|
||||
return CallTranslator.instance$.translate(context, resolvedCall, baseExpression);
|
||||
}
|
||||
|
||||
private static boolean isExclForBinaryEqualLikeExpr(@NotNull JetUnaryExpression expression, @NotNull JsExpression baseExpression) {
|
||||
|
||||
+2
-1
@@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.psi.ValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ExpressionValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.context.TemporaryVariable;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||
@@ -81,7 +82,7 @@ public class ArrayAccessTranslator extends AbstractTranslator implements AccessT
|
||||
if (!isGetter) {
|
||||
context = contextWithValueParameterAliasInArrayGetAccess(toSetTo);
|
||||
}
|
||||
return ReferencePackage.buildCall(context, resolvedCall, arrayExpression);
|
||||
return CallTranslator.instance$.translate(context, resolvedCall, arrayExpression);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@ import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
|
||||
public final class CallExpressionTranslator extends AbstractCallExpressionTranslator {
|
||||
@@ -43,6 +44,6 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
|
||||
|
||||
@NotNull
|
||||
private JsExpression translate() {
|
||||
return ReferencePackage.buildCall(context(), resolvedCall, receiver);
|
||||
return CallTranslator.instance$.translate(context(), resolvedCall, receiver);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,10 @@ public enum CallType {
|
||||
SAFE {
|
||||
@NotNull
|
||||
@Override
|
||||
JsExpression constructCall(@Nullable JsExpression receiver, @NotNull CallConstructor constructor,
|
||||
@NotNull TranslationContext context) {
|
||||
public JsExpression constructCall(
|
||||
@Nullable JsExpression receiver, @NotNull CallConstructor constructor,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
assert receiver != null;
|
||||
JsConditional expression = notNullConditional(receiver, JsLiteral.NULL, context);
|
||||
expression.setThenExpression(constructor.construct(expression.getThenExpression()));
|
||||
@@ -45,14 +47,16 @@ public enum CallType {
|
||||
NORMAL {
|
||||
@NotNull
|
||||
@Override
|
||||
JsExpression constructCall(@Nullable JsExpression receiver, @NotNull CallConstructor constructor,
|
||||
@NotNull TranslationContext context) {
|
||||
public JsExpression constructCall(
|
||||
@Nullable JsExpression receiver, @NotNull CallConstructor constructor,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
return constructor.construct(receiver);
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
abstract JsExpression constructCall(@Nullable JsExpression receiver, @NotNull CallConstructor constructor,
|
||||
public abstract JsExpression constructCall(@Nullable JsExpression receiver, @NotNull CallConstructor constructor,
|
||||
@NotNull TranslationContext context);
|
||||
|
||||
@NotNull
|
||||
|
||||
+3
-1
@@ -31,6 +31,8 @@ import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetFunction;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallInfo;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallTranslatorPackage;
|
||||
import org.jetbrains.k2js.translate.context.TemporaryVariable;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.utils.JsAstUtils;
|
||||
@@ -116,7 +118,7 @@ public final class InlinedCallExpressionTranslator extends AbstractCallExpressio
|
||||
private TranslationContext createContextWithAliasForThisExpression(@NotNull TranslationContext contextForInlining) {
|
||||
TranslationContext contextWithAliasForThisExpression = contextForInlining;
|
||||
SimpleFunctionDescriptor functionDescriptor = getFunctionDescriptor();
|
||||
CallInfo callInfo = ReferencePackage.getCallInfo(contextForInlining, resolvedCall, receiver);
|
||||
CallInfo callInfo = CallTranslatorPackage.getCallInfo(contextForInlining, resolvedCall, receiver);
|
||||
JsExpression receiver = callInfo.getReceiverObject();
|
||||
if (receiver != null) {
|
||||
contextWithAliasForThisExpression =
|
||||
|
||||
+3
-2
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.k2js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.context.TemporaryVariable;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||
@@ -58,13 +59,13 @@ public class VariableAccessTranslator extends AbstractTranslator implements Acce
|
||||
@NotNull
|
||||
@Override
|
||||
public JsExpression translateAsGet() {
|
||||
return ReferencePackage.buildGet(context(), resolvedCall, receiver);
|
||||
return CallTranslator.instance$.translateGet(context(), resolvedCall, receiver);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JsExpression translateAsSet(@NotNull JsExpression setTo) {
|
||||
return ReferencePackage.buildSet(context(), resolvedCall, setTo, receiver);
|
||||
return CallTranslator.instance$.translateSet(context(), resolvedCall, setTo, receiver);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -23,9 +23,9 @@ 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.k2js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.JetTestFunctionDetector;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
import org.jetbrains.k2js.translate.reference.ReferenceTranslator;
|
||||
import org.jetbrains.k2js.translate.utils.JsDescriptorUtils;
|
||||
|
||||
@@ -60,7 +60,8 @@ public final class JSTestGenerator {
|
||||
@NotNull ClassDescriptor classDescriptor, @NotNull JSTester tester) {
|
||||
JsExpression expression = ReferenceTranslator.translateAsFQReference(classDescriptor, context);
|
||||
JsNew testClass = new JsNew(expression);
|
||||
JsExpression functionToTestCall = ReferencePackage.buildFakeCall(context, functionDescriptor, Collections.<JsExpression>emptyList(), testClass);
|
||||
JsExpression functionToTestCall = CallTranslator.instance$.buildCall(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