Supported SAM adapters in augmented assignment operators.

This commit is contained in:
Evgeny Gerashchenko
2013-06-26 00:51:52 +04:00
parent 036960f117
commit 0059db486f
6 changed files with 109 additions and 1 deletions
@@ -55,7 +55,8 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.*;
class CodegenAnnotatingVisitor extends JetVisitorVoid {
private static final TokenSet BINARY_OPERATIONS =
TokenSet.create(JetTokens.PLUS, JetTokens.MINUS, JetTokens.MUL, JetTokens.DIV, JetTokens.PERC, JetTokens.RANGE);
TokenSet.orSet(JetTokens.AUGMENTED_ASSIGNMENTS,
TokenSet.create(JetTokens.PLUS, JetTokens.MINUS, JetTokens.MUL, JetTokens.DIV, JetTokens.PERC, JetTokens.RANGE));
private final Map<String, Integer> anonymousSubclassesCount = new HashMap<String, Integer>();
@@ -0,0 +1,21 @@
class JavaClass {
void plusAssign(Runnable i) {
i.run();
}
void minusAssign(Runnable i) {
i.run();
}
void timesAssign(Runnable i) {
i.run();
}
void divAssign(Runnable i) {
i.run();
}
void modAssign(Runnable i) {
i.run();
}
}
@@ -0,0 +1,25 @@
fun box(): String {
val obj = JavaClass()
var v1 = "FAIL"
obj += { v1 = "OK" }
if (v1 != "OK") return "plus: $v1"
var v2 = "FAIL"
obj -= { v2 = "OK" }
if (v2 != "OK") return "minus: $v2"
var v3 = "FAIL"
obj *= { v3 = "OK" }
if (v3 != "OK") return "times: $v3"
var v4 = "FAIL"
obj /= { v4 = "OK" }
if (v4 != "OK") return "div: $v4"
var v5 = "FAIL"
obj %= { v5 = "OK" }
if (v5 != "OK") return "mod: $v5"
return "OK"
}
@@ -0,0 +1,26 @@
class JavaClass {
JavaClass plus(Runnable i) {
i.run();
return this;
}
JavaClass minus(Runnable i) {
i.run();
return this;
}
JavaClass times(Runnable i) {
i.run();
return this;
}
JavaClass div(Runnable i) {
i.run();
return this;
}
JavaClass mod(Runnable i) {
i.run();
return this;
}
}
@@ -0,0 +1,25 @@
fun box(): String {
var obj = JavaClass()
var v1 = "FAIL"
obj += { v1 = "OK" }
if (v1 != "OK") return "plus: $v1"
var v2 = "FAIL"
obj -= { v2 = "OK" }
if (v2 != "OK") return "minus: $v2"
var v3 = "FAIL"
obj *= { v3 = "OK" }
if (v3 != "OK") return "times: $v3"
var v4 = "FAIL"
obj /= { v4 = "OK" }
if (v4 != "OK") return "div: $v4"
var v5 = "FAIL"
obj %= { v5 = "OK" }
if (v5 != "OK") return "mod: $v5"
return "OK"
}
@@ -232,6 +232,16 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/boxWithJava/samAdapters/operators"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("augmentedAssignmentPure.kt")
public void testAugmentedAssignmentPure() throws Exception {
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentPure.kt");
}
@TestMetadata("augmentedAssignmentViaSimpleBinary.kt")
public void testAugmentedAssignmentViaSimpleBinary() throws Exception {
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentViaSimpleBinary.kt");
}
@TestMetadata("binary.kt")
public void testBinary() throws Exception {
doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/operators/binary.kt");