Skip to content

Commit

Permalink
[lang] Ensure correct referencing of this into the serialized lambdas.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Nov 27, 2018
1 parent 5e35f2c commit 9f409b3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
Expand Up @@ -28,7 +28,7 @@ package io.sarl.util
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @deprecated see SARLTimeExtensions
* @deprecated see {@link io.sarl.lang.scoping.extensions.time.TimeExtensions}
*/
@Deprecated
public final class TimeExtensions {
Expand Down
Expand Up @@ -857,9 +857,9 @@ private ITreeAppendable toSerializableAnonymousClass(XClosure closure, ITreeAppe
final LightweightTypeReference returnType = getClosureOperationReturnType(type, operation);
appendable.append("new ").append(type).append("() {"); //$NON-NLS-1$ //$NON-NLS-2$
appendable.increaseIndentation();
String selfVariable = null;
try {
appendable.openScope();
String selfVariable = null;
if (needSyntheticSelfVariable(closure, type)) {
appendable.newLine().append("final "); //$NON-NLS-1$
appendable.append(type).append(" "); //$NON-NLS-1$
Expand Down Expand Up @@ -916,6 +916,12 @@ private ITreeAppendable toSerializableAnonymousClass(XClosure closure, ITreeAppe
}
appendable.newLine().append("private ").append(Object.class).append(" writeReplace() throws "); //$NON-NLS-1$//$NON-NLS-2$
appendable.append(ObjectStreamException.class).append(" {").increaseIndentation().newLine(); //$NON-NLS-1$
if (selfVariable == null) {
reassignThisInClosure(appendable, type.getType());
} else {
// We have already assigned the closure type to _self, so don't assign it again
reassignThisInClosure(appendable, null);
}
appendable.append("return new ").append(SerializableProxy.class); //$NON-NLS-1$
appendable.append("(").append(appendable.getName(type)).append(".class"); //$NON-NLS-1$ //$NON-NLS-2$
for (final XAbstractFeatureCall call : localReferences) {
Expand Down
Expand Up @@ -313,7 +313,7 @@ public void compilingLocalVariable() throws Exception {
" return Objects.equal(_uUID, _uUID_1);",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, this.p.getUUID());",
" return new SerializableProxy($SerializableClosureProxy.class, Boot.this.p.getUUID());",
" }",
" };",
" this.f(_function);",
Expand Down Expand Up @@ -432,7 +432,7 @@ public void compilingField() throws Exception {
" return Objects.equal(_uUID, _uUID_1);",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, this.p.getUUID());",
" return new SerializableProxy($SerializableClosureProxy.class, Boot.this.p.getUUID());",
" }",
" };",
" this.f(_function);",
Expand Down Expand Up @@ -534,7 +534,7 @@ public void compilingSuperField() throws Exception {
" return Objects.equal(_uUID, _uUID_1);",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, this.callF().getUUID());",
" return new SerializableProxy($SerializableClosureProxy.class, Boot.this.callF().getUUID());",
" }",
" };",
" this.f(_function);",
Expand Down Expand Up @@ -642,7 +642,7 @@ public void compilingLocalFunction_01() throws Exception {
" return Objects.equal(_uUID, _callF);",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, this.callF());",
" return new SerializableProxy($SerializableClosureProxy.class, Boot.this.callF());",
" }",
" };",
" this.f(_function);",
Expand Down Expand Up @@ -751,7 +751,7 @@ public void compilingLocalFunction_02() throws Exception {
" return Objects.equal(_uUID, _uUID_1);",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, this.callF().getUUID());",
" return new SerializableProxy($SerializableClosureProxy.class, Boot.this.callF().getUUID());",
" }",
" };",
" this.f(_function);",
Expand Down Expand Up @@ -856,7 +856,7 @@ public void compilingSuperFunction_01() throws Exception {
" return Objects.equal(_uUID, _callF);",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, this.callF());",
" return new SerializableProxy($SerializableClosureProxy.class, Boot.this.callF());",
" }",
" };",
" this.f(_function);",
Expand Down Expand Up @@ -966,7 +966,7 @@ public void compilingSuperFunction_02() throws Exception {
" return Objects.equal(_uUID, _uUID_1);",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, this.p.callF().getUUID());",
" return new SerializableProxy($SerializableClosureProxy.class, Boot.this.p.callF().getUUID());",
" }",
" };",
" this.f(_function);",
Expand Down Expand Up @@ -1505,7 +1505,7 @@ public void compilingStaticExtensionImport() throws Exception {
" return Objects.equal(_uUID, _callF);",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, this.callF(new Object()));",
" return new SerializableProxy($SerializableClosureProxy.class, Boot.this.callF(new Object()));",
" }",
" };",
" this.f(_function);",
Expand Down Expand Up @@ -1711,7 +1711,7 @@ public void compilingLocalInstanceCreation02() throws Exception {
" return Objects.equal(_uUID, _callF);",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, this.callF(Integer.valueOf((1 + (2 * 3)))));",
" return new SerializableProxy($SerializableClosureProxy.class, Boot.this.callF(Integer.valueOf((1 + (2 * 3)))));",
" }",
" };",
" this.f(_function);",
Expand Down Expand Up @@ -1830,7 +1830,7 @@ public void compilingArithmetiParameter() throws Exception {
" return _xifexpression;",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, this.callF(Integer.valueOf((1 + (2 * 3)))));",
" return new SerializableProxy($SerializableClosureProxy.class, Boot.this.callF(Integer.valueOf((1 + (2 * 3)))));",
" }",
" };",
" this.f(_function);",
Expand Down Expand Up @@ -1952,7 +1952,7 @@ public void compilingIfThenOnIt() throws Exception {
" return _xifexpression;",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, s, this.callF(Integer.valueOf((1 + (2 * 3)))));",
" return new SerializableProxy($SerializableClosureProxy.class, s, Boot.this.callF(Integer.valueOf((1 + (2 * 3)))));",
" }",
" };",
" this.f(_function);",
Expand Down Expand Up @@ -2190,7 +2190,7 @@ public void compilingIsMe() throws Exception {
" return Objects.equal(_uUID, _callF);",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, this.callF(Integer.valueOf((1 + (2 * 3)))));",
" return new SerializableProxy($SerializableClosureProxy.class, Boot.this.callF(Integer.valueOf((1 + (2 * 3)))));",
" }",
" };",
" this.f(_function);",
Expand All @@ -2216,7 +2216,7 @@ public void compilingIsMe() throws Exception {
" return (!Objects.equal(_uUID, _callF));",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy_1.class, this.callF(Integer.valueOf((1 + (2 * 3)))));",
" return new SerializableProxy($SerializableClosureProxy_1.class, Boot.this.callF(Integer.valueOf((1 + (2 * 3)))));",
" }",
" };",
" this.f(_function_1);",
Expand Down Expand Up @@ -2853,7 +2853,7 @@ public void compilingLocalVariavleAsParameter() throws Exception {
" return (_callF == _callF_1);",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, this.callF((1 + 2)), this.callF(5));",
" return new SerializableProxy($SerializableClosureProxy.class, Boot.this.callF((1 + 2)), Boot.this.callF(5));",
" }",
" };",
" this.f(_function);",
Expand Down Expand Up @@ -2961,7 +2961,7 @@ public void compilingMultipleCallsToSameFunction() throws Exception {
" return (p == _callF);",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, p, this.callF(p));",
" return new SerializableProxy($SerializableClosureProxy.class, p, Boot.this.callF(p));",
" }",
" };",
" this.f(_function);",
Expand Down Expand Up @@ -3096,7 +3096,7 @@ public void compilingMultipleCallsToSameParameter() throws Exception {
" return r;",
" }",
" private Object writeReplace() throws ObjectStreamException {",
" return new SerializableProxy($SerializableClosureProxy.class, UUID.randomUUID(), this.field, s);",
" return new SerializableProxy($SerializableClosureProxy.class, UUID.randomUUID(), Boot.this.field, s);",
" }",
" };",
" this.f(_function);",
Expand Down

0 comments on commit 9f409b3

Please sign in to comment.