diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 172f0053031..a717a31f30b 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -8,14 +8,24 @@
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -32,11 +42,12 @@
-
- org.jetbrains.k2js.declarations.*
- org.jetbrains.k2js.generate.*
+
+ org.jetbrains.k2js.translate.*
+
+
+ org.jetbrains.k2js.test.*
org.jetbrains.k2js.translate.*
- org.jetbrains.k2js.utils.*
@@ -99,19 +110,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -195,58 +193,13 @@
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -273,16 +226,63 @@
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -292,91 +292,91 @@
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
@@ -403,22 +403,22 @@
@@ -569,7 +569,7 @@
-
+
@@ -587,69 +587,11 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -671,143 +613,15 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translator/src/org/jetbrains/k2js/declarations/DeclarationVisitor.java b/translator/src/org/jetbrains/k2js/declarations/DeclarationVisitor.java
index 852097285cc..00fd0ec8e8d 100644
--- a/translator/src/org/jetbrains/k2js/declarations/DeclarationVisitor.java
+++ b/translator/src/org/jetbrains/k2js/declarations/DeclarationVisitor.java
@@ -102,7 +102,8 @@ public final class DeclarationVisitor extends DeclarationDescriptorVisitor 0);
}
+ public static boolean isEquals(@NotNull FunctionDescriptor functionDescriptor) {
+ return (functionDescriptor.getName().equals(OperatorConventions.EQUALS));
+ }
+
+ public static boolean isCompareTo(@NotNull FunctionDescriptor functionDescriptor) {
+ return (functionDescriptor.getName().equals(OperatorConventions.COMPARE_TO));
+ }
+
+ public static boolean isConstructorDescriptor(@NotNull FunctionDescriptor descriptor) {
+ return (descriptor instanceof ConstructorDescriptor);
+ }
}
diff --git a/translator/src/org/jetbrains/k2js/translate/utils/PsiUtils.java b/translator/src/org/jetbrains/k2js/translate/utils/PsiUtils.java
index 9ad05c2f6aa..5635b200e6f 100644
--- a/translator/src/org/jetbrains/k2js/translate/utils/PsiUtils.java
+++ b/translator/src/org/jetbrains/k2js/translate/utils/PsiUtils.java
@@ -3,11 +3,9 @@ package org.jetbrains.k2js.translate.utils;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.jetbrains.jet.lang.psi.JetExpression;
-import org.jetbrains.jet.lang.psi.JetOperationExpression;
-import org.jetbrains.jet.lang.psi.JetQualifiedExpression;
-import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
+import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lexer.JetToken;
+import org.jetbrains.jet.lexer.JetTokens;
/**
* @author Talanov Pavel
@@ -34,4 +32,19 @@ public final class PsiUtils {
assert elementType instanceof JetToken : "Unary expression should have operation token of type JetToken";
return (JetToken) elementType;
}
+
+ @NotNull
+ public static JetExpression getBaseExpression(@NotNull JetUnaryExpression expression) {
+ JetExpression baseExpression = expression.getBaseExpression();
+ assert baseExpression != null;
+ return baseExpression;
+ }
+
+ public static boolean isPrefix(@NotNull JetUnaryExpression expression) {
+ return (expression instanceof JetPrefixExpression);
+ }
+
+ public static boolean isAssignment(JetToken token) {
+ return (token == JetTokens.EQ);
+ }
}
diff --git a/translator/src/org/jetbrains/k2js/translate/utils/TranslationUtils.java b/translator/src/org/jetbrains/k2js/translate/utils/TranslationUtils.java
index 6efe58e0f0c..357a4b276ff 100644
--- a/translator/src/org/jetbrains/k2js/translate/utils/TranslationUtils.java
+++ b/translator/src/org/jetbrains/k2js/translate/utils/TranslationUtils.java
@@ -4,7 +4,6 @@ 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;
-import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
@@ -72,7 +71,13 @@ public final class TranslationUtils {
public static JsNameRef backingFieldReference(@NotNull TranslationContext context,
@NotNull PropertyDescriptor descriptor) {
JsName backingFieldName = getBackingFieldName(descriptor.getName(), context);
- return getThisQualifiedNameReference(context, backingFieldName);
+ if (BindingUtils.isOwnedByClass(descriptor)) {
+ return getThisQualifiedNameReference(context, backingFieldName);
+ }
+ assert BindingUtils.isOwnedByNamespace(descriptor)
+ : "Only classes and namespaces may own descriptors";
+ JsNameRef qualifier = context.declarations().getQualifier(descriptor);
+ return AstUtil.qualified(backingFieldName, qualifier);
}
@NotNull
@@ -102,11 +107,6 @@ public final class TranslationUtils {
return jsInitExpression;
}
- //TODO: move to descriptor UTILS
- public static boolean isConstructorDescriptor(@NotNull FunctionDescriptor descriptor) {
- return (descriptor instanceof ConstructorDescriptor);
- }
-
@NotNull
public static JsStatement assignmentToBackingFieldFromParameter(@NotNull TranslationContext context,
@NotNull PropertyDescriptor descriptor,
@@ -168,32 +168,13 @@ public final class TranslationUtils {
return result;
}
- public static boolean isIntrinsicOperation(@NotNull TranslationContext context,
- @NotNull JetReferenceExpression expression) {
- DeclarationDescriptor descriptor =
- BindingUtils.getDescriptorForReferenceExpression(context.bindingContext(), expression);
-
- if (descriptor == null) return true;
-
- return (context.intrinsics().hasDescriptor(descriptor));
- }
-
-
@NotNull
public static JsExpression translateBaseExpression(@NotNull TranslationContext context,
@NotNull JetUnaryExpression expression) {
- JetExpression baseExpression = getBaseExpression(expression);
+ JetExpression baseExpression = PsiUtils.getBaseExpression(expression);
return Translation.translateAsExpression(baseExpression, context);
}
- //TODO: move to psi utils
- @NotNull
- public static JetExpression getBaseExpression(@NotNull JetUnaryExpression expression) {
- JetExpression baseExpression = expression.getBaseExpression();
- assert baseExpression != null : "Unary expression should have a base expression";
- return baseExpression;
- }
-
@NotNull
public static JsExpression translateReceiver(@NotNull TranslationContext context,
@NotNull JetDotQualifiedExpression expression) {
@@ -215,7 +196,6 @@ public final class TranslationUtils {
return Translation.translateAsExpression(rightExpression, context);
}
- //TODO: check function with same name
public static boolean isIntrinsicOperation(@NotNull TranslationContext context,
@NotNull JetOperationExpression expression) {
FunctionDescriptor operationDescriptor =
diff --git a/translator/test/org/jetbrains/k2js/test/BasicClassTest.java b/translator/test/org/jetbrains/k2js/test/BasicClassTest.java
index 6facd9ed4df..e1b6fdd191b 100644
--- a/translator/test/org/jetbrains/k2js/test/BasicClassTest.java
+++ b/translator/test/org/jetbrains/k2js/test/BasicClassTest.java
@@ -24,7 +24,6 @@ public class BasicClassTest extends TranslationTest {
testFooBoxIsTrue("methodDeclarationAndCall.kt");
}
- //TODO: wait for bugfix and implement properties as constructor parameter declaration
@Test
public void constructorWithParameter() throws Exception {
testFooBoxIsTrue("constructorWithParameter.kt");
diff --git a/translator/test/org/jetbrains/k2js/test/IntrinsicTest.java b/translator/test/org/jetbrains/k2js/test/IntrinsicTest.java
new file mode 100644
index 00000000000..ac05cb325ac
--- /dev/null
+++ b/translator/test/org/jetbrains/k2js/test/IntrinsicTest.java
@@ -0,0 +1,27 @@
+package org.jetbrains.k2js.test;
+
+import org.junit.Test;
+
+/**
+ * @author Talanov Pavel
+ */
+public class IntrinsicTest extends AbstractExpressionTest {
+
+ final private static String MAIN = "intrinsic/";
+
+ @Override
+ protected String mainDirectory() {
+ return MAIN;
+ }
+
+ @Test
+ public void intrinsicPlusAssign() throws Exception {
+ testFooBoxIsTrue("plusAssign.kt");
+ }
+
+ @Test
+ public void minusAssignOnProperty() throws Exception {
+ testFooBoxIsTrue("minusAssignOnProperty.kt");
+ }
+
+}
diff --git a/translator/testFiles/expression/intrinsic/cases/minusAssignOnProperty.kt b/translator/testFiles/expression/intrinsic/cases/minusAssignOnProperty.kt
new file mode 100644
index 00000000000..17a20d2eee2
--- /dev/null
+++ b/translator/testFiles/expression/intrinsic/cases/minusAssignOnProperty.kt
@@ -0,0 +1,10 @@
+namespace foo
+
+var a = 3
+
+fun box() : Boolean {
+ a -= 10
+
+ return (a == -7)
+
+}
\ No newline at end of file
diff --git a/translator/testFiles/expression/intrinsic/cases/plusAssign.kt b/translator/testFiles/expression/intrinsic/cases/plusAssign.kt
new file mode 100644
index 00000000000..1981e291b22
--- /dev/null
+++ b/translator/testFiles/expression/intrinsic/cases/plusAssign.kt
@@ -0,0 +1,8 @@
+namespace foo
+
+
+fun box() : Boolean {
+ var a = 3
+ a += 3
+ return (a == 6)
+}
\ No newline at end of file