diff --git a/tests/io.sarl.lang.tests/src/test/java/io/sarl/lang/tests/bugs/to00999/Bug885.java b/tests/io.sarl.lang.tests/src/test/java/io/sarl/lang/tests/bugs/to00999/Bug885.java
index 440fc78edc..4dac5b45cf 100644
--- a/tests/io.sarl.lang.tests/src/test/java/io/sarl/lang/tests/bugs/to00999/Bug885.java
+++ b/tests/io.sarl.lang.tests/src/test/java/io/sarl/lang/tests/bugs/to00999/Bug885.java
@@ -3160,5 +3160,532 @@ public void compilingComplexLambda01() throws Exception {
});
}
+ private static final String SNIPSET_COMPLEX_LAMBDA_02 = multilineString(
+ "package io.sarl.lang.tests.bug885",
+ "import io.sarl.lang.core.Address",
+ "import io.sarl.lang.core.Scope",
+ "import java.util.UUID",
+ "agent Boot {",
+ " def f(s : Scope
) {",
+ " }",
+ " def f2(s : Scope) {",
+ " f [ val p = it",
+ " var sss : (Address) => UUID = [a|if(a != null) a.UUID else p.UUID]",
+ " it.UUID == sss.apply(p) ]",
+ " }",
+ "}");
+
+ private static final String EXPECTED_COMPLEX_LAMBDA_02 = multilineString(
+ "package io.sarl.lang.tests.bug885;",
+ "",
+ "import com.google.common.base.Objects;",
+ "import io.sarl.lang.annotation.SarlElementType;",
+ "import io.sarl.lang.annotation.SarlSpecification;",
+ "import io.sarl.lang.annotation.SyntheticMember;",
+ "import io.sarl.lang.core.Address;",
+ "import io.sarl.lang.core.Agent;",
+ "import io.sarl.lang.core.BuiltinCapacitiesProvider;",
+ "import io.sarl.lang.core.DynamicSkillProvider;",
+ "import io.sarl.lang.core.Scope;",
+ "import io.sarl.lang.util.SerializableProxy;",
+ "import java.io.ObjectStreamException;",
+ "import java.util.UUID;",
+ "import javax.inject.Inject;",
+ "import org.eclipse.xtext.xbase.lib.Functions.Function1;",
+ "import org.eclipse.xtext.xbase.lib.Pure;",
+ "",
+ "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
+ "@SarlElementType(" + SarlPackage.SARL_AGENT + ")",
+ "@SuppressWarnings(\"all\")",
+ "public class Boot extends Agent {",
+ " @Pure",
+ " protected void f(final Scope s) {",
+ " }",
+ " ",
+ " @Pure",
+ " protected void f2(final Scope s) {",
+ " class $SerializableClosureProxy implements Scope {",
+ " ",
+ " private final Address $_a;",
+ " ",
+ " private final UUID $_uUID;",
+ " ",
+ " public $SerializableClosureProxy(final Address $_a, final UUID $_uUID) {",
+ " this.$_a = $_a;",
+ " this.$_uUID = $_uUID;",
+ " }",
+ " ",
+ " @Override",
+ " public boolean matches(final Address it) {",
+ " boolean _xblockexpression = false;",
+ " {",
+ " final Address p = it;",
+ " final Function1 _function = (Address a) -> {",
+ " UUID _xifexpression = null;",
+ " boolean _notEquals = (!Objects.equal($_a, null));",
+ " if (_notEquals) {",
+ " _xifexpression = $_uUID;",
+ " } else {",
+ " _xifexpression = p.getUUID();",
+ " }",
+ " return _xifexpression;",
+ " };",
+ " Function1 super Address, ? extends UUID> sss = _function;",
+ " UUID _uUID = it.getUUID();",
+ " UUID _apply = sss.apply(p);",
+ " _xblockexpression = Objects.equal(_uUID, _apply);",
+ " }",
+ " return _xblockexpression;",
+ " }",
+ " }",
+ " final Scope _function = new Scope() {",
+ " @Override",
+ " public boolean matches(final Address it) {",
+ " boolean _xblockexpression = false;",
+ " {",
+ " final Address p = it;",
+ " final Function1 _function = (Address a) -> {",
+ " UUID _xifexpression = null;",
+ " boolean _notEquals = (!Objects.equal(a, null));",
+ " if (_notEquals) {",
+ " _xifexpression = a.getUUID();",
+ " } else {",
+ " _xifexpression = p.getUUID();",
+ " }",
+ " return _xifexpression;",
+ " };",
+ " Function1 super Address, ? extends UUID> sss = _function;",
+ " UUID _uUID = it.getUUID();",
+ " UUID _apply = sss.apply(p);",
+ " _xblockexpression = Objects.equal(_uUID, _apply);",
+ " }",
+ " return _xblockexpression;",
+ " }",
+ " private Object writeReplace() throws ObjectStreamException {",
+ " return new SerializableProxy($SerializableClosureProxy.class, a, a.getUUID());",
+ " }",
+ " };",
+ " this.f(_function);",
+ " }",
+ " ",
+ " @SyntheticMember",
+ " public Boot(final UUID arg0, final UUID arg1) {",
+ " super(arg0, arg1);",
+ " }",
+ " ",
+ " @SyntheticMember",
+ " @Deprecated",
+ " @Inject",
+ " public Boot(final BuiltinCapacitiesProvider arg0, final UUID arg1, final UUID arg2) {",
+ " super(arg0, arg1, arg2);",
+ " }",
+ " ",
+ " @SyntheticMember",
+ " @Inject",
+ " public Boot(final UUID arg0, final UUID arg1, final DynamicSkillProvider arg2) {",
+ " super(arg0, arg1, arg2);",
+ " }",
+ "}",
+ "");
+
+ @Test
+ public void compilingComplexLambda02() throws Exception {
+ /*SarlScript mas = file(SNIPSET02);
+ final Validator validator = validate(mas);
+ validator.assertNoErrors();*/
+ this.compiler.compile(SNIPSET_COMPLEX_LAMBDA_02, (it) -> {
+ String actual;
+ actual = it.getGeneratedCode("io.sarl.lang.tests.bug885.Boot");
+ assertEquals(EXPECTED_COMPLEX_LAMBDA_02, actual);
+ });
+ }
+
+ private static final String SNIPSET_COMPLEX_LAMBDA_03 = multilineString(
+ "package io.sarl.lang.tests.bug885",
+ "import io.sarl.lang.core.Address",
+ "import io.sarl.lang.core.Scope",
+ "import java.util.UUID",
+ "agent Boot {",
+ " def f(s : Scope) {",
+ " }",
+ " def f2(s : Scope) {",
+ " for (UUID : newArrayList) {",
+ " f [it.UUID == UUID]",
+ " }",
+ " }",
+ "}");
+
+ private static final String EXPECTED_COMPLEX_LAMBDA_03 = multilineString(
+ "package io.sarl.lang.tests.bug885;",
+ "",
+ "import com.google.common.base.Objects;",
+ "import io.sarl.lang.annotation.SarlElementType;",
+ "import io.sarl.lang.annotation.SarlSpecification;",
+ "import io.sarl.lang.annotation.SyntheticMember;",
+ "import io.sarl.lang.core.Address;",
+ "import io.sarl.lang.core.Agent;",
+ "import io.sarl.lang.core.BuiltinCapacitiesProvider;",
+ "import io.sarl.lang.core.DynamicSkillProvider;",
+ "import io.sarl.lang.core.Scope;",
+ "import io.sarl.lang.util.SerializableProxy;",
+ "import java.io.ObjectStreamException;",
+ "import java.util.ArrayList;",
+ "import java.util.UUID;",
+ "import javax.inject.Inject;",
+ "import org.eclipse.xtext.xbase.lib.CollectionLiterals;",
+ "import org.eclipse.xtext.xbase.lib.Pure;",
+ "",
+ "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
+ "@SarlElementType(" + SarlPackage.SARL_AGENT + ")",
+ "@SuppressWarnings(\"all\")",
+ "public class Boot extends Agent {",
+ " @Pure",
+ " protected void f(final Scope s) {",
+ " }",
+ " ",
+ " @Pure",
+ " protected void f2(final Scope s) {",
+ " ArrayList _newArrayList = CollectionLiterals.newArrayList();",
+ " for (final UUID UUID : _newArrayList) {",
+ " class $SerializableClosureProxy implements Scope {",
+ " ",
+ " private final java.util.UUID UUID;",
+ " ",
+ " public $SerializableClosureProxy(final java.util.UUID UUID) {",
+ " this.UUID = UUID;",
+ " }",
+ " ",
+ " @Override",
+ " public boolean matches(final Address it) {",
+ " java.util.UUID _uUID = it.getUUID();",
+ " return Objects.equal(_uUID, UUID);",
+ " }",
+ " }",
+ " final Scope _function = new Scope() {",
+ " @Override",
+ " public boolean matches(final Address it) {",
+ " java.util.UUID _uUID = it.getUUID();",
+ " return Objects.equal(_uUID, UUID);",
+ " }",
+ " private Object writeReplace() throws ObjectStreamException {",
+ " return new SerializableProxy($SerializableClosureProxy.class, UUID);",
+ " }",
+ " };",
+ " this.f(_function);",
+ " }",
+ " }",
+ " ",
+ " @SyntheticMember",
+ " public Boot(final UUID arg0, final UUID arg1) {",
+ " super(arg0, arg1);",
+ " }",
+ " ",
+ " @SyntheticMember",
+ " @Deprecated",
+ " @Inject",
+ " public Boot(final BuiltinCapacitiesProvider arg0, final UUID arg1, final UUID arg2) {",
+ " super(arg0, arg1, arg2);",
+ " }",
+ " ",
+ " @SyntheticMember",
+ " @Inject",
+ " public Boot(final UUID arg0, final UUID arg1, final DynamicSkillProvider arg2) {",
+ " super(arg0, arg1, arg2);",
+ " }",
+ "}",
+ "");
+
+ @Test
+ public void compilingComplexLambda03() throws Exception {
+ /*SarlScript mas = file(SNIPSET02);
+ final Validator validator = validate(mas);
+ validator.assertNoErrors();*/
+ this.compiler.compile(SNIPSET_COMPLEX_LAMBDA_03, (it) -> {
+ String actual;
+ actual = it.getGeneratedCode("io.sarl.lang.tests.bug885.Boot");
+ assertEquals(EXPECTED_COMPLEX_LAMBDA_03, actual);
+ });
+ }
+
+ private static final String SNIPSET_COMPLEX_LAMBDA_04 = multilineString(
+ "package io.sarl.lang.tests.bug885",
+ "import io.sarl.lang.core.Address",
+ "import io.sarl.lang.core.Scope",
+ "import java.util.UUID",
+ "import org.eclipse.xtend.lib.annotations.Accessors",
+ "agent Boot {",
+ " def f(s : Scope) {",
+ " }",
+ " def f2(s : Scope) {",
+ " try {",
+ " throw new UUIDException(UUID.randomUUID);",
+ " } catch (e: UUIDException) {",
+ " f [ it.UUID == e.uuid]",
+ " }",
+ " }",
+ " static class UUIDException extends Exception {",
+ " @Accessors(PUBLIC_GETTER)",
+ " val uuid: UUID",
+ " new(uuid: UUID) {",
+ " this.uuid = uuid",
+ " }",
+ " }",
+ "}");
+
+ private static final String EXPECTED_COMPLEX_LAMBDA_04 = multilineString(
+ "package io.sarl.lang.tests.bug885;",
+ "",
+ "import io.sarl.lang.annotation.SarlElementType;",
+ "import io.sarl.lang.annotation.SarlSpecification;",
+ "import io.sarl.lang.annotation.SyntheticMember;",
+ "import io.sarl.lang.core.Address;",
+ "import io.sarl.lang.core.Agent;",
+ "import io.sarl.lang.core.BuiltinCapacitiesProvider;",
+ "import io.sarl.lang.core.DynamicSkillProvider;",
+ "import io.sarl.lang.core.Scope;",
+ "import io.sarl.lang.util.SerializableProxy;",
+ "import java.io.ObjectStreamException;",
+ "import java.util.Objects;",
+ "import java.util.UUID;",
+ "import javax.inject.Inject;",
+ "import org.eclipse.xtend.lib.annotations.AccessorType;",
+ "import org.eclipse.xtend.lib.annotations.Accessors;",
+ "import org.eclipse.xtext.xbase.lib.Exceptions;",
+ "import org.eclipse.xtext.xbase.lib.Pure;",
+ "",
+ "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
+ "@SarlElementType(" + SarlPackage.SARL_AGENT + ")",
+ "@SuppressWarnings(\"all\")",
+ "public class Boot extends Agent {",
+ " @SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
+ " @SarlElementType(" + SarlPackage.SARL_CLASS + ")",
+ " protected static class UUIDException extends Exception {",
+ " @Accessors(AccessorType.PUBLIC_GETTER)",
+ " private final UUID uuid;",
+ " ",
+ " public UUIDException(final UUID uuid) {",
+ " this.uuid = uuid;",
+ " }",
+ " ",
+ " @Override",
+ " @Pure",
+ " @SyntheticMember",
+ " public boolean equals(final Object obj) {",
+ " if (this == obj)",
+ " return true;",
+ " if (obj == null)",
+ " return false;",
+ " if (getClass() != obj.getClass())",
+ " return false;",
+ " UUIDException other = (UUIDException) obj;",
+ " if (!Objects.equals(this.uuid, other.uuid)) {",
+ " return false;",
+ " }",
+ " return super.equals(obj);",
+ " }",
+ " ",
+ " @Override",
+ " @Pure",
+ " @SyntheticMember",
+ " public int hashCode() {",
+ " int result = super.hashCode();",
+ " final int prime = 31;",
+ " result = prime * result + Objects.hashCode(this.uuid);",
+ " return result;",
+ " }",
+ " ",
+ " @SyntheticMember",
+ " private final static long serialVersionUID = 2117806963L;",
+ " }",
+ " ",
+ " @Pure",
+ " protected void f(final Scope s) {",
+ " }",
+ " ",
+ " @Pure",
+ " protected void f2(final Scope s) {",
+ " try {",
+ " UUID _randomUUID = UUID.randomUUID();",
+ " throw new Boot.UUIDException(_randomUUID);",
+ " } catch (final Throwable _t) {",
+ " if (_t instanceof Boot.UUIDException) {",
+ " final Boot.UUIDException e = (Boot.UUIDException)_t;",
+ " class $SerializableClosureProxy implements Scope {",
+ " ",
+ " private final UUID $_uuid;",
+ " ",
+ " public $SerializableClosureProxy(final UUID $_uuid) {",
+ " this.$_uuid = $_uuid;",
+ " }",
+ " ",
+ " @Override",
+ " public boolean matches(final Address it) {",
+ " UUID _uUID = it.getUUID();",
+ " return com.google.common.base.Objects.equal(_uUID, $_uuid);",
+ " }",
+ " }",
+ " final Scope _function = new Scope() {",
+ " @Override",
+ " public boolean matches(final Address it) {",
+ " UUID _uUID = it.getUUID();",
+ " return com.google.common.base.Objects.equal(_uUID, e.uuid);",
+ " }",
+ " private Object writeReplace() throws ObjectStreamException {",
+ " return new SerializableProxy($SerializableClosureProxy.class, e.uuid);",
+ " }",
+ " };",
+ " this.f(_function);",
+ " } else {",
+ " throw Exceptions.sneakyThrow(_t);",
+ " }",
+ " }",
+ " }",
+ " ",
+ " @SyntheticMember",
+ " public Boot(final UUID arg0, final UUID arg1) {",
+ " super(arg0, arg1);",
+ " }",
+ " ",
+ " @SyntheticMember",
+ " @Deprecated",
+ " @Inject",
+ " public Boot(final BuiltinCapacitiesProvider arg0, final UUID arg1, final UUID arg2) {",
+ " super(arg0, arg1, arg2);",
+ " }",
+ " ",
+ " @SyntheticMember",
+ " @Inject",
+ " public Boot(final UUID arg0, final UUID arg1, final DynamicSkillProvider arg2) {",
+ " super(arg0, arg1, arg2);",
+ " }",
+ "}",
+ "");
+
+ @Test
+ public void compilingComplexLambda04() throws Exception {
+ /*SarlScript mas = file(SNIPSET02);
+ final Validator validator = validate(mas);
+ validator.assertNoErrors();*/
+ this.compiler.compile(SNIPSET_COMPLEX_LAMBDA_04, (it) -> {
+ String actual;
+ actual = it.getGeneratedCode("io.sarl.lang.tests.bug885.Boot");
+ assertEquals(EXPECTED_COMPLEX_LAMBDA_04, actual);
+ });
+ }
+
+ private static final String SNIPSET_COMPLEX_LAMBDA_05 = multilineString(
+ "package io.sarl.lang.tests.bug885",
+ "import io.sarl.lang.core.Address",
+ "import io.sarl.lang.core.Scope",
+ "import java.util.UUID",
+ "agent Boot {",
+ " def f(s : Scope) {",
+ " }",
+ " def f2(s : Scope) {",
+ " val random = UUID.randomUUID",
+ " f [ val uuid = it.UUID",
+ " val it = random",
+ " uuid == it",
+ " ]",
+ " }",
+ "}");
+
+ private static final String EXPECTED_COMPLEX_LAMBDA_05 = multilineString(
+ "package io.sarl.lang.tests.bug885;",
+ "",
+ "import com.google.common.base.Objects;",
+ "import io.sarl.lang.annotation.SarlElementType;",
+ "import io.sarl.lang.annotation.SarlSpecification;",
+ "import io.sarl.lang.annotation.SyntheticMember;",
+ "import io.sarl.lang.core.Address;",
+ "import io.sarl.lang.core.Agent;",
+ "import io.sarl.lang.core.BuiltinCapacitiesProvider;",
+ "import io.sarl.lang.core.DynamicSkillProvider;",
+ "import io.sarl.lang.core.Scope;",
+ "import io.sarl.lang.util.SerializableProxy;",
+ "import java.io.ObjectStreamException;",
+ "import java.util.UUID;",
+ "import javax.inject.Inject;",
+ "import org.eclipse.xtext.xbase.lib.Pure;",
+ "",
+ "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
+ "@SarlElementType(" + SarlPackage.SARL_AGENT + ")",
+ "@SuppressWarnings(\"all\")",
+ "public class Boot extends Agent {",
+ " @Pure",
+ " protected void f(final Scope s) {",
+ " }",
+ " ",
+ " @Pure",
+ " protected void f2(final Scope s) {",
+ " final UUID random = UUID.randomUUID();",
+ " class $SerializableClosureProxy implements Scope {",
+ " ",
+ " private final UUID random;",
+ " ",
+ " public $SerializableClosureProxy(final UUID random) {",
+ " this.random = random;",
+ " }",
+ " ",
+ " @Override",
+ " public boolean matches(final Address it) {",
+ " boolean _xblockexpression = false;",
+ " {",
+ " final UUID uuid = it.getUUID();",
+ " final UUID it_1 = random;",
+ " _xblockexpression = Objects.equal(uuid, it_1);",
+ " }",
+ " return _xblockexpression;",
+ " }",
+ " }",
+ " final Scope _function = new Scope() {",
+ " @Override",
+ " public boolean matches(final Address it) {",
+ " boolean _xblockexpression = false;",
+ " {",
+ " final UUID uuid = it.getUUID();",
+ " final UUID it_1 = random;",
+ " _xblockexpression = Objects.equal(uuid, it_1);",
+ " }",
+ " return _xblockexpression;",
+ " }",
+ " private Object writeReplace() throws ObjectStreamException {",
+ " return new SerializableProxy($SerializableClosureProxy.class, random);",
+ " }",
+ " };",
+ " this.f(_function);",
+ " }",
+ " ",
+ " @SyntheticMember",
+ " public Boot(final UUID arg0, final UUID arg1) {",
+ " super(arg0, arg1);",
+ " }",
+ " ",
+ " @SyntheticMember",
+ " @Deprecated",
+ " @Inject",
+ " public Boot(final BuiltinCapacitiesProvider arg0, final UUID arg1, final UUID arg2) {",
+ " super(arg0, arg1, arg2);",
+ " }",
+ " ",
+ " @SyntheticMember",
+ " @Inject",
+ " public Boot(final UUID arg0, final UUID arg1, final DynamicSkillProvider arg2) {",
+ " super(arg0, arg1, arg2);",
+ " }",
+ "}",
+ "");
+
+ @Test
+ public void compilingComplexLambda05() throws Exception {
+ /*SarlScript mas = file(SNIPSET02);
+ final Validator validator = validate(mas);
+ validator.assertNoErrors();*/
+ this.compiler.compile(SNIPSET_COMPLEX_LAMBDA_05, (it) -> {
+ String actual;
+ actual = it.getGeneratedCode("io.sarl.lang.tests.bug885.Boot");
+ assertEquals(EXPECTED_COMPLEX_LAMBDA_05, actual);
+ });
+ }
}