diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index ccb5ce74db4..bbca007f954 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,37 +4,10 @@
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -228,27 +201,9 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -294,6 +249,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -312,10 +285,10 @@
-
+
-
+
@@ -327,37 +300,28 @@
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
@@ -365,55 +329,64 @@
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
@@ -440,7 +413,6 @@
@@ -654,6 +627,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -813,72 +830,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -971,6 +922,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1098,11 +1115,11 @@
-
-
-
-
-
+
+
+
+
+
localhost
@@ -1171,14 +1188,14 @@
-
+
-
-
+
+
@@ -1221,7 +1238,7 @@
-
+
@@ -1234,7 +1251,6 @@
-
@@ -1259,6 +1275,7 @@
+
@@ -1268,13 +1285,6 @@
-
-
-
-
-
-
-
@@ -1282,6 +1292,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1289,95 +1315,86 @@
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
-
-
-
+
+
-
+
-
+
+
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/translator/src/org/jetbrains/k2js/translate/reference/CallTranslator.java b/translator/src/org/jetbrains/k2js/translate/reference/CallTranslator.java
index ed69ce8513d..5cf22bf19fa 100644
--- a/translator/src/org/jetbrains/k2js/translate/reference/CallTranslator.java
+++ b/translator/src/org/jetbrains/k2js/translate/reference/CallTranslator.java
@@ -1,9 +1,6 @@
package org.jetbrains.k2js.translate.reference;
-import com.google.dart.compiler.backend.js.ast.JsExpression;
-import com.google.dart.compiler.backend.js.ast.JsName;
-import com.google.dart.compiler.backend.js.ast.JsNameRef;
-import com.google.dart.compiler.backend.js.ast.JsNew;
+import com.google.dart.compiler.backend.js.ast.*;
import com.google.dart.compiler.util.AstUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -81,49 +78,63 @@ public final class CallTranslator extends AbstractTranslator {
private final List arguments;
@NotNull
- private final FunctionDescriptor descriptor;
+ private final FunctionDescriptor functionDescriptor;
private CallTranslator(@Nullable JsExpression receiver, @NotNull List arguments,
@NotNull FunctionDescriptor descriptor, @NotNull TranslationContext context) {
super(context);
this.receiver = receiver;
this.arguments = arguments;
- this.descriptor = descriptor;
+ this.functionDescriptor = descriptor;
}
@NotNull
private JsExpression translate() {
- if (context().intrinsics().isIntrinsic(descriptor)) {
- FunctionIntrinsic functionIntrinsic = context().intrinsics().getFunctionIntrinsic(descriptor);
- assert receiver != null : "Functions that have functionIntrinsic implementation should have a receiver.";
- return functionIntrinsic.apply(receiver, arguments, context());
+ if (isIntrinsic()) {
+ return intrinsicInvocation();
}
- if (isConstructorDescriptor(descriptor)) {
+ if (isConstructor()) {
return constructorCall();
}
+ return methodCall();
+ }
+
+ @NotNull
+ private JsExpression intrinsicInvocation() {
+ FunctionIntrinsic functionIntrinsic = context().intrinsics().getFunctionIntrinsic(functionDescriptor);
+ assert receiver != null : "Functions that have functionIntrinsic implementation should have a receiver.";
+ return functionIntrinsic.apply(receiver, arguments, context());
+ }
+
+ private JsInvocation methodCall() {
return AstUtil.newInvocation(calleeReference(), arguments);
}
+ private boolean isConstructor() {
+ return isConstructorDescriptor(functionDescriptor);
+ }
+
+ private boolean isIntrinsic() {
+ return context().intrinsics().isIntrinsic(functionDescriptor);
+ }
+
@NotNull
private JsExpression calleeReference() {
//TODO: refactor
//TODO: write tests on this cases
- if (descriptor instanceof VariableAsFunctionDescriptor) {
- VariableDescriptor variableDescriptor = ((VariableAsFunctionDescriptor) descriptor).getVariableDescriptor();
+ if (functionDescriptor instanceof VariableAsFunctionDescriptor) {
+ VariableDescriptor variableDescriptor = ((VariableAsFunctionDescriptor) functionDescriptor).getVariableDescriptor();
if (variableDescriptor instanceof PropertyDescriptor) {
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) variableDescriptor;
return PropertyAccessTranslator.translateAsPropertyGetterCall(propertyDescriptor, context());
}
+ return qualifiedMethodReference(variableDescriptor);
}
- if (context().isDeclared(descriptor)) {
- return qualifiedMethodReference();
- }
- //TODO: hack
- return AstUtil.newQualifiedNameRef(descriptor.getName());
+ return qualifiedMethodReference(functionDescriptor);
}
@NotNull
- private JsNameRef qualifiedMethodReference() {
+ private JsNameRef qualifiedMethodReference(@Nullable DeclarationDescriptor descriptor) {
JsName methodName = context().getNameForDescriptor(descriptor);
if (receiver != null) {
return AstUtil.qualified(methodName, receiver);
@@ -137,14 +148,4 @@ public final class CallTranslator extends AbstractTranslator {
constructorCall.setArguments(arguments);
return constructorCall;
}
-
-// //TODO: delete?
-// @NotNull
-// private JsExpression translateCallee(@NotNull JetCallExpression expression) {
-// JetExpression callee = expression.getCalleeExpression();
-// assert callee != null : "Call expression with no callee encountered!";
-// return Translation.translateAsExpression(callee, context);
-// }
-
-
}
diff --git a/translator/src/org/jetbrains/k2js/translate/utils/TranslationUtils.java b/translator/src/org/jetbrains/k2js/translate/utils/TranslationUtils.java
index 16ab6ee6a89..2773d3f8116 100644
--- a/translator/src/org/jetbrains/k2js/translate/utils/TranslationUtils.java
+++ b/translator/src/org/jetbrains/k2js/translate/utils/TranslationUtils.java
@@ -208,4 +208,17 @@ public final class TranslationUtils {
return context.program().getNumberLiteral(0);
}
+ @Nullable
+ public static JsExpression getImplicitReceiver(@NotNull TranslationContext context,
+ @NotNull DeclarationDescriptor referencedDescriptor) {
+ if (!context.isDeclared(referencedDescriptor)) return null;
+
+ if (BindingUtils.isOwnedByClass(referencedDescriptor)) {
+ return TranslationUtils.getThisQualifier(context);
+ }
+ if (!BindingUtils.isOwnedByNamespace(referencedDescriptor)) return null;
+
+ return context.declarations().getQualifier(referencedDescriptor);
+ }
+
}