diff --git a/eclipse-sarl/plugins/io.sarl.lang.core/src/io/sarl/lang/core/Capacity.java b/eclipse-sarl/plugins/io.sarl.lang.core/src/io/sarl/lang/core/Capacity.java index b6690adce8..d6f5095c80 100644 --- a/eclipse-sarl/plugins/io.sarl.lang.core/src/io/sarl/lang/core/Capacity.java +++ b/eclipse-sarl/plugins/io.sarl.lang.core/src/io/sarl/lang/core/Capacity.java @@ -29,5 +29,58 @@ * @mavenartifactid $ArtifactId$ */ public interface Capacity { - // + + /** Wrapper to a capacity that enable to manage and provide the caller to the capacity function. + * + * @param the type of the wrapper capacity. + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.5 + */ + abstract class ContextAwareCapacityWrapper implements Capacity { + + private static final ThreadLocal CALLER = new ThreadLocal<>(); + + /** The wrapped capacity. + */ + protected final C capacity; + + private final Object caller; + + /** Constructor. + * + * @param capacity the wrapped capacity. + * @param caller the owner of the wrapper, that should be the caller of the capacity's function. + */ + public ContextAwareCapacityWrapper(C capacity, Object caller) { + assert capacity != null; + this.capacity = capacity; + this.caller = caller; + } + + /** Ensure that the local-thread variable stores the caller. + */ + protected final void ensureCallerInLocalThread() { + CALLER.set(this.caller); + } + + /** Reset the local-thread variable storing the caller. + */ + @SuppressWarnings("static-method") + protected final void resetCallerInLocalThread() { + CALLER.remove(); + } + + /** Replies the caller of the capacity functions. + * + * @return the caller, or {@code null} if no caller is registered. + */ + public static final Object getCaller() { + return CALLER.get(); + } + + } + } diff --git a/eclipse-sarl/plugins/io.sarl.lang/src/io/sarl/lang/actionprototype/InferredStandardParameter.java b/eclipse-sarl/plugins/io.sarl.lang/src/io/sarl/lang/actionprototype/InferredStandardParameter.java index 43ed7b31f9..b80e1021a3 100644 --- a/eclipse-sarl/plugins/io.sarl.lang/src/io/sarl/lang/actionprototype/InferredStandardParameter.java +++ b/eclipse-sarl/plugins/io.sarl.lang/src/io/sarl/lang/actionprototype/InferredStandardParameter.java @@ -50,6 +50,10 @@ public class InferredStandardParameter { */ protected String defaultValueAnnotationValue; + /** Basename of default value annotation value. + */ + protected String defaultValueAnnotationValueBasename; + /** * @param source - the original parameter. * @param name - the name of the formal parameter. @@ -98,12 +102,22 @@ public String getDefaultValueAnnotationValue() { return this.defaultValueAnnotationValue; } + /** Replies the basename of the value of the annotation that is marked this parameter with a default value. + * + * @return the basename of the annotation's value. + */ + public String getDefaultValueAnnotationValueBasename() { + return this.defaultValueAnnotationValueBasename; + } + /** Set the value of the annotation that is marked this parameter with a default value. * * @param value the annotation's value. + * @param basename the basename of the value. */ - void setDefaultValueAnnotationValue(String value) { + void setDefaultValueAnnotationValue(String value, String basename) { this.defaultValueAnnotationValue = value; + this.defaultValueAnnotationValueBasename = basename; } } diff --git a/eclipse-sarl/plugins/io.sarl.lang/src/io/sarl/lang/jvmmodel/SARLJvmModelInferrer.java b/eclipse-sarl/plugins/io.sarl.lang/src/io/sarl/lang/jvmmodel/SARLJvmModelInferrer.java index 3e69974027..294b5be090 100644 --- a/eclipse-sarl/plugins/io.sarl.lang/src/io/sarl/lang/jvmmodel/SARLJvmModelInferrer.java +++ b/eclipse-sarl/plugins/io.sarl.lang/src/io/sarl/lang/jvmmodel/SARLJvmModelInferrer.java @@ -110,6 +110,7 @@ import org.eclipse.xtext.xbase.lib.Pair; import org.eclipse.xtext.xbase.lib.Procedures; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure2; import org.eclipse.xtext.xbase.lib.Pure; import org.eclipse.xtext.xbase.typesystem.InferredTypeIndicator; import org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices; @@ -1022,6 +1023,88 @@ protected void initialize(SarlCapacity source, JvmGenericType inferredJvmType) { } finally { closeContext(context); } + + // Generate the internal class for context-aware wrappers + + // Change the modifiers on the generated type. + final JvmGenericType innerType = this.typesFactory.createJvmGenericType(); + innerType.setInterface(false); + innerType.setAbstract(false); + innerType.setVisibility(JvmVisibility.PUBLIC); + innerType.setStatic(true); + innerType.setStrictFloatingPoint(false); + innerType.setFinal(false); + final String innerTypeName = Capacity.ContextAwareCapacityWrapper.class.getSimpleName(); + innerType.setSimpleName(innerTypeName); + + inferredJvmType.getMembers().add(innerType); + + final JvmTypeParameter typeParameter = this.typesFactory.createJvmTypeParameter(); + typeParameter.setName("C"); //$NON-NLS-1$ + final JvmUpperBound constraint = this.typesFactory.createJvmUpperBound(); + constraint.setTypeReference(this._typeReferenceBuilder.typeRef(inferredJvmType)); + typeParameter.getConstraints().add(constraint); + innerType.getTypeParameters().add(typeParameter); + + final JvmTypeReference extendedType = inferredJvmType.getExtendedInterfaces().iterator().next(); + final JvmTypeReference superType = this._typeReferenceBuilder.typeRef( + extendedType.getQualifiedName() + "$" + innerTypeName, //$NON-NLS-1$ + this._typeReferenceBuilder.typeRef(typeParameter)); + innerType.getSuperTypes().add(superType); + + innerType.getSuperTypes().add(this._typeReferenceBuilder.typeRef(inferredJvmType)); + + final JvmConstructor constructor = this.typesFactory.createJvmConstructor(); + constructor.setVisibility(JvmVisibility.PUBLIC); + innerType.getMembers().add(constructor); + final JvmFormalParameter parameter1 = this.typesFactory.createJvmFormalParameter(); + parameter1.setName("capacity"); //$NON-NLS-1$ + parameter1.setParameterType(this._typeReferenceBuilder.typeRef(typeParameter)); + constructor.getParameters().add(parameter1); + final JvmFormalParameter parameter2 = this.typesFactory.createJvmFormalParameter(); + parameter2.setName("caller"); //$NON-NLS-1$ + parameter2.setParameterType(this._typeReferenceBuilder.typeRef(Object.class)); + constructor.getParameters().add(parameter2); + setBody(constructor, (it) -> { + it.append("super(capacity, caller);"); //$NON-NLS-1$ + }); + + final Set createdActions = new TreeSet<>(); + for (final JvmGenericType sourceType : Iterables.concat( + Collections.singletonList(inferredJvmType), + Iterables.transform(Iterables.skip(inferredJvmType.getExtendedInterfaces(), 1), (it) -> { + return (JvmGenericType) it.getType(); + }))) { + copyNonStaticPublicJvmOperations(sourceType, innerType, createdActions, (operation, it) -> { + it.append("try {"); //$NON-NLS-1$ + it.newLine(); + it.append(" ensureCallerInLocalThread();"); //$NON-NLS-1$ + it.newLine(); + it.append(" "); //$NON-NLS-1$ + if (operation.getReturnType() != null && !Objects.equal("void", operation.getReturnType().getIdentifier())) { //$NON-NLS-1$ + it.append("return "); //$NON-NLS-1$ + } + it.append("this.capacity."); //$NON-NLS-1$ + it.append(operation.getSimpleName()); + it.append("("); //$NON-NLS-1$ + boolean first = true; + for (final JvmFormalParameter fparam : operation.getParameters()) { + if (first) { + first = false; + } else { + it.append(", "); //$NON-NLS-1$ + } + it.append(fparam.getName()); + } + it.append(");"); //$NON-NLS-1$ + it.newLine(); + it.append("} finally {"); //$NON-NLS-1$ + it.newLine(); + it.append(" resetCallerInLocalThread();"); //$NON-NLS-1$ + it.newLine(); + it.append("}"); //$NON-NLS-1$ + }); + } } /** Initialize the SARL space type. @@ -2763,4 +2846,55 @@ private String reentrantSerialize(EObject object) { return code; } + /** Copy the JVM operations from the source to the destination. + * + * @param source the source. + * @param target the destination. + * @param createdActions the set of actions that are created before (input) or during (output) the invocation. + * @param bodyBuilder the builder of the target's operations. + * @since 0.5 + */ + protected void copyNonStaticPublicJvmOperations(JvmGenericType source, JvmGenericType target, + Set createdActions, Procedure2 bodyBuilder) { + final Iterable operations = Iterables.transform(Iterables.filter(source.getMembers(), (it) -> { + if (it instanceof JvmOperation) { + final JvmOperation op = (JvmOperation) it; + return !op.isStatic() && op.getVisibility() == JvmVisibility.PUBLIC; + } + return false; + }), (it) -> (JvmOperation) it); + for (final JvmOperation operation : operations) { + final ActionParameterTypes types = this.sarlSignatureProvider.createParameterTypesFromJvmModel( + operation.isVarArgs(), operation.getParameters()); + final ActionPrototype actSigKey = this.sarlSignatureProvider.createActionPrototype( + operation.getSimpleName(), types); + if (createdActions.add(actSigKey)) { + final JvmOperation newOp = this.typesFactory.createJvmOperation(); + target.getMembers().add(newOp); + newOp.setAbstract(false); + newOp.setDefault(operation.isDefault()); + newOp.setDeprecated(operation.isDeprecated()); + newOp.setFinal(false); + newOp.setNative(false); + newOp.setReturnType(this.typeBuilder.cloneWithProxies(operation.getReturnType())); + newOp.setSimpleName(operation.getSimpleName()); + newOp.setStatic(false); + newOp.setStrictFloatingPoint(operation.isStrictFloatingPoint()); + newOp.setSynchronized(operation.isSynchronized()); + newOp.setVisibility(JvmVisibility.PUBLIC); + + for (final JvmFormalParameter parameter : operation.getParameters()) { + final JvmFormalParameter newParam = this.typesFactory.createJvmFormalParameter(); + newOp.getParameters().add(newParam); + newParam.setName(parameter.getSimpleName()); + newParam.setParameterType(this.typeBuilder.cloneWithProxies(parameter.getParameterType())); + } + + newOp.setVarArgs(operation.isVarArgs()); + + setBody(newOp, (it) -> bodyBuilder.apply(operation, it)); + } + } + } + } diff --git a/tests/io.sarl.lang.core.tests/src/io/sarl/lang/core/tests/core/AbstractAgentTraitBehaviorTest.java b/tests/io.sarl.lang.core.tests/src/io/sarl/lang/core/tests/core/AbstractAgentTraitBehaviorTest.java index 9341709774..ec755f67ab 100644 --- a/tests/io.sarl.lang.core.tests/src/io/sarl/lang/core/tests/core/AbstractAgentTraitBehaviorTest.java +++ b/tests/io.sarl.lang.core.tests/src/io/sarl/lang/core/tests/core/AbstractAgentTraitBehaviorTest.java @@ -40,6 +40,7 @@ import io.sarl.lang.core.Skill; import io.sarl.lang.core.SpaceID; import io.sarl.lang.core.UnimplementedCapacityException; +import io.sarl.lang.core.tests.core.AbstractAgentTraitBehaviorTest.Capacity1; import io.sarl.tests.api.AbstractSarlTest; import io.sarl.tests.api.Nullable; @@ -111,7 +112,7 @@ public void getSkill_set() throws Exception { // Object result = invoke(getInstance(), "getSkill", Capacity1.class); // - assertSame(skill, result); + assertInstanceOf(Capacity1.class, result); } @Test @@ -139,7 +140,7 @@ public void setSkill() throws Exception { assertSame(skill, result); // result = invoke(getInstance(), "getSkill", Capacity1.class); - assertSame(skill, result); + assertInstanceOf(Capacity1.class, result); } @Test @@ -149,7 +150,7 @@ public void operator_mappedTo() throws Exception { invoke(getInstance(), "operator_mappedTo", Capacity1.class, skill); // Object result = invoke(getInstance(), "getSkill", Capacity1.class); - assertSame(skill, result); + assertInstanceOf(Capacity1.class, result); } @Test(expected = UnimplementedCapacityException.class) @@ -235,7 +236,11 @@ public S setSkill_Fake(S skill, Class... c * @mavenartifactid $ArtifactId$ */ protected static interface Capacity1 extends Capacity { - // + public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements Capacity1 { + public ContextAwareCapacityWrapper(C capacity, Object caller) { + super(capacity, caller); + } + } } /** diff --git a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/bugs/Bug294.java b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/bugs/Bug294.java index 6ca540069a..507ec6d1e0 100644 --- a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/bugs/Bug294.java +++ b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/bugs/Bug294.java @@ -151,6 +151,84 @@ public void testCompiler() throws Exception { " @DefaultValueUse(\"java.lang.String,float,java.lang.Object*\")", " @SyntheticMember", " public abstract void influenceSteering(final String linearInfluence, final Object... otherInfluences);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements PhysicEnvironment {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void influenceKinematic(final String linearInfluence, final float angularInfluence, final Object... otherInfluences) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.influenceKinematic(linearInfluence, angularInfluence, otherInfluences);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void influenceSteering(final String linearInfluence, final float angularInfluence, final Object... otherInfluences) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.influenceSteering(linearInfluence, angularInfluence, otherInfluences);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void influenceKinematic(final Object... otherInfluences) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.influenceKinematic(otherInfluences);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void influenceKinematic(final float angularInfluence, final Object... otherInfluences) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.influenceKinematic(angularInfluence, otherInfluences);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void influenceKinematic(final String linearInfluence, final Object... otherInfluences) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.influenceKinematic(linearInfluence, otherInfluences);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void influenceSteering(final Object... otherInfluences) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.influenceSteering(otherInfluences);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void influenceSteering(final float angularInfluence, final Object... otherInfluences) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.influenceSteering(angularInfluence, otherInfluences);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void influenceSteering(final String linearInfluence, final Object... otherInfluences) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.influenceSteering(linearInfluence, otherInfluences);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", ""); final String expectedStandardPhysicEnvironment = multilineString( diff --git a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/bugs/Bug312.java b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/bugs/Bug312.java index c3521c4246..d32b4bebc0 100644 --- a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/bugs/Bug312.java +++ b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/bugs/Bug312.java @@ -100,6 +100,48 @@ public void testCompiler() throws Exception { " @DefaultValueUse(\"Vector2i,boolean\")", " @SyntheticMember", " public abstract void move(final Vector2i direction2);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void move(final Vector2f direction1, final boolean changeHeading1) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.move(direction1, changeHeading1);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void move(final Vector2i direction2, final boolean changeHeading2) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.move(direction2, changeHeading2);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void move(final Vector2f direction1) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.move(direction1);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void move(final Vector2i direction2) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.move(direction2);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", ""); this.compiler.compile(this.snippet, (r) -> assertEquals(expected, r.getGeneratedCode("C1"))); diff --git a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/bugs/Bug92.java b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/bugs/Bug92.java index 454081e864..bc2552b450 100644 --- a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/bugs/Bug92.java +++ b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/bugs/Bug92.java @@ -271,6 +271,30 @@ public void originialCode_withDoubleType() throws Exception { " public abstract Double getEnergy(final Double currentTime, final Double deltaTime, final Double wantedEnergy);", " ", " public abstract void setVoltage(final Double currentVoltage);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements ComputeEnergyCapacity {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public Double getEnergy(final Double currentTime, final Double deltaTime, final Double wantedEnergy) {", + " try {", + " ensureCallerInLocalThread();", + " return this.capacity.getEnergy(currentTime, deltaTime, wantedEnergy);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void setVoltage(final Double currentVoltage) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.setVoltage(currentVoltage);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", ""); final String expected2 = multilineString( @@ -379,6 +403,30 @@ public void originialCode_withoutDoubleType() throws Exception { " public abstract Double getEnergy(final Double currentTime, final Double deltaTime, final Double wantedEnergy);", " ", " public abstract void setVoltage(final Double currentVoltage);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements ComputeEnergyCapacity {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public Double getEnergy(final Double currentTime, final Double deltaTime, final Double wantedEnergy) {", + " try {", + " ensureCallerInLocalThread();", + " return this.capacity.getEnergy(currentTime, deltaTime, wantedEnergy);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void setVoltage(final Double currentVoltage) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.setVoltage(currentVoltage);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", ""); final String expected2 = multilineString( diff --git a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/aop/AgentCompilerTest.java b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/aop/AgentCompilerTest.java index 4fd6589db5..7b5146ba90 100644 --- a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/aop/AgentCompilerTest.java +++ b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/aop/AgentCompilerTest.java @@ -1407,6 +1407,21 @@ public void inlinedCapacityFunctionCall_nativeParameter() throws Exception { "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", " public abstract void myfunction(final double v);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void myfunction(final double v) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myfunction(v);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -1479,6 +1494,21 @@ public void inlinedCapacityFunctionCall_classParameter_baseName() throws Excepti "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", " public abstract void myfunction(final Class v);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void myfunction(final Class v) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myfunction(v);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -1551,6 +1581,21 @@ public void inlinedCapacityFunctionCall_classParameter_typeof() throws Exception "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", " public abstract void myfunction(final Class v);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void myfunction(final Class v) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myfunction(v);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -1628,6 +1673,21 @@ public void inlinedCapacityFunctionCall_variadicParameter01() throws Exception { "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", " public abstract void myfunction(final Class v1, final int... v2);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void myfunction(final Class v1, final int... v2) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myfunction(v1, v2);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -1711,6 +1771,21 @@ public void inlinedCapacityFunctionCall_variadicParameter02() throws Exception { "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", " public abstract void myfunction(final int... v2);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void myfunction(final int... v2) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myfunction(v2);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); diff --git a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/aop/CapacityCompilerTest.java b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/aop/CapacityCompilerTest.java index 9e677c195f..e2a439c52a 100644 --- a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/aop/CapacityCompilerTest.java +++ b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/aop/CapacityCompilerTest.java @@ -45,6 +45,11 @@ public void basicCapacityCompile() throws Exception { "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " }", "}", "" ); @@ -64,6 +69,11 @@ public void capacitymodifier_none() throws Exception { "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " }", "}", "" )); @@ -82,6 +92,11 @@ public void capacitymodifier_public() throws Exception { "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " }", "}", "" )); @@ -100,6 +115,11 @@ public void capacitymodifier_private() throws Exception { "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SuppressWarnings(\"all\")", "interface C1 extends Capacity {", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " }", "}", "" )); @@ -124,10 +144,26 @@ public void actionmodifier_override() throws Exception { "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", " public abstract void name();", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void name() {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.name();", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); final String expectedC2 = multilineString( + "import C1;", "import io.sarl.lang.annotation.SarlSpecification;", "", "@FunctionalInterface", @@ -136,6 +172,21 @@ public void actionmodifier_override() throws Exception { "public interface C2 extends C1 {", " @Override", " public abstract void name();", + " ", + " public static class ContextAwareCapacityWrapper extends C1.ContextAwareCapacityWrapper implements C2 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void name() {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.name();", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -162,6 +213,21 @@ public void actionmodifier_none() throws Exception { "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", " public abstract void name();", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void name() {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.name();", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" )); diff --git a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/aop/SkillCompilerTest.java b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/aop/SkillCompilerTest.java index 9a998fe49f..061d90309e 100644 --- a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/aop/SkillCompilerTest.java +++ b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/aop/SkillCompilerTest.java @@ -462,6 +462,11 @@ public void completeFinalFieldInitialization() throws Exception { "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " }", "}", "" ); @@ -1169,6 +1174,21 @@ public void missedActionImplementation_0() throws Exception { "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", " public abstract void myaction1(final int a);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void myaction1(final int a) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction1(a);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -1181,6 +1201,21 @@ public void missedActionImplementation_0() throws Exception { "@SuppressWarnings(\"all\")", "public interface C2 extends Capacity {", " public abstract void myaction2(final float b, final boolean c);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C2 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void myaction2(final float b, final boolean c) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction2(b, c);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -1256,6 +1291,11 @@ public void compatibleReturnType_0() throws Exception { "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " }", "}", "" ); @@ -1266,6 +1306,11 @@ public void compatibleReturnType_0() throws Exception { "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SuppressWarnings(\"all\")", "public interface C2 extends Capacity {", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C2 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " }", "}", "" ); @@ -1370,6 +1415,11 @@ public void compatibleReturnType_1() throws Exception { "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " }", "}", "" ); @@ -1380,6 +1430,11 @@ public void compatibleReturnType_1() throws Exception { "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SuppressWarnings(\"all\")", "public interface C2 extends Capacity {", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C2 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " }", "}", "" ); @@ -1484,6 +1539,11 @@ public void compatibleReturnType_2() throws Exception { "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " }", "}", "" ); @@ -1549,6 +1609,21 @@ public void compatibleReturnType_3() throws Exception { "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", " public abstract float myaction(final int a);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public float myaction(final int a) {", + " try {", + " ensureCallerInLocalThread();", + " return this.capacity.myaction(a);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -1880,6 +1955,30 @@ public void capacityAccessors_inSkill() throws Exception { " public abstract float myaction(final int a);", " ", " public abstract void myaction2(final boolean a);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public float myaction(final int a) {", + " try {", + " ensureCallerInLocalThread();", + " return this.capacity.myaction(a);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void myaction2(final boolean a) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction2(a);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -1893,6 +1992,30 @@ public void capacityAccessors_inSkill() throws Exception { " public abstract float myaction3(final int a);", " ", " public abstract void myaction4(final boolean a);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C2 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public float myaction3(final int a) {", + " try {", + " ensureCallerInLocalThread();", + " return this.capacity.myaction3(a);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void myaction4(final boolean a) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction4(a);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -1994,16 +2117,47 @@ public void inheritance() throws Exception { "@SuppressWarnings(\"all\")", "public interface CapTest1 extends Capacity {", " public abstract int func1();", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements CapTest1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public int func1() {", + " try {", + " ensureCallerInLocalThread();", + " return this.capacity.func1();", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); final String expectedC2 = multilineString( + "import CapTest1;", "import io.sarl.lang.annotation.SarlSpecification;", "", "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SuppressWarnings(\"all\")", "public interface CapTest2 extends CapTest1 {", " public abstract void func2(final int a);", + " ", + " public static class ContextAwareCapacityWrapper extends CapTest1.ContextAwareCapacityWrapper implements CapTest2 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void func2(final int a) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.func2(a);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); diff --git a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/general/ArgDefaultValueCompilerTest.java b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/general/ArgDefaultValueCompilerTest.java index 60556d98fc..4faa194603 100644 --- a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/general/ArgDefaultValueCompilerTest.java +++ b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/general/ArgDefaultValueCompilerTest.java @@ -2224,6 +2224,48 @@ public void capacity() throws Exception { " @DefaultValueUse(\"int,int,int,int\")", " @SyntheticMember", " public abstract void myaction(final int arg0, final int arg1, final int arg2);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void myaction(final int arg0, final int arg1, final int arg2, final int arg3) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction(arg0, arg1, arg2, arg3);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void myaction(final int arg2) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction(arg2);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void myaction(final int arg0, final int arg2) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction(arg0, arg2);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void myaction(final int arg0, final int arg1, final int arg2) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction(arg0, arg1, arg2);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -2275,6 +2317,39 @@ public void overridingCapacitySkill() throws Exception { " @DefaultValueUse(\"int,int,int*\")", " @SyntheticMember", " public abstract void myaction(final int arg0, final int... arg2);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void myaction(final int arg0, final int arg1, final int... arg2) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction(arg0, arg1, arg2);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void myaction(final int... arg2) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction(arg2);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void myaction(final int arg0, final int... arg2) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction(arg0, arg2);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -2370,6 +2445,30 @@ public void missedActionImplementation() throws Exception { " @DefaultValueUse(\"int\")", " @SyntheticMember", " public abstract void myaction1();", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void myaction1(final int a) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction1(a);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void myaction1() {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction1();", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -2398,6 +2497,30 @@ public void missedActionImplementation() throws Exception { " @DefaultValueUse(\"float,boolean\")", " @SyntheticMember", " public abstract void myaction2(final boolean c);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C2 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void myaction2(final float b, final boolean c) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction2(b, c);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " ", + " public void myaction2(final boolean c) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction2(c);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); diff --git a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/general/VarArgsCompilerTest.java b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/general/VarArgsCompilerTest.java index b6ef2c86b9..4d34346bd6 100644 --- a/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/general/VarArgsCompilerTest.java +++ b/tests/io.sarl.lang.tests/src/io/sarl/lang/tests/general/compilation/general/VarArgsCompilerTest.java @@ -287,6 +287,21 @@ public void action_singleParam() throws Exception { "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", " public abstract void myaction(final int... arg);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void myaction(final int... arg) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction(arg);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -309,6 +324,21 @@ public void action() throws Exception { "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", " public abstract void myaction(final char arg1, final boolean arg2, final int... arg3);", + " ", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " ", + " public void myaction(final char arg1, final boolean arg2, final int... arg3) {", + " try {", + " ensureCallerInLocalThread();", + " this.capacity.myaction(arg1, arg2, arg3);", + " } finally {", + " resetCallerInLocalThread();", + " }", + " }", + " }", "}", "" ); @@ -404,6 +434,11 @@ public void action_singleParam() throws Exception { "@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")", "@SuppressWarnings(\"all\")", "public interface C1 extends Capacity {", + " public static class ContextAwareCapacityWrapper extends Capacity.ContextAwareCapacityWrapper implements C1 {", + " public ContextAwareCapacityWrapper(final C capacity, final Object caller) {", + " super(capacity, caller);", + " }", + " }", "}", "" );