JS backend: Move CallTranslator to new package & create CallTranslator object

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