diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index eb6634b14b8..912ad38fe35 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,11 +6,12 @@
-
-
+
+
-
+
+
@@ -35,7 +36,7 @@
-
+
@@ -88,47 +89,9 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -187,6 +150,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -194,7 +193,7 @@
-
+
@@ -202,6 +201,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -220,64 +273,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -299,10 +298,6 @@
@@ -429,28 +428,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -552,51 +529,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -663,6 +596,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -738,11 +721,11 @@
-
-
-
-
-
+
+
+
+
+
localhost
@@ -778,13 +761,13 @@
-
+
-
+
@@ -794,7 +777,7 @@
-
+
@@ -832,7 +815,7 @@
-
+
@@ -851,6 +834,7 @@
+
@@ -860,79 +844,9 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -944,32 +858,104 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
diff --git a/js/src/com/google/dart/compiler/backend/js/ast/JsNew.java b/js/src/com/google/dart/compiler/backend/js/ast/JsNew.java
index 19b6f5d6c90..68fc366684d 100644
--- a/js/src/com/google/dart/compiler/backend/js/ast/JsNew.java
+++ b/js/src/com/google/dart/compiler/backend/js/ast/JsNew.java
@@ -12,50 +12,55 @@ import java.util.List;
*/
public final class JsNew extends JsExpression implements HasArguments {
- private final List args = new ArrayList();
- private JsExpression ctorExpr;
+ private final List args = new ArrayList();
+ private JsExpression ctorExpr;
- public JsNew(JsExpression ctorExpr) {
- this.ctorExpr = ctorExpr;
- }
-
- @Override
- public List getArguments() {
- return args;
- }
-
- public JsExpression getConstructorExpression() {
- return ctorExpr;
- }
-
- @Override
- public boolean hasSideEffects() {
- return true;
- }
-
- @Override
- public boolean isDefinitelyNotNull() {
- // Sadly, in JS it can be!
- // TODO: analysis could probably determine most instances cannot be null.
- return false;
- }
-
- @Override
- public boolean isDefinitelyNull() {
- return false;
- }
-
- @Override
- public void traverse(JsVisitor v, JsContext ctx) {
- if (v.visit(this, ctx)) {
- ctorExpr = v.accept(ctorExpr);
- v.acceptList(args);
+ public JsNew(JsExpression ctorExpr) {
+ this.ctorExpr = ctorExpr;
}
- v.endVisit(this, ctx);
- }
- @Override
- public NodeKind getKind() {
- return NodeKind.NEW;
- }
+ @Override
+ public List getArguments() {
+ return args;
+ }
+
+ public void setArguments(List arguments) {
+ args.clear();
+ args.addAll(arguments);
+ }
+
+ public JsExpression getConstructorExpression() {
+ return ctorExpr;
+ }
+
+ @Override
+ public boolean hasSideEffects() {
+ return true;
+ }
+
+ @Override
+ public boolean isDefinitelyNotNull() {
+ // Sadly, in JS it can be!
+ // TODO: analysis could probably determine most instances cannot be null.
+ return false;
+ }
+
+ @Override
+ public boolean isDefinitelyNull() {
+ return false;
+ }
+
+ @Override
+ public void traverse(JsVisitor v, JsContext ctx) {
+ if (v.visit(this, ctx)) {
+ ctorExpr = v.accept(ctorExpr);
+ v.acceptList(args);
+ }
+ v.endVisit(this, ctx);
+ }
+
+ @Override
+ public NodeKind getKind() {
+ return NodeKind.NEW;
+ }
}
diff --git a/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java b/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java
index 77608dbbd0f..b90648551f0 100644
--- a/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java
+++ b/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java
@@ -5,11 +5,14 @@ import com.google.dart.compiler.backend.js.ast.JsExpression;
import com.google.dart.compiler.backend.js.ast.*;
import com.google.dart.compiler.backend.js.ast.JsReturn;
import com.google.dart.compiler.util.AstUtil;
+import com.sun.xml.internal.bind.v2.runtime.reflect.opt.Const;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
+import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lexer.JetToken;
@@ -135,14 +138,26 @@ public final class ExpressionVisitor extends TranslatorVisitor {
@Override
@NotNull
public JsNode visitCallExpression(JetCallExpression expression, TranslationContext context) {
- ConstructorDescriptor constructorDescriptor = (context.bindingContext().get(BindingContext.CONSTRUCTOR, expression.getCalleeExpression()));
- JetExpression calleeExpression = expression.getCalleeExpression();
- if (constructorDescriptor == null) {
- JsExpression callee = getCallee(expression, context);
- List arguments = generateArgumentList(expression.getValueArguments(), context);
- return AstUtil.newInvocation(callee, arguments);
+ JsExpression callee = getCallee(expression, context);
+ List arguments = generateArgumentList(expression.getValueArguments(), context);
+
+ if (isConstructorInvocation(expression, context)) {
+ JsNew constructorCall = new JsNew(callee);
+ constructorCall.setArguments(arguments);
+ return constructorCall;
}
- throw new AssertionError("Should generate constructor invocation");
+ return AstUtil.newInvocation(callee, arguments);
+ }
+
+ private boolean isConstructorInvocation(@NotNull JetCallExpression expression,
+ @NotNull TranslationContext context) {
+ ResolvedCall> resolvedCall =
+ (context.bindingContext().get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression()));
+ if (resolvedCall == null) {
+ return false;
+ }
+ CallableDescriptor descriptor = resolvedCall.getCandidateDescriptor();
+ return (descriptor instanceof ConstructorDescriptor);
}
@NotNull
diff --git a/translator/test/org/jetbrains/k2js/test/ClassTest.java b/translator/test/org/jetbrains/k2js/test/ClassTest.java
index a5858f42e8a..863eafb8cac 100644
--- a/translator/test/org/jetbrains/k2js/test/ClassTest.java
+++ b/translator/test/org/jetbrains/k2js/test/ClassTest.java
@@ -47,4 +47,9 @@ public final class ClassTest extends TranslationTest {
testFooBoxIsTrue("classInstantiation.kt");
}
+ @Test
+ public void methodDeclarationAndCall() throws Exception {
+ testFooBoxIsTrue("methodDeclarationAndCall.kt");
+ }
+
}
diff --git a/translator/test_files/test_cases/classInstantiation.js b/translator/test_files/test_cases/classInstantiation.js
index 2979e4b0715..4a18b69cade 100644
--- a/translator/test_files/test_cases/classInstantiation.js
+++ b/translator/test_files/test_cases/classInstantiation.js
@@ -4,7 +4,7 @@ foo = {};
}
});
foo.box = function(){
- var test = foo.Test();
+ var test = new foo.Test;
return true;
}
;
diff --git a/translator/test_files/test_cases/mehodDeclarationAndCall.kt b/translator/test_files/test_cases/mehodDeclarationAndCall.kt
new file mode 100644
index 00000000000..dae1f5b234d
--- /dev/null
+++ b/translator/test_files/test_cases/mehodDeclarationAndCall.kt
@@ -0,0 +1,12 @@
+namespace foo
+
+class Test() {
+ fun method() : Boolean {
+ return true;
+ }
+}
+
+fun box() : Boolean {
+ var test = Test()
+ return test.method
+}
\ No newline at end of file