From 504a2d510132e042dfd06a3dd8dbfe03f8d1faa7 Mon Sep 17 00:00:00 2001 From: Pavel Talanov Date: Fri, 25 Nov 2011 20:05:35 +0400 Subject: [PATCH] compareTo support. --- .idea/workspace.xml | 367 +++++++++--------- .../k2js/translate/utils/BindingUtils.java | 39 +- .../translate/utils/TranslationUtils.java | 8 - .../k2js/test/OperatorOverloadingTest.java | 9 +- .../operatorOverloading/cases/compareTo.kt | 10 +- 5 files changed, 210 insertions(+), 223 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c9df3632798..49837a3806d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -9,13 +9,10 @@ - - - - - + - + + @@ -85,13 +82,13 @@ - + - + @@ -100,16 +97,43 @@ - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -118,34 +142,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -184,37 +181,48 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -223,39 +231,46 @@ - + - + - - + + - - - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + - + @@ -265,26 +280,6 @@ - - - - - - - - - - - - - - - - - - - - @@ -306,9 +301,6 @@ @@ -471,7 +466,7 @@ @@ -1295,58 +1306,79 @@ - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + @@ -1355,66 +1387,43 @@ - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - + + diff --git a/translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java b/translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java index cc06d10380d..e5b03082618 100644 --- a/translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java +++ b/translator/src/org/jetbrains/k2js/translate/utils/BindingUtils.java @@ -63,21 +63,22 @@ public final class BindingUtils { return getDescriptorForExpression(context, declaration, PropertyDescriptor.class); } - @NotNull - static public PropertySetterDescriptor getPropertySetterDescriptorForProperty(@NotNull BindingContext context, - @NotNull JetProperty property) { - PropertySetterDescriptor result = getPropertyDescriptor(context, property).getSetter(); - assert result != null : "Property should have a setter descriptor"; - return result; - } - - @NotNull - static public PropertyGetterDescriptor getPropertyGetterDescriptorForProperty(@NotNull BindingContext context, - @NotNull JetProperty property) { - PropertyGetterDescriptor result = getPropertyDescriptor(context, property).getGetter(); - assert result != null : "Property should have a getter descriptor"; - return result; - } + //TODO: possibly remove +// @NotNull +// static public PropertySetterDescriptor getPropertySetterDescriptorForProperty(@NotNull BindingContext context, +// @NotNull JetProperty property) { +// PropertySetterDescriptor result = getPropertyDescriptor(context, property).getSetter(); +// assert result != null : "Property should have a setter descriptor"; +// return result; +// } +// +// @NotNull +// static public PropertyGetterDescriptor getPropertyGetterDescriptorForProperty(@NotNull BindingContext context, +// @NotNull JetProperty property) { +// PropertyGetterDescriptor result = getPropertyDescriptor(context, property).getGetter(); +// assert result != null : "Property should have a getter descriptor"; +// return result; +// } @NotNull static public JetClass getClassForDescriptor(@NotNull BindingContext context, @@ -179,14 +180,6 @@ public final class BindingUtils { return null; } - static public boolean belongsToNamespace(@NotNull BindingContext context, @NotNull JetProperty property) { - return belongsToNamespace(context, getPropertyDescriptor(context, property)); - } - - static public boolean belongsToNamespace(@NotNull BindingContext context, @NotNull PropertyDescriptor descriptor) { - return descriptor.getContainingDeclaration() instanceof NamespaceDescriptor; - } - @Nullable static public ResolvedCall getResolvedCall(@NotNull BindingContext context, @NotNull JetExpression expression) { diff --git a/translator/src/org/jetbrains/k2js/translate/utils/TranslationUtils.java b/translator/src/org/jetbrains/k2js/translate/utils/TranslationUtils.java index 59fbc40aed7..0d0e86aa9b2 100644 --- a/translator/src/org/jetbrains/k2js/translate/utils/TranslationUtils.java +++ b/translator/src/org/jetbrains/k2js/translate/utils/TranslationUtils.java @@ -130,12 +130,4 @@ public final class TranslationUtils { JsNameRef backingFieldReference = backingFieldReference(context, descriptor); return AstUtil.newAssignmentStatement(backingFieldReference, parameter.getName().makeRef()); } - - @NotNull - public static JsStatement assignmentToBackingFieldFromParameter(@NotNull TranslationContext context, - @NotNull JetProperty property, - @NotNull JsParameter parameter) { - return assignmentToBackingFieldFromParameter - (context, BindingUtils.getPropertyDescriptor(context.bindingContext(), property), parameter); - } } diff --git a/translator/test/org/jetbrains/k2js/test/OperatorOverloadingTest.java b/translator/test/org/jetbrains/k2js/test/OperatorOverloadingTest.java index 42efb229d9c..68764501724 100644 --- a/translator/test/org/jetbrains/k2js/test/OperatorOverloadingTest.java +++ b/translator/test/org/jetbrains/k2js/test/OperatorOverloadingTest.java @@ -79,11 +79,10 @@ public class OperatorOverloadingTest extends TranslationTest { testFooBoxIsTrue("notOverload.kt"); } - //TODO: test fails due to issue KT-618 -// @Test -// public void compareTo() throws Exception { -// testFooBoxIsTrue("compareTo.kt"); -// } + @Test + public void compareTo() throws Exception { + testFooBoxIsTrue("compareTo.kt"); + } @Test public void plusAndMinusAsAnExpression() throws Exception { diff --git a/translator/testFiles/operatorOverloading/cases/compareTo.kt b/translator/testFiles/operatorOverloading/cases/compareTo.kt index 816054e2846..5b88e78c579 100644 --- a/translator/testFiles/operatorOverloading/cases/compareTo.kt +++ b/translator/testFiles/operatorOverloading/cases/compareTo.kt @@ -1,17 +1,11 @@ namespace foo - class A(t : Int) : Comparable { + class A(t : Int) { var i = t - override fun compareTo(other : A) = (this.i - other.i) + fun compareTo(other : A) = (this.i - other.i) } fun box() : Boolean{ return (A(3) > A(2)) && (A(2) >= A(2)) && (A(1) >= A(0)) && (A(2) <= A(2)) && (A(3) <= A(4)) && (A(0) < A(100)) } - - - -fun main(args : Array) { - System.out?.println(box()) -} \ No newline at end of file