diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 912ad38fe35..c6da240ed7f 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,12 +6,15 @@
-
+
+
-
+
+
+
+
-
@@ -36,7 +39,7 @@
-
+
@@ -89,42 +92,13 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -132,46 +106,73 @@
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -190,10 +191,10 @@
-
+
-
+
@@ -201,64 +202,28 @@
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -267,16 +232,58 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -298,22 +305,22 @@
@@ -434,7 +441,19 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -530,72 +549,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -646,6 +599,80 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -721,11 +748,11 @@
-
-
-
-
-
+
+
+
+
+
localhost
@@ -761,7 +788,7 @@
-
+
@@ -777,7 +804,7 @@
-
+
@@ -815,7 +842,7 @@
-
+
@@ -835,6 +862,7 @@
+
@@ -844,76 +872,48 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -925,16 +925,16 @@
-
+
-
+
-
+
-
+
@@ -946,16 +946,48 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translator/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java b/translator/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java
index c10c72738a2..10aa88d8b95 100644
--- a/translator/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java
+++ b/translator/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java
@@ -2,11 +2,9 @@ package org.jetbrains.k2js.translate;
import com.google.dart.compiler.backend.js.ast.*;
import com.google.dart.compiler.util.AstUtil;
+import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.jet.lang.psi.JetClass;
-import org.jetbrains.jet.lang.psi.JetDeclaration;
-import org.jetbrains.jet.lang.psi.JetProperty;
-import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
+import org.jetbrains.jet.lang.psi.*;
import java.util.ArrayList;
import java.util.Arrays;
@@ -27,6 +25,15 @@ public final class ClassBodyVisitor extends TranslatorVisitor visitNamedFunction(@NotNull JetNamedFunction expression, @NotNull TranslationContext context) {
+ List properties = new ArrayList();
+ properties.add((new FunctionTranslator(context)).translateAsMethod(expression));
+ return properties;
+ }
+
@Override
@NotNull
public List visitProperty(@NotNull JetProperty expression, @NotNull TranslationContext context) {
@@ -83,7 +90,6 @@ public final class ClassBodyVisitor extends TranslatorVisitor visitPropertyAccessor
diff --git a/translator/src/org/jetbrains/k2js/translate/ClassTranslator.java b/translator/src/org/jetbrains/k2js/translate/ClassTranslator.java
index 5cb935744fe..4bcf939bb6f 100644
--- a/translator/src/org/jetbrains/k2js/translate/ClassTranslator.java
+++ b/translator/src/org/jetbrains/k2js/translate/ClassTranslator.java
@@ -46,7 +46,7 @@ public final class ClassTranslator extends AbstractTranslator {
private JsObjectLiteral translateClassDeclarations(JetClass classDeclaration) {
List propertyList = new ArrayList();
propertyList.add(generateInitializeMethod(classDeclaration));
- propertyList.addAll(classDeclaration.accept(classBodyVisitor, translationContext()));
+ propertyList.addAll(classDeclaration.accept(classBodyVisitor, translationContext().newClass()));
return new JsObjectLiteral(propertyList);
}
diff --git a/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java b/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java
index b90648551f0..ba049aac277 100644
--- a/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java
+++ b/translator/src/org/jetbrains/k2js/translate/ExpressionVisitor.java
@@ -269,12 +269,36 @@ public final class ExpressionVisitor extends TranslatorVisitor {
context.bindingContext().get(BindingContext.COMPILE_TIME_VALUE, expression);
if (compileTimeValue != null) {
Object value = compileTimeValue.getValue();
- assert value instanceof String : "Compile time constant template should be a String constant";
+ assert value instanceof String : "Compile time constant template should be a String constant.";
String constantString = (String)value;
return context.program().getStringLiteral(constantString);
}
return null;
}
+ @Override
+ @NotNull
+ public JsNode visitDotQualifiedExpression(@NotNull JetDotQualifiedExpression expression,
+ @NotNull TranslationContext context) {
+ JsExpression receiver = AstUtil.convertToExpression(expression.getReceiverExpression().accept(this, context));
+ JetExpression jetSelector = expression.getSelectorExpression();
+ assert jetSelector != null : "Selector should not be null in dot qualified expression.";
+ JsExpression selector = AstUtil.convertToExpression(jetSelector.accept(this, context));
+ assert (selector instanceof JsNameRef || selector instanceof JsInvocation)
+ : "Selector should be a name reference or a method invocation in dot qualified expression.";
+ if (selector instanceof JsInvocation) {
+ JsInvocation result = (JsInvocation)selector;
+ JsExpression qualifier = result.getQualifier();
+ JsNameRef nameRef = (JsNameRef)qualifier;
+ nameRef.setQualifier(receiver);
+ return result;
+ } else {
+ JsNameRef result = (JsNameRef)selector;
+ result.setQualifier(receiver);
+ return result;
+ }
+ }
+
+
}
diff --git a/translator/src/org/jetbrains/k2js/translate/FunctionTranslator.java b/translator/src/org/jetbrains/k2js/translate/FunctionTranslator.java
index 9de43f6edfc..69247208b79 100644
--- a/translator/src/org/jetbrains/k2js/translate/FunctionTranslator.java
+++ b/translator/src/org/jetbrains/k2js/translate/FunctionTranslator.java
@@ -27,6 +27,12 @@ public final class FunctionTranslator extends AbstractTranslator {
(translationContext().getNamespaceQualifiedReference(functionName), function));
}
+ @NotNull JsPropertyInitializer translateAsMethod(@NotNull JetNamedFunction jetFunction) {
+ JsName functionName = translationContext().namespaceScope().declareFreshName(jetFunction.getName());
+ JsFunction function = generateFunctionObject(jetFunction);
+ return new JsPropertyInitializer(functionName.makeRef(), function);
+ }
+
@NotNull
private JsFunction generateFunctionObject(@NotNull JetNamedFunction jetFunction) {
JetExpression jetBodyExpression = jetFunction.getBodyExpression();
diff --git a/translator/src/org/jetbrains/k2js/translate/TranslationContext.java b/translator/src/org/jetbrains/k2js/translate/TranslationContext.java
index 1644d87c66b..9380ff5777d 100644
--- a/translator/src/org/jetbrains/k2js/translate/TranslationContext.java
+++ b/translator/src/org/jetbrains/k2js/translate/TranslationContext.java
@@ -58,16 +58,23 @@ public final class TranslationContext {
@NotNull
public TranslationContext newBlock() {
Scopes newScopes = new Scopes(new JsScope
- (scopes.enclosingScope, "dummy enclosingScope for a block"), scopes.classScope, scopes.namespaceScope);
+ (scopes.enclosingScope, "Scope for a block"), scopes.classScope, scopes.namespaceScope);
+ return new TranslationContext(currentNamespace, program,
+ bindingContext, newScopes);
+ }
+
+ @NotNull
+ public TranslationContext newClass() {
+ JsScope classDummyScope = new JsScope(namespaceScope(), "Scope for a class");
+ Scopes newScopes = new Scopes(classDummyScope, classDummyScope, scopes.namespaceScope);
return new TranslationContext(currentNamespace, program,
bindingContext, newScopes);
}
- //TODO new Class?
@NotNull
public TranslationContext newFunction(@NotNull JsFunction function) {
JsScope functionScope = function.getScope();
- Scopes newScopes = new Scopes(functionScope, functionScope, scopes.namespaceScope);
+ Scopes newScopes = new Scopes(functionScope, scopes.classScope, scopes.namespaceScope);
return new TranslationContext(currentNamespace, program,
bindingContext, newScopes);
}
diff --git a/translator/test/org/jetbrains/k2js/test/ClassTest.java b/translator/test/org/jetbrains/k2js/test/ClassTest.java
index 863eafb8cac..7ddc07e7a00 100644
--- a/translator/test/org/jetbrains/k2js/test/ClassTest.java
+++ b/translator/test/org/jetbrains/k2js/test/ClassTest.java
@@ -52,4 +52,9 @@ public final class ClassTest extends TranslationTest {
testFooBoxIsTrue("methodDeclarationAndCall.kt");
}
+ @Test
+ public void accessToInstanceProperty() throws Exception {
+ testFooBoxIsTrue("accessToInstanceProperty.kt");
+ }
+
}
diff --git a/translator/test_files/test_cases/accessToInstanceProperty.kt b/translator/test_files/test_cases/accessToInstanceProperty.kt
new file mode 100644
index 00000000000..340dee70671
--- /dev/null
+++ b/translator/test_files/test_cases/accessToInstanceProperty.kt
@@ -0,0 +1,10 @@
+namespace foo
+
+class Test() {
+ val a : Int = 1
+}
+
+fun box() : Boolean {
+ var test = Test()
+ return (test.a == 1)
+}
\ No newline at end of file
diff --git a/translator/test_files/test_cases/mehodDeclarationAndCall.kt b/translator/test_files/test_cases/methodDeclarationAndCall.kt
similarity index 84%
rename from translator/test_files/test_cases/mehodDeclarationAndCall.kt
rename to translator/test_files/test_cases/methodDeclarationAndCall.kt
index dae1f5b234d..d982852ba7e 100644
--- a/translator/test_files/test_cases/mehodDeclarationAndCall.kt
+++ b/translator/test_files/test_cases/methodDeclarationAndCall.kt
@@ -8,5 +8,5 @@ class Test() {
fun box() : Boolean {
var test = Test()
- return test.method
+ return test.method()
}
\ No newline at end of file