From 4855cace5740973241e69b5408a22182c459e3f3 Mon Sep 17 00:00:00 2001 From: badlogic Date: Wed, 15 Jul 2015 14:08:27 +0200 Subject: [PATCH] Added lambda test suite from Android's Jack --- .../org/robovm/compiler/config/Config.java | 4 +- .../robovm/rt/{ => lambdas}/LambdasTest.java | 2 +- .../org/robovm/rt/lambdas/test001/Lambda.java | 32 ++++++++ .../org/robovm/rt/lambdas/test001/Tests.java | 31 ++++++++ .../java/org/robovm/rt/lambdas/test002/I.java | 21 +++++ .../org/robovm/rt/lambdas/test002/Lambda.java | 28 +++++++ .../org/robovm/rt/lambdas/test002/Tests.java | 32 ++++++++ .../java/org/robovm/rt/lambdas/test003/I.java | 21 +++++ .../org/robovm/rt/lambdas/test003/Lambda.java | 34 +++++++++ .../org/robovm/rt/lambdas/test003/Tests.java | 33 ++++++++ .../java/org/robovm/rt/lambdas/test004/I.java | 21 +++++ .../org/robovm/rt/lambdas/test004/Lambda.java | 34 +++++++++ .../org/robovm/rt/lambdas/test004/Tests.java | 33 ++++++++ .../java/org/robovm/rt/lambdas/test005/I.java | 21 +++++ .../org/robovm/rt/lambdas/test005/Lambda.java | 33 ++++++++ .../org/robovm/rt/lambdas/test005/Tests.java | 33 ++++++++ .../java/org/robovm/rt/lambdas/test006/I.java | 21 +++++ .../org/robovm/rt/lambdas/test006/Lambda.java | 38 ++++++++++ .../org/robovm/rt/lambdas/test006/Tests.java | 32 ++++++++ .../java/org/robovm/rt/lambdas/test007/I.java | 21 +++++ .../org/robovm/rt/lambdas/test007/Lambda.java | 31 ++++++++ .../org/robovm/rt/lambdas/test007/Tests.java | 33 ++++++++ .../robovm/rt/lambdas/test007/UseLambda.java | 24 ++++++ .../java/org/robovm/rt/lambdas/test008/I.java | 21 +++++ .../org/robovm/rt/lambdas/test008/Lambda.java | 29 +++++++ .../org/robovm/rt/lambdas/test008/Tests.java | 32 ++++++++ .../java/org/robovm/rt/lambdas/test009/I.java | 21 +++++ .../org/robovm/rt/lambdas/test009/Lambda.java | 46 +++++++++++ .../rt/lambdas/test009/Test009Exception.java | 23 ++++++ .../org/robovm/rt/lambdas/test009/Tests.java | 48 ++++++++++++ .../org/robovm/rt/lambdas/test010/jack/I.java | 24 ++++++ .../rt/lambdas/test010/jack/Lambda.java | 42 ++++++++++ .../robovm/rt/lambdas/test010/jack/Tests.java | 31 ++++++++ .../robovm/rt/lambdas/test010/mapping.flags | 1 + .../robovm/rt/lambdas/test010/proguard.flags | 6 ++ .../org/robovm/rt/lambdas/test011/Lambda.java | 43 +++++++++++ .../org/robovm/rt/lambdas/test011/Tests.java | 32 ++++++++ .../org/robovm/rt/lambdas/test012/Lambda.java | 43 +++++++++++ .../org/robovm/rt/lambdas/test012/Tests.java | 32 ++++++++ .../org/robovm/rt/lambdas/test013/Lambda.java | 34 +++++++++ .../org/robovm/rt/lambdas/test013/Tests.java | 32 ++++++++ .../org/robovm/rt/lambdas/test014/Lambda.java | 45 +++++++++++ .../org/robovm/rt/lambdas/test014/Tests.java | 32 ++++++++ .../org/robovm/rt/lambdas/test015/Lambda.java | 36 +++++++++ .../org/robovm/rt/lambdas/test015/Tests.java | 32 ++++++++ .../org/robovm/rt/lambdas/test016/Lambda.java | 31 ++++++++ .../org/robovm/rt/lambdas/test016/Tests.java | 32 ++++++++ .../org/robovm/rt/lambdas/test017/Lambda.java | 47 ++++++++++++ .../org/robovm/rt/lambdas/test017/Tests.java | 33 ++++++++ .../org/robovm/rt/lambdas/test018/Lambda.java | 76 +++++++++++++++++++ .../org/robovm/rt/lambdas/test018/Tests.java | 36 +++++++++ 51 files changed, 1550 insertions(+), 3 deletions(-) rename tests/robovm/src/test/java/org/robovm/rt/{ => lambdas}/LambdasTest.java (98%) create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test001/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test001/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test002/I.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test002/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test002/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test003/I.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test003/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test003/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test004/I.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test004/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test004/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test005/I.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test005/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test005/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test006/I.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test006/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test006/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/I.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/UseLambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test008/I.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test008/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test008/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/I.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/Test009Exception.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/jack/I.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/jack/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/jack/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/mapping.flags create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/proguard.flags create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test011/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test011/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test012/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test012/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test013/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test013/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test014/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test014/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test015/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test015/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test016/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test016/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test017/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test017/Tests.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test018/Lambda.java create mode 100644 tests/robovm/src/test/java/org/robovm/rt/lambdas/test018/Tests.java diff --git a/compiler/src/main/java/org/robovm/compiler/config/Config.java b/compiler/src/main/java/org/robovm/compiler/config/Config.java index 4d39f0c40..addd89b61 100644 --- a/compiler/src/main/java/org/robovm/compiler/config/Config.java +++ b/compiler/src/main/java/org/robovm/compiler/config/Config.java @@ -225,8 +225,8 @@ protected Config() throws IOException { new ObjCMemberPlugin(), new ObjCBlockPlugin(), new AnnotationImplPlugin(), - // new LambdaPlugin() - new org.robovm.compiler.plugin.lambda2.LambdaPlugin() + new LambdaPlugin() + //new org.robovm.compiler.plugin.lambda2.LambdaPlugin() )); this.loadPluginsFromClassPath(); } diff --git a/tests/robovm/src/test/java/org/robovm/rt/LambdasTest.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/LambdasTest.java similarity index 98% rename from tests/robovm/src/test/java/org/robovm/rt/LambdasTest.java rename to tests/robovm/src/test/java/org/robovm/rt/lambdas/LambdasTest.java index 44368f377..e86cd990c 100644 --- a/tests/robovm/src/test/java/org/robovm/rt/LambdasTest.java +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/LambdasTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.robovm.rt; +package org.robovm.rt.lambdas; import static org.junit.Assert.*; diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test001/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test001/Lambda.java new file mode 100644 index 000000000..78f95b4ba --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test001/Lambda.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test001; + +interface I { + int getValue(); +} + +/** + * Lambda expression test without parameters. + */ +public class Lambda { + + public static int testGet10() { + I i = () -> 10; + return i.getValue(); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test001/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test001/Tests.java new file mode 100644 index 000000000..d8a5c3ef0 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test001/Tests.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test001; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Lambda expression test without parameters. + */ +public class Tests { + + @Test + public void test001() { + Assert.assertEquals(10, Lambda.testGet10()); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test002/I.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test002/I.java new file mode 100644 index 000000000..3ffcd706a --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test002/I.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test002; + +interface I { + int add(int a, int b); +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test002/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test002/Lambda.java new file mode 100644 index 000000000..3ee575325 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test002/Lambda.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test002; + +/** + * Lambda expression test with parameters. + */ +public class Lambda { + + public static int testAdd(int a, int b) { + I i = (x, y) -> x + y; + return i.add(a, b); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test002/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test002/Tests.java new file mode 100644 index 000000000..e27634dbd --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test002/Tests.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test002; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Lambda expression test with parameters. + */ +public class Tests { + + @Test + public void test001() { + Assert.assertEquals(10, Lambda.testAdd(5, 5)); + Assert.assertEquals(8, Lambda.testAdd(5, 3)); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test003/I.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test003/I.java new file mode 100644 index 000000000..aab9d01e5 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test003/I.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test003; + +interface I { + int addOutsideValue(); +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test003/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test003/Lambda.java new file mode 100644 index 000000000..6ef4272f1 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test003/Lambda.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test003; + +/** + * Test with lambda expression accessing field and local variable from enclosing class. + */ +public class Lambda { + + private int field; + + public Lambda(int value) { + this.field = value; + } + + public int testAdd(int a) { + I i = () -> a + field; + return i.addOutsideValue(); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test003/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test003/Tests.java new file mode 100644 index 000000000..2c99be4e3 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test003/Tests.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test003; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Test with lambda expression accessing field and local variable from enclosing class. + */ +public class Tests { + + @Test + public void test001() { + Lambda lambda = new Lambda(5); + Assert.assertEquals(10, lambda.testAdd(5)); + Assert.assertEquals(8, lambda.testAdd(3)); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test004/I.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test004/I.java new file mode 100644 index 000000000..4a441f96b --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test004/I.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test004; + +interface I { + int addOutsideValue(); +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test004/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test004/Lambda.java new file mode 100644 index 000000000..2976b5ede --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test004/Lambda.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test004; + + +/** + * Test casting lambda expression. + */ +public class Lambda { + + private int field; + + public Lambda(int value) { + this.field = value; + } + + public int testAdd(int a) { + return ((I)() -> a + field).addOutsideValue(); + } +} \ No newline at end of file diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test004/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test004/Tests.java new file mode 100644 index 000000000..f0142e506 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test004/Tests.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test004; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Test casting lambda expression. + */ +public class Tests { + + @Test + public void test001() { + Lambda lambda = new Lambda(5); + Assert.assertEquals(10, lambda.testAdd(5)); + Assert.assertEquals(8, lambda.testAdd(3)); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test005/I.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test005/I.java new file mode 100644 index 000000000..44a271532 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test005/I.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test005; + +interface I { + int add(V val1, V val2); +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test005/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test005/Lambda.java new file mode 100644 index 000000000..9b39ddb79 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test005/Lambda.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test005; + +/** + * Lambda expression with generic. + */ +public class Lambda { + + public int testAddInt(int i1, int i2) { + I i = (a, b) -> a.intValue() + b.intValue(); + return i.add(new Integer(i1), new Integer(i2)); + } + + public int testAddDouble(double d1, double d2) { + I i = (a, b) -> a.intValue() + b.intValue(); + return i.add(new Double(d1), new Double(d2)); + } +} \ No newline at end of file diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test005/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test005/Tests.java new file mode 100644 index 000000000..516ae0b98 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test005/Tests.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test005; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Lambda expression with generic. + */ +public class Tests { + + @Test + public void test001() { + Lambda lambda = new Lambda(); + Assert.assertEquals(30, lambda.testAddInt(10, 20)); + Assert.assertEquals(20, lambda.testAddDouble(15.45, 5.23)); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test006/I.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test006/I.java new file mode 100644 index 000000000..58b602216 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test006/I.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test006; + +interface I { + int add(V val1, V val2); +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test006/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test006/Lambda.java new file mode 100644 index 000000000..753e32051 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test006/Lambda.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test006; + +/** + * Test that mixed lambda with non lambda expression of the same type. + */ +public class Lambda { + + public class A implements I { + @Override + public int add(Double val1, Double val2) { + return (int) (val1.doubleValue() + val2.doubleValue()); + } + } + + public int testAddDouble(double d1, double d2) { + Double D1 = new Double(d1); + Double D2 = new Double(d2); + I i = (a, b) -> a.intValue() + b.intValue() + 1; + I a = new A(); + return i.add(D1, D2) + a.add(D1, D2); + } +} \ No newline at end of file diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test006/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test006/Tests.java new file mode 100644 index 000000000..b70de321d --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test006/Tests.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test006; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Test that mixed lambda with non lambda expression of the same type. + */ +public class Tests { + + @Test + public void test001() { + Lambda lambda = new Lambda(); + Assert.assertEquals(41, lambda.testAddDouble(15.45, 5.23)); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/I.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/I.java new file mode 100644 index 000000000..eb1cc8be3 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/I.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test007; + +interface I { + int add(V val1, V val2); +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/Lambda.java new file mode 100644 index 000000000..b5933e965 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/Lambda.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test007; + +/** + * Test returning a lambda expression accessing local values that will be used outside his + * definition scope. + */ +public class Lambda { + + private int fieldValue = 10; + + public I getLambda() { + int localConstant = 1; + return (a, b) -> a.intValue() + b.intValue() + localConstant + fieldValue; + } +} \ No newline at end of file diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/Tests.java new file mode 100644 index 000000000..9ccfa5176 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/Tests.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test007; + +import org.junit.Assert; +import org.junit.Test; + + +/** + * Test returning a lambda expression accessing local values that will be used outside his + * definition scope. + */ +public class Tests { + + @Test + public void test001() { + Assert.assertEquals(35, UseLambda.testAddDouble(15.4, 9.08)); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/UseLambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/UseLambda.java new file mode 100644 index 000000000..e279d0995 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test007/UseLambda.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test007; + +public class UseLambda { + + public static int testAddDouble(double d1, double d2) { + return new Lambda().getLambda().add(new Double(d1), new Double (d2)); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test008/I.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test008/I.java new file mode 100644 index 000000000..cefd732dd --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test008/I.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test008; + +interface I { + V add(int v1, int v2); +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test008/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test008/Lambda.java new file mode 100644 index 000000000..414a62eb6 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test008/Lambda.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test008; + +/** + * Test that check that boxing work in lambda body and that return type with generic works properly + */ +public class Lambda { + + @SuppressWarnings("boxing") + public int testAddInt(int v1, int v2) { + I i = (a, b) -> a + b + 1; + return i.add(v1, v2).intValue(); + } +} \ No newline at end of file diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test008/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test008/Tests.java new file mode 100644 index 000000000..23523b0f4 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test008/Tests.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test008; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Test that check that boxing work in lambda body and that return type with generic works properly + */ +public class Tests { + + @Test + public void test001() { + Lambda lambda = new Lambda(); + Assert.assertEquals(21, lambda.testAddInt(15, 5)); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/I.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/I.java new file mode 100644 index 000000000..813d152ca --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/I.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test009; + +interface I { + int add(int v1, int v2) throws Test009Exception; +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/Lambda.java new file mode 100644 index 000000000..2530f0f46 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/Lambda.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test009; + +/** + * Test using exception with lambda. + */ +public class Lambda { + + public int testAddInt(int v1, int v2) { + I i = (a, b) -> a + b; + try { + return i.add(v1, v2); + } catch (Test009Exception e) { + return 1; + } + } + + public int testCatchingException() { + I i = (a, b) -> { throw new Test009Exception(); }; + try { + return i.add(0, 0); + } catch (Test009Exception e) { + return 1; + } + } + + public int testThrowingException() throws Test009Exception { + I i = (a, b) -> { throw new Test009Exception(); }; + return i.add(0, 0); + } +} \ No newline at end of file diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/Test009Exception.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/Test009Exception.java new file mode 100644 index 000000000..1b6519863 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/Test009Exception.java @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test009; + +public class Test009Exception extends Exception { + + private static final long serialVersionUID = 1L; + +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/Tests.java new file mode 100644 index 000000000..6b9496e25 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test009/Tests.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test009; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Test using exception with lambda. + */ +public class Tests { + + @Test + public void test001() { + Lambda lambda = new Lambda(); + Assert.assertEquals(20, lambda.testAddInt(15, 5)); + } + + @Test + public void test002() { + Lambda lambda = new Lambda(); + Assert.assertEquals(1, lambda.testCatchingException()); + } + + @Test + public void test003() { + try { + Lambda lambda = new Lambda(); + lambda.testThrowingException(); + Assert.fail(); + } catch (Test009Exception e) { + } + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/jack/I.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/jack/I.java new file mode 100644 index 000000000..4d5d2202d --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/jack/I.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test010.jack; + +/** + * Interface used with lambda. + */ +interface I { + int getValue(); +} \ No newline at end of file diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/jack/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/jack/Lambda.java new file mode 100644 index 000000000..afb054d85 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/jack/Lambda.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test010.jack; + +/** + * Lambda with obfuscation to check that MethodId is well managed + */ +public class Lambda { + + class C implements I { + @Override + public int getValue() { + return 20; + } + } + + class D implements I { + @Override + public int getValue() { + return 30; + } + } + + public int testGet10() { + I i = () -> 10; + return i.getValue() + new D().getValue() + new C().getValue(); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/jack/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/jack/Tests.java new file mode 100644 index 000000000..1f2a11358 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/jack/Tests.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test010.jack; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Lambda with obfuscation to check that MethodId is well managed + */ +public class Tests { + + @Test + public void test001() { + Assert.assertEquals(60, new Lambda().testGet10()); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/mapping.flags b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/mapping.flags new file mode 100644 index 000000000..ddadfdec0 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/mapping.flags @@ -0,0 +1 @@ +com.android.jack.java8.lambda.test010.jack.I -> com.android.jack.java8.lambda.test010.jack.Z: \ No newline at end of file diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/proguard.flags b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/proguard.flags new file mode 100644 index 000000000..1a40ce346 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test010/proguard.flags @@ -0,0 +1,6 @@ +-applymapping mapping.flags + +-keepattributes +-keep class * { + *; +} \ No newline at end of file diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test011/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test011/Lambda.java new file mode 100644 index 000000000..faabf4076 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test011/Lambda.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test011; + +/** + * Lambda accessing super members. + */ +interface I { + int getValue(); +} + + +class SuperLambda { + protected int field = 10; + int getValue() { + return 10; + } +} + + +public class Lambda extends SuperLambda { + + public int testAccessingSuperMembers() { + I i = () -> { + return field + this.getValue() ; + }; + return i.getValue(); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test011/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test011/Tests.java new file mode 100644 index 000000000..8d7cc2c43 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test011/Tests.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test011; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Lambda accessing super members. + */ +public class Tests { + + @Test + public void test001() { + Lambda lambda = new Lambda(); + Assert.assertEquals(20, lambda.testAccessingSuperMembers()); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test012/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test012/Lambda.java new file mode 100644 index 000000000..7521bbaee --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test012/Lambda.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test012; + +/** + * Lambda expression into another lambda expression. + */ +interface I1 { + int getValue1(); +} + + +interface I2 { + int getValue2(); +} + +public class Lambda { + + public int testWithNestedLambda(int a) { + I1 i1 = () -> { + int b = 10; + I2 i2 = () -> { + return a + b; + }; + return a + i2.getValue2(); + }; + return i1.getValue1(); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test012/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test012/Tests.java new file mode 100644 index 000000000..179d36d61 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test012/Tests.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test012; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Lambda expression into another lambda expression. + */ +public class Tests { + + @Test + public void test001() { + Lambda lambda = new Lambda(); + Assert.assertEquals(30, lambda.testWithNestedLambda(10)); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test013/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test013/Lambda.java new file mode 100644 index 000000000..4096a051c --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test013/Lambda.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test013; + +/** + * Lambda specifying parameter types. + */ +interface I { + int addValues(int v1, float v2, short v3, byte v4); +} + +public class Lambda { + + public int addValues() { + I i = (int v1, float v2, short v3, byte v4) -> { + return v1 + (int) v2 + v3 + v4; + }; + return i.addValues(1, 2, (short) 3, (byte) 4); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test013/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test013/Tests.java new file mode 100644 index 000000000..440163d8f --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test013/Tests.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test013; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Lambda specifying parameter types. + */ +public class Tests { + + @Test + public void test001() { + Lambda lambda = new Lambda(); + Assert.assertEquals(10, lambda.addValues()); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test014/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test014/Lambda.java new file mode 100644 index 000000000..77a0812f5 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test014/Lambda.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test014; + +/** + * Lambda mixing vararg and array. + */ +interface I { + int addValues(int[] values); +} + +public class Lambda { + + public int addValues() { + I i1 = (v1) -> { + int sum = 0; + for (int v : v1) { + sum += v; + } + return sum; + }; + I i2 = (int ...v1) -> { + int sum = 0; + for (int v : v1) { + sum += v; + } + return sum; + }; + return i1.addValues(new int[]{1,2,3,4}) + i2.addValues(new int[]{1,2,3,4}); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test014/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test014/Tests.java new file mode 100644 index 000000000..20f21ddfe --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test014/Tests.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test014; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Lambda mixing vararg and array. + */ +public class Tests { + + @Test + public void test001() { + Lambda lambda = new Lambda(); + Assert.assertEquals(20, lambda.addValues()); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test015/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test015/Lambda.java new file mode 100644 index 000000000..bfee5b0c1 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test015/Lambda.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test015; + +/** + * Nested lambda expression. + */ +interface Printable { + T getPrintable(); +} + +interface People { + String getMessage(String name); +} + +public class Lambda { + + public String getString() { + Printable p = () -> (name) -> name; + return p.getPrintable().getMessage("Jack"); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test015/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test015/Tests.java new file mode 100644 index 000000000..d80256fdb --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test015/Tests.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test015; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Nested lambda expression. + */ +public class Tests { + + @Test + public void test001() { + Lambda lambda = new Lambda(); + Assert.assertEquals("Jack", lambda.getString()); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test016/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test016/Lambda.java new file mode 100644 index 000000000..d4306d13f --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test016/Lambda.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test016; + +/** + * Lambda expression into array initializer. + */ +interface I { + String getString(); +} + +public class Lambda { + public String getString() { + I[] array = new I[] {() -> "Hello", () -> " World"}; + return array[0].getString() + array[1].getString(); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test016/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test016/Tests.java new file mode 100644 index 000000000..d43248df6 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test016/Tests.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test016; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Lambda expression into array initializer. + */ +public class Tests { + + @Test + public void test001() { + Lambda lambda = new Lambda(); + Assert.assertEquals("Hello World", lambda.getString()); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test017/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test017/Lambda.java new file mode 100644 index 000000000..169064540 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test017/Lambda.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test017; + +/** + * Use parameter type of lambda when type inference could not select the right type. + */ +interface I { + Number getNumber(int i); +} + +interface I1 { + Number getNumber(float f); +} + +public class Lambda { + + public Number m(I i) { + return i.getNumber(1); + } + + public Number m(I1 i1) { + return i1.getNumber(2f); + } + + public Number getInt() { + return (m((int i) -> new Integer(i))); + } + + public Number getFloat() { + return (m((float i) -> new Float(i))); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test017/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test017/Tests.java new file mode 100644 index 000000000..219e4a75e --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test017/Tests.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test017; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Use parameter type of lambda when type inference could not select the right type + */ +public class Tests { + + @Test + public void test001() { + Lambda lambda = new Lambda(); + Assert.assertEquals(1, lambda.getInt().intValue()); + Assert.assertTrue(lambda.getFloat().floatValue() == 2f); + } +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test018/Lambda.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test018/Lambda.java new file mode 100644 index 000000000..b1e33dc09 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test018/Lambda.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test018; + +/** + * Test target typing with overloading methods. + */ + +interface I1 { + void m(); +} + +interface I2 { + String m(); +} + +interface I3 { + int m(); +} + +class C { + + int idMethod; + + void call(I1 i1) { + idMethod = 1; + i1.m(); + } + + String call(I2 i2) { + idMethod = 2; + return i2.m(); + } + + int call(I3 i3) { + idMethod = 3; + return i3.m(); + } + +} + +public class Lambda { + + public String test1() { + C c = new C(); + c.call(() -> {int i = 0;}); + return c.idMethod + "-void"; + } + + public String test2() { + C c = new C(); + String s = c.call(() -> "test"); + return c.idMethod + "-" + s; + } + + public String test3() { + C c = new C(); + int r = c.call(() -> "test".length()); + return c.idMethod + "-" + r; + } + +} diff --git a/tests/robovm/src/test/java/org/robovm/rt/lambdas/test018/Tests.java b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test018/Tests.java new file mode 100644 index 000000000..6e68ffdd7 --- /dev/null +++ b/tests/robovm/src/test/java/org/robovm/rt/lambdas/test018/Tests.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.robovm.rt.lambdas.test018; + + +import junit.framework.Assert; + +import org.junit.Test; + +/** + * Test target typing with overloading methods. + */ +public class Tests { + + @Test + public void test001() { + Lambda lambda = new Lambda(); + Assert.assertEquals("1-void", lambda.test1()); + Assert.assertEquals("2-test", lambda.test2()); + Assert.assertEquals("3-4", lambda.test3()); + } +}