From 82edde914855b8f2306f46e9363da8fb5aa1b580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Galland?= Date: Tue, 1 Oct 2019 13:47:58 +0800 Subject: [PATCH] [lang] Refactor the DefaultActionPrototype type in order to limit memory leaks. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Several tests indicated that DefaultActionPrototype takes 250Mb of heap space over the 350Mb allocated by the SARL IDE. This issue is caused by a buffer that is not clear in an appropriate way. A context, which contains the buffer is added in order to control the life-time of this buffer. Signed-off-by: Stéphane Galland --- .../ExtraLanguageGeneratorContext.java | 14 + .../IExtraLanguageGeneratorContext.java | 11 + .../sarl/lang/jvmmodel/GenerationContext.java | 19 + .../lang/jvmmodel/SARLJvmModelInferrer.java | 5 +- .../DefaultActionPrototypeProvider.java | 365 ++++++++--- .../IActionPrototypeContext.java | 40 ++ .../IActionPrototypeProvider.java | 194 ++++-- .../lang/typesystem/SARLOperationHelper.java | 4 + .../DefaultActionPrototypeProviderTest.java | 602 +++++++++--------- 9 files changed, 817 insertions(+), 437 deletions(-) create mode 100644 main/coreplugins/io.sarl.lang/src/io/sarl/lang/sarl/actionprototype/IActionPrototypeContext.java diff --git a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/extralanguage/compiler/ExtraLanguageGeneratorContext.java b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/extralanguage/compiler/ExtraLanguageGeneratorContext.java index 24f3964909..9439e917db 100644 --- a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/extralanguage/compiler/ExtraLanguageGeneratorContext.java +++ b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/extralanguage/compiler/ExtraLanguageGeneratorContext.java @@ -39,6 +39,9 @@ import org.eclipse.xtext.util.Strings; import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference; +import io.sarl.lang.sarl.actionprototype.IActionPrototypeContext; +import io.sarl.lang.sarl.actionprototype.IActionPrototypeProvider; + /** The generator from SARL to the Python language. * * @author $Author: sgalland$ @@ -67,6 +70,8 @@ public class ExtraLanguageGeneratorContext implements IExtraLanguageGeneratorCon private LightweightTypeReference expectedExpressionType; + private IActionPrototypeContext actionPrototypeContext; + /** Create the context for the given delegate. * * @param delegate the delegate. @@ -171,6 +176,7 @@ public void setData(String id, Object value) { @Override public void clearData() { this.temporaryData = null; + this.actionPrototypeContext = null; } @Override @@ -264,4 +270,12 @@ public LightweightTypeReference setExpectedExpressionType(LightweightTypeReferen return old; } + @Override + public IActionPrototypeContext getActionPrototypeContext(IActionPrototypeProvider provider) { + if (this.actionPrototypeContext == null) { + this.actionPrototypeContext = provider.createContext(); + } + return this.actionPrototypeContext; + } + } diff --git a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/extralanguage/compiler/IExtraLanguageGeneratorContext.java b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/extralanguage/compiler/IExtraLanguageGeneratorContext.java index baa67198da..245019e144 100644 --- a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/extralanguage/compiler/IExtraLanguageGeneratorContext.java +++ b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/extralanguage/compiler/IExtraLanguageGeneratorContext.java @@ -32,6 +32,9 @@ import org.eclipse.xtext.generator.IGeneratorContext; import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference; +import io.sarl.lang.sarl.actionprototype.IActionPrototypeContext; +import io.sarl.lang.sarl.actionprototype.IActionPrototypeProvider; + /** The generator from SARL to the Python language. * * @author $Author: sgalland$ @@ -105,6 +108,14 @@ public interface IExtraLanguageGeneratorContext extends IGeneratorContext { */ IFileSystemAccess2 getFileSystemAccess(); + /** Replies the context for the action prototype provider. + * + * @param provider the provider for creating the context if it was not created. + * @return the context. + * @since 0.10 + */ + IActionPrototypeContext getActionPrototypeContext(IActionPrototypeProvider provider); + /** Replies the stored data with the given identifier. * If the data was not found, the default value is replied. * diff --git a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/jvmmodel/GenerationContext.java b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/jvmmodel/GenerationContext.java index 6c88aa5f2f..1980de07a4 100644 --- a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/jvmmodel/GenerationContext.java +++ b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/jvmmodel/GenerationContext.java @@ -47,6 +47,8 @@ import io.sarl.lang.sarl.SarlBehaviorUnit; import io.sarl.lang.sarl.actionprototype.ActionParameterTypes; import io.sarl.lang.sarl.actionprototype.ActionPrototype; +import io.sarl.lang.sarl.actionprototype.IActionPrototypeContext; +import io.sarl.lang.sarl.actionprototype.IActionPrototypeProvider; /** Describe generation context. * @@ -135,6 +137,8 @@ abstract class GenerationContext { */ private GenerationContext parent; + private IActionPrototypeContext actionPrototypeContext; + /** Construct a information about the generation. * * @param owner the object for which the context is created. @@ -415,10 +419,25 @@ public boolean isAtLeastJava8() { return getGeneratorConfig().getJavaSourceVersion().isAtLeast(JavaVersion.JAVA8); } + /** Get the context for the action prototype provider. + * + * @param provider the provider for creating the context if it was not created. + * @return the context + */ + public IActionPrototypeContext getActionPrototypeContext(IActionPrototypeProvider provider) { + if (this.actionPrototypeContext == null) { + this.actionPrototypeContext = provider.createContext(); + } + return this.actionPrototypeContext; + } /** Release any allocated resource. */ public void release() { + if (this.actionPrototypeContext != null) { + this.actionPrototypeContext.release(); + this.actionPrototypeContext = null; + } this.target = null; this.contextObject = null; this.generatorConfig = null; diff --git a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/jvmmodel/SARLJvmModelInferrer.java b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/jvmmodel/SARLJvmModelInferrer.java index bf6bf4518d..3ba24ee89a 100644 --- a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/jvmmodel/SARLJvmModelInferrer.java +++ b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/jvmmodel/SARLJvmModelInferrer.java @@ -522,7 +522,6 @@ protected final synchronized GenerationContext openContext(EObject sarlObject, J final Iterable> supportedMemberTypes) { assert type != null; assert supportedMemberTypes != null; - this.sarlSignatureProvider.clear(type); final GenerationContext context = new GenerationContext(sarlObject, type) { @Override public boolean isSupportedMember(XtendMember member) { @@ -1466,6 +1465,7 @@ protected void transform(final XtendConstructor source, final JvmGenericType con // Generate all the constructor signatures related to the constructor to create. final InferredPrototype constructorSignatures = this.sarlSignatureProvider.createPrototypeFromSarlModel( + context.getActionPrototypeContext(this.sarlSignatureProvider), actionKey, Utils.isVarArg(source.getParameters()), source.getParameters()); @@ -1631,6 +1631,7 @@ protected void transform(final XtendFunction source, final JvmGenericType contai // Compute the different action prototypes associated to the action to create. final boolean isVarArgs = Utils.isVarArg(source.getParameters()); final InferredPrototype actionSignatures = this.sarlSignatureProvider.createPrototypeFromSarlModel( + context.getActionPrototypeContext(this.sarlSignatureProvider), actionKey, isVarArgs, source.getParameters()); @@ -2282,10 +2283,12 @@ protected void appendSyntheticDefaultValuedParameterMethods( // Retreive the inferred prototype (including the prototypes with optional arguments) InferredPrototype redefinedPrototype = this.sarlSignatureProvider.getPrototypes( + context.getActionPrototypeContext(this.sarlSignatureProvider), qualifiedActionName, parameterTypes); if (redefinedPrototype == null) { // The original operation was not parsed by the SARL compiler in the current run-time context. redefinedPrototype = this.sarlSignatureProvider.createPrototypeFromJvmModel( + context.getActionPrototypeContext(this.sarlSignatureProvider), qualifiedActionName, redefinedOperation.isVarArgs(), redefinedOperation.getParameters()); } diff --git a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/sarl/actionprototype/DefaultActionPrototypeProvider.java b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/sarl/actionprototype/DefaultActionPrototypeProvider.java index feb1339055..1b2662e743 100644 --- a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/sarl/actionprototype/DefaultActionPrototypeProvider.java +++ b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/sarl/actionprototype/DefaultActionPrototypeProvider.java @@ -26,13 +26,15 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.TreeMap; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +import javax.inject.Inject; -import com.google.common.base.Objects; import com.google.common.base.Strings; import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import com.google.inject.Singleton; import org.eclipse.xtend.core.xtend.XtendParameter; import org.eclipse.xtext.EcoreUtil2; import org.eclipse.xtext.common.types.JvmDeclaredType; @@ -56,50 +58,107 @@ * Provides additional function signatures according the semantic * associated to the parameter's default values. * + *

This implementation is thread-safe. + * * @author $Author: sgalland$ * @version $FullVersion$ * @mavengroupid $GroupId$ * @mavenartifactid $ArtifactId$ */ -@Singleton public class DefaultActionPrototypeProvider implements IActionPrototypeProvider { + @Inject + private SARLAnnotationUtil annotationUtils; + @Inject private TypeReferences references; @Inject private SARLGrammarKeywordAccess grammarAccess; - private final Map>> prototypes = new TreeMap<>(); - - private final Map> defaultValueIDPrefixes = new TreeMap<>(); - @Inject private AnnotationLookup annotationFinder; - @Inject - private SARLAnnotationUtil annotationUtils; - /** Construct a provider of action prototypes. */ public DefaultActionPrototypeProvider() { // } - private static Pair>, Boolean> buildParameter( + @Override + public Iterable getPrototypes(IActionPrototypeContext context, QualifiedActionName id) { + final Context ctx = (Context) context; + final InnerMap> c; + ctx.getPrototypes().getLock().readLock().lock(); + try { + c = ctx.getPrototypes().get(id.getContainerID()); + } finally { + ctx.getPrototypes().getLock().readLock().unlock(); + } + if (c != null) { + final InnerMap list; + c.getLock().readLock().lock(); + try { + list = c.get(id.getActionName()); + } finally { + c.getLock().readLock().unlock(); + } + if (list != null) { + list.getLock().readLock().lock(); + try { + return Collections.unmodifiableCollection(list.values()); + } finally { + list.getLock().readLock().unlock(); + } + } + } + return Collections.emptyList(); + } + + @Override + public InferredPrototype getPrototypes(IActionPrototypeContext context, QualifiedActionName actionID, ActionParameterTypes signatureID) { + final Context ctx = (Context) context; + final InnerMap> c; + ctx.getPrototypes().getLock().readLock().lock(); + try { + c = ctx.getPrototypes().get(actionID.getContainerID()); + } finally { + ctx.getPrototypes().getLock().readLock().unlock(); + } + if (c != null) { + final InnerMap list; + c.getLock().readLock().lock(); + try { + list = c.get(actionID.getActionName()); + } finally { + c.getLock().readLock().unlock(); + } + if (list != null) { + list.getLock().readLock().lock(); + try { + return list.get(signatureID); + } finally { + list.getLock().readLock().unlock(); + } + } + } + return null; + } + + private static Pair>, Boolean> buildParameter( int parameterIndex, final int lastParameterIndex, String argumentValue, FormalParameterProvider params, - Map> signatures, + InnerMap> signatures, ActionParameterTypes fillSignatureKeyOutputParameter) { final boolean isOptional = params.hasFormalParameterDefaultValue(parameterIndex) && ((parameterIndex < lastParameterIndex) - || (!fillSignatureKeyOutputParameter.isVarArg())); + || (!fillSignatureKeyOutputParameter.isVarArg())); final boolean isVarArg = parameterIndex >= lastParameterIndex && fillSignatureKeyOutputParameter.isVarArg(); final String name = params.getFormalParameterName(parameterIndex); final JvmTypeReference type = params.getFormalParameterTypeReference(parameterIndex, isVarArg); - final Map> tmpSignatures = new TreeMap<>(); + final InnerMap> tmpSignatures = new InnerMap<>(); if (type == null) { return new Pair<>(tmpSignatures, isOptional); } @@ -148,21 +207,42 @@ private static Pair>, return new Pair<>(tmpSignatures, isOptional); } - private Map> buildSignaturesForArgDefaultValues( + private InnerMap> buildSignaturesForArgDefaultValues( + Context context, JvmIdentifiableElement container, String actionId, FormalParameterProvider params, ActionParameterTypes fillSignatureKeyOutputParameter) { - Map> signatures = new TreeMap<>(); + InnerMap> signatures = new InnerMap<>(); fillSignatureKeyOutputParameter.clear(); if (params.getFormalParameterCount() > 0) { final int lastParamIndex = params.getFormalParameterCount() - 1; final String containerFullyQualifiedName = createQualifiedActionName(container, null).getContainerID(); - Map indexes = this.defaultValueIDPrefixes.get(containerFullyQualifiedName); + InnerMap indexes; + context.getDefaultValueIDPrefixes().getLock().readLock().lock(); + try { + indexes = context.getDefaultValueIDPrefixes().get(containerFullyQualifiedName); + } finally { + context.getDefaultValueIDPrefixes().getLock().readLock().unlock(); + } if (indexes == null) { - indexes = new TreeMap<>(); - this.defaultValueIDPrefixes.put(containerFullyQualifiedName, indexes); + context.getDefaultValueIDPrefixes().getLock().writeLock().lock(); + try { + indexes = context.getDefaultValueIDPrefixes().get(containerFullyQualifiedName); + if (indexes == null) { + indexes = new InnerMap<>(); + context.getDefaultValueIDPrefixes().put(containerFullyQualifiedName, indexes); + } + } finally { + context.getDefaultValueIDPrefixes().getLock().writeLock().unlock(); + } + } + final Integer lastIndex; + indexes.getLock().readLock().lock(); + try { + lastIndex = indexes.get(actionId); + } finally { + indexes.getLock().readLock().unlock(); } - final Integer lastIndex = indexes.get(actionId); int defaultValueIndex; if (lastIndex == null) { defaultValueIndex = 0; @@ -174,7 +254,7 @@ private Map> buildSignatur final String prefix = container.getQualifiedName() + "#" //$NON-NLS-1$ + actionId.toUpperCase() + "_"; //$NON-NLS-1$ for (int i = 0; i <= lastParamIndex; ++i) { - final Pair>, Boolean> pair = buildParameter( + final Pair>, Boolean> pair = buildParameter( i, lastParamIndex, prefix + defaultValueIndex, @@ -188,7 +268,12 @@ private Map> buildSignatur } } - indexes.put(actionId, defaultValueIndex); + indexes.getLock().writeLock().lock(); + try { + indexes.put(actionId, defaultValueIndex); + } finally { + indexes.getLock().writeLock().unlock(); + } final List parameters = signatures.get(fillSignatureKeyOutputParameter); if (parameters != null) { @@ -203,44 +288,22 @@ private Map> buildSignatur return signatures; } - @Override - public Iterable getPrototypes(QualifiedActionName id) { - final Map> c = this.prototypes.get(id.getContainerID()); - if (c != null) { - final Map list = c.get(id.getActionName()); - if (list != null) { - return list.values(); - } - } - return Collections.emptyList(); - } - - @Override - public InferredPrototype getPrototypes(QualifiedActionName actionID, ActionParameterTypes signatureID) { - final Map> c = this.prototypes.get(actionID.getContainerID()); - if (c != null) { - final Map list = c.get(actionID.getActionName()); - if (list != null) { - return list.get(signatureID); - } - } - return null; - } - /** Build and replies the inferred action signature for the element with * the given ID. This function creates the different signatures according * to the definition, or not, of default values for the formal parameters. * + * @param context the context in which the prototype should be created. * @param id identifier of the function. - * @param isVarargs indicates if the signature has a variatic parameter. + * @param isVarargs indicates if the signature has a variadic parameter. * @param parameters list of the formal parameters of the function. * @return the signature or null if none. */ - protected InferredPrototype createPrototype(QualifiedActionName id, + protected InferredPrototype createPrototype(Context context, QualifiedActionName id, boolean isVarargs, FormalParameterProvider parameters) { assert parameters != null; final ActionParameterTypes key = new ActionParameterTypes(isVarargs, parameters.getFormalParameterCount()); final Map> ip = buildSignaturesForArgDefaultValues( + context, id.getDeclaringType(), key.toActionPrototype(id.getActionName()).toActionId(), parameters, key); @@ -252,49 +315,71 @@ protected InferredPrototype createPrototype(QualifiedActionName id, op, ip); final String containerID = id.getContainerID(); - Map> c = this.prototypes.get(containerID); + InnerMap> c; + context.getPrototypes().getLock().readLock().lock(); + try { + c = context.getPrototypes().get(containerID); + } finally { + context.getPrototypes().getLock().readLock().unlock(); + } if (c == null) { - c = new TreeMap<>(); - this.prototypes.put(containerID, c); + context.getPrototypes().getLock().writeLock().lock(); + try { + c = context.getPrototypes().get(containerID); + if (c == null) { + c = new InnerMap<>(); + context.getPrototypes().put(containerID, c); + } + } finally { + context.getPrototypes().getLock().writeLock().unlock(); + } + } + + InnerMap list; + c.getLock().readLock().lock(); + try { + list = c.get(id.getActionName()); + } finally { + c.getLock().readLock().unlock(); } - Map list = c.get(id.getActionName()); if (list == null) { - list = new TreeMap<>(); - c.put(id.getActionName(), list); + c.getLock().writeLock().lock(); + try { + list = c.get(id.getActionName()); + if (list == null) { + list = new InnerMap<>(); + c.put(id.getActionName(), list); + } + } finally { + c.getLock().writeLock().unlock(); + } + } + list.getLock().writeLock().lock(); + try { + list.put(key, proto); + } finally { + list.getLock().writeLock().unlock(); } - list.put(key, proto); return proto; } @Override - public final InferredPrototype createPrototypeFromSarlModel(QualifiedActionName id, + public final InferredPrototype createPrototypeFromSarlModel(IActionPrototypeContext context, QualifiedActionName id, boolean isVarargs, List parameters) { - return createPrototype(id, isVarargs, + return createPrototype((Context) context, id, isVarargs, new SarlFormalParameterProvider(parameters, this.references)); } @Override - public final InferredPrototype createPrototypeFromJvmModel(QualifiedActionName id, + public final InferredPrototype createPrototypeFromJvmModel(IActionPrototypeContext context, QualifiedActionName id, boolean isVarargs, List parameters) { - return createPrototype(id, isVarargs, + return createPrototype((Context) context, id, isVarargs, new JvmFormalParameterProvider(parameters, this.annotationFinder, this)); } @Override - public QualifiedActionName createQualifiedActionName(JvmIdentifiableElement container, - String functionName) { - return new QualifiedActionName( - container.eResource().getURI().toString(), - container, - functionName); - } - - @Override - public QualifiedActionName createConstructorQualifiedName(JvmIdentifiableElement container) { - return new QualifiedActionName( - container.eResource().getURI().toString(), - container, - this.grammarAccess.getNewKeyword()); + public IActionPrototypeContext createContext() { + return new Context(); } @Override @@ -322,20 +407,20 @@ public ActionParameterTypes createParameterTypesFromSarlModel(boolean isVarargs, } @Override - public ActionParameterTypes createParameterTypesFromString(String parameters) { - return new ActionParameterTypes(parameters); + public QualifiedActionName createQualifiedActionName(JvmIdentifiableElement container, + String functionName) { + return new QualifiedActionName( + container.eResource().getURI().toString(), + container, + functionName); } @Override - public ActionParameterTypes createParameterTypesFromJvmModel(boolean isVarargs, List parameters) { - final ActionParameterTypes sig = new ActionParameterTypes(isVarargs, parameters.size()); - for (final JvmFormalParameter p : parameters) { - final JvmTypeReference paramType = p.getParameterType(); - if (paramType != null) { - sig.add(paramType.getIdentifier()); - } - } - return sig; + public QualifiedActionName createConstructorQualifiedName(JvmIdentifiableElement container) { + return new QualifiedActionName( + container.eResource().getURI().toString(), + container, + this.grammarAccess.getNewKeyword()); } @Override @@ -360,27 +445,30 @@ public ActionParameterTypes createParameterTypes(boolean isVarargs, } @Override - public ActionParameterTypes createParameterTypesForVoid() { - return new ActionParameterTypes(false, 0); + public ActionParameterTypes createParameterTypesFromString(String parameters) { + return new ActionParameterTypes(parameters); } @Override - public ActionPrototype createActionPrototype(String actionName, ActionParameterTypes parameters) { - return new ActionPrototype(actionName, parameters, false); + public ActionParameterTypes createParameterTypesFromJvmModel(boolean isVarargs, List parameters) { + final ActionParameterTypes sig = new ActionParameterTypes(isVarargs, parameters.size()); + for (final JvmFormalParameter p : parameters) { + final JvmTypeReference paramType = p.getParameterType(); + if (paramType != null) { + sig.add(paramType.getIdentifier()); + } + } + return sig; } @Override - public void clear(JvmIdentifiableElement container) { - final QualifiedActionName qn = createQualifiedActionName(container, null); - final String fqn = qn.getContainerID(); - this.prototypes.remove(fqn); - this.defaultValueIDPrefixes.remove(fqn); + public ActionParameterTypes createParameterTypesForVoid() { + return new ActionParameterTypes(false, 0); } @Override - public void clear() { - this.prototypes.clear(); - this.defaultValueIDPrefixes.clear(); + public ActionPrototype createActionPrototype(String actionName, ActionParameterTypes parameters) { + return new ActionPrototype(actionName, parameters, false); } @Override @@ -407,7 +495,7 @@ public String toJavaArgument(String callerQualifiedName, String id) { final int index = id.indexOf('#'); if (index > 0) { final String qn = id.substring(0, index); - if (!Objects.equal(qn, callerQualifiedName)) { + if (!Objects.equals(qn, callerQualifiedName)) { b.append(qn); b.append("."); //$NON-NLS-1$ } @@ -441,7 +529,7 @@ public String extractDefaultValueString(JvmFormalParameter parameter) { } final JvmField field = Iterables.find(target.getDeclaredFields(), - it -> Objects.equal(it.getSimpleName(), fieldName), + it -> Objects.equals(it.getSimpleName(), fieldName), null); if (field != null) { final String value = this.annotationUtils.findStringValue(field, SarlSourceCode.class); @@ -454,4 +542,83 @@ public String extractDefaultValueString(JvmFormalParameter parameter) { return null; } + /** + * Context for a {@code DefaultActionPrototypeProvider}. + * + * @param the type of the keys. + * @param the type of the values. + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.10 + */ + private static class InnerMap extends TreeMap { + // It is important to have a SortedMap as the super type in + // order to preserve the order of the prototypes into the + // map. This order is assumed to be present in all the unit tests. + + private static final long serialVersionUID = -7858620757455956027L; + + private final ReadWriteLock lock = new ReentrantReadWriteLock(); + + InnerMap() { + // + } + + /** Replies the lock. + * + * @return never {@code null}. + */ + public ReadWriteLock getLock() { + return this.lock; + } + + } + + /** + * Context for a {@code DefaultActionPrototypeProvider}. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.10 + */ + private static class Context implements IActionPrototypeContext { + + private final InnerMap>> prototypes = new InnerMap<>(); + + private final InnerMap> defaultValueIDPrefixes = new InnerMap<>(); + + Context() { + // + } + + @Override + public void release() { + this.prototypes.getLock().writeLock().lock(); + try { + this.prototypes.clear(); + } finally { + this.prototypes.getLock().writeLock().unlock(); + } + this.defaultValueIDPrefixes.getLock().writeLock().lock(); + try { + this.defaultValueIDPrefixes.clear(); + } finally { + this.defaultValueIDPrefixes.getLock().writeLock().unlock(); + } + } + + public InnerMap> getDefaultValueIDPrefixes() { + return this.defaultValueIDPrefixes; + } + + public InnerMap>> getPrototypes() { + return this.prototypes; + } + + } + } diff --git a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/sarl/actionprototype/IActionPrototypeContext.java b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/sarl/actionprototype/IActionPrototypeContext.java new file mode 100644 index 0000000000..aef9180c2d --- /dev/null +++ b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/sarl/actionprototype/IActionPrototypeContext.java @@ -0,0 +1,40 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2019 the original authors or authors. + * + * 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 io.sarl.lang.sarl.actionprototype; + +/** + * Context used by a {@code IActionPrototypeProvider}. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + * @since 0.10 + * @see IActionPrototypeProvider + */ +public interface IActionPrototypeContext { + + /** Release any resource. + */ + void release(); + +} diff --git a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/sarl/actionprototype/IActionPrototypeProvider.java b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/sarl/actionprototype/IActionPrototypeProvider.java index c60af6a1b7..f2c73f43c7 100644 --- a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/sarl/actionprototype/IActionPrototypeProvider.java +++ b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/sarl/actionprototype/IActionPrototypeProvider.java @@ -63,7 +63,7 @@ public interface IActionPrototypeProvider { /** Build an identifier with the given parameters. * - * @param isVarargs indicates if the signature has a variatic parameter. + * @param isVarargs indicates if the signature has a variadic parameter. * @param parameters the list of the formal parameter to put in the signature key. * @return the list of the parameters' types. */ @@ -71,7 +71,7 @@ public interface IActionPrototypeProvider { /** Build an identifier with the given parameters. * - * @param isVarargs indicates if the signature has a variatic parameter. + * @param isVarargs indicates if the signature has a variadic parameter. * @param parameters the list of the formal parameter to put in the signature key. * @return the list of the parameters' types. */ @@ -79,7 +79,7 @@ public interface IActionPrototypeProvider { /** Build an identifier with the given parameters. * - * @param isVarargs indicates if the signature has a variatic parameter. + * @param isVarargs indicates if the signature has a variadic parameter. * @param provider the provider of the formal parameters. * @return the list of the parameters' types. */ @@ -103,85 +103,189 @@ public interface IActionPrototypeProvider { */ ActionPrototype createActionPrototype(String actionName, ActionParameterTypes parameters); + /** Replies the name of the field that should store the default value associated to the parameter with the given id. + * + * @param id the parameter's identifier. + * @return the field's name. + */ + String createFieldNameForDefaultValueID(String id); + + /** Qualify the default value identifier with the given container's qualified name if the ID is not qualified. + * + * @param containerQualifiedName the qualified name. + * @param id the parameter's identifier. + * @return the qualified name. + */ + String qualifyDefaultValueID(String containerQualifiedName, String id); + + /** Replies the calling agument associated to the parameter with the given id. + * + * @param callerQualifiedName qualified name of the type where the argument is used. + * @param argumentSpecification the parameter's identifier. + * @return the calling argument for the formal parameter. + */ + String toJavaArgument(String callerQualifiedName, String argumentSpecification); + + /** Replies the default value of the given formal parameter. + * + *

This function replies the string representation of the default value. + * + * @param parameter the parameter for which the default value should be extracted. + * @return the default value, or null if none. + */ + String extractDefaultValueString(JvmFormalParameter parameter); + /** Reset all the prototypes associated to the given container. * * @param container the element for which the prototype store must be reset. + * @deprecated since 0.10, see {@link #createContext()} */ - void clear(JvmIdentifiableElement container); + @Deprecated + default void clear(JvmIdentifiableElement container) { + // Do nothing + } /** Reset all the prototypes. - */ - void clear(); - - /** Build and replies the inferred action signature for the element with - * the given ID. This function creates the different signatures according - * to the definition, or not, of default values for the formal parameters. * - * @param id identifier of the function. - * @param isVarargs indicates if the signature has a variatic parameter. - * @param parameters list of the formal parameters of the function. - * @return the signature or null if none. + * @deprecated since 0.10, see {@link #createContext()} */ - InferredPrototype createPrototypeFromSarlModel(QualifiedActionName id, boolean isVarargs, - List parameters); + @Deprecated + default void clear() { + // Do nothing. + } - /** Build and replies the inferred action signature for the element with - * the given ID. This function creates the different signatures according - * to the definition, or not, of default values for the formal parameters. + /** Replies the inferred action signatures for the element with + * the given ID. * - * @param id identifier of the function. - * @param isVarargs indicates if the signature has a variatic parameter. - * @param parameters list of the formal parameters of the function. - * @return the signature or null if none. + * @param context the context in which the prototype should be created. + * @param id the ID of the action. + * @return the signature, never null. + * @since 0.10 + * @see #createContext() */ - InferredPrototype createPrototypeFromJvmModel(QualifiedActionName id, boolean isVarargs, List parameters); + Iterable getPrototypes(IActionPrototypeContext context, QualifiedActionName id); /** Replies the inferred action signatures for the element with * the given ID. * * @param id the ID of the action. * @return the signature, never null. + * @deprecated since 0.10, see {@link #getPrototypes(IActionPrototypeContext, QualifiedActionName)} */ - Iterable getPrototypes(QualifiedActionName id); + @Deprecated + default Iterable getPrototypes(QualifiedActionName id) { + final IActionPrototypeContext ctx = createContext(); + try { + return getPrototypes(ctx, id); + } finally { + ctx.release(); + } + } /** Replies the inferred action signature for the given IDs. * + * @param context the context in which the prototype should be created. * @param actionID the ID of the action. * @param signatureID ID of the signature. * @return the signature or null if none. + * @since 0.10 + * @see #createContext() */ - InferredPrototype getPrototypes(QualifiedActionName actionID, ActionParameterTypes signatureID); + InferredPrototype getPrototypes(IActionPrototypeContext context, QualifiedActionName actionID, ActionParameterTypes signatureID); - /** Replies the name of the field that should store the default value associated to the parameter with the given id. + /** Replies the inferred action signature for the given IDs. * - * @param id the parameter's identifier. - * @return the field's name. + * @param actionID the ID of the action. + * @param signatureID ID of the signature. + * @return the signature or null if none. + * @deprecated since 0.10, see {@link #getPrototypes(IActionPrototypeContext, QualifiedActionName, ActionParameterTypes)} */ - String createFieldNameForDefaultValueID(String id); + @Deprecated + default InferredPrototype getPrototypes(QualifiedActionName actionID, ActionParameterTypes signatureID) { + final IActionPrototypeContext ctx = createContext(); + try { + return getPrototypes(ctx, actionID, signatureID); + } finally { + ctx.release(); + } + } - /** Qualify the default value identifier with the given container's qualified name if the ID is not qualified. + /** Build and replies the inferred action signature for the element with + * the given ID. This function creates the different signatures according + * to the definition, or not, of default values for the formal parameters. * - * @param containerQualifiedName the qualified name. - * @param id the parameter's identifier. - * @return the qualified name. + * @param context the context in which the prototype should be created. + * @param id identifier of the function. + * @param isVarargs indicates if the signature has a variadic parameter. + * @param parameters list of the formal parameters of the function. + * @return the signature or null if none. + * @since 0.10 + * @see #createContext() */ - String qualifyDefaultValueID(String containerQualifiedName, String id); + InferredPrototype createPrototypeFromSarlModel(IActionPrototypeContext context, QualifiedActionName id, boolean isVarargs, + List parameters); - /** Replies the calling agument associated to the parameter with the given id. + /** Build and replies the inferred action signature for the element with + * the given ID. This function creates the different signatures according + * to the definition, or not, of default values for the formal parameters. * - * @param callerQualifiedName qualified name of the type where the argument is used. - * @param argumentSpecification the parameter's identifier. - * @return the calling argument for the formal parameter. + * @param id identifier of the function. + * @param isVarargs indicates if the signature has a variadic parameter. + * @param parameters list of the formal parameters of the function. + * @return the signature or null if none. + * @deprecated since 0.10, see {@link #createPrototypeFromSarlModel(IActionPrototypeContext, QualifiedActionName, boolean, List)} */ - String toJavaArgument(String callerQualifiedName, String argumentSpecification); + @Deprecated + default InferredPrototype createPrototypeFromSarlModel(QualifiedActionName id, boolean isVarargs, + List parameters) { + final IActionPrototypeContext ctx = createContext(); + try { + return createPrototypeFromSarlModel(ctx, id, isVarargs, parameters); + } finally { + ctx.release(); + } + } - /** Replies the default value of the given formal parameter. + /** Build and replies the inferred action signature for the element with + * the given ID. This function creates the different signatures according + * to the definition, or not, of default values for the formal parameters. * - *

This function replies the string representation of the default value. + * @param context the context in which the prototype should be created. + * @param id identifier of the function. + * @param isVarargs indicates if the signature has a variadic parameter. + * @param parameters list of the formal parameters of the function. + * @return the signature or null if none. + * @since 0.10 + * @see #createContext() + */ + InferredPrototype createPrototypeFromJvmModel(IActionPrototypeContext context, QualifiedActionName id, + boolean isVarargs, List parameters); + + /** Build and replies the inferred action signature for the element with + * the given ID. This function creates the different signatures according + * to the definition, or not, of default values for the formal parameters. * - * @param parameter the parameter for which the default value should be extracted. - * @return the default value, or null if none. + * @param id identifier of the function. + * @param isVarargs indicates if the signature has a variadic parameter. + * @param parameters list of the formal parameters of the function. + * @return the signature or null if none. + * @deprecated since 0.10, see {@link #createPrototypeFromJvmModel(IActionPrototypeContext, QualifiedActionName, boolean, List)} */ - String extractDefaultValueString(JvmFormalParameter parameter); + @Deprecated + default InferredPrototype createPrototypeFromJvmModel(QualifiedActionName id, boolean isVarargs, List parameters) { + final IActionPrototypeContext ctx = createContext(); + try { + return createPrototypeFromJvmModel(ctx, id, isVarargs, parameters); + } finally { + ctx.release(); + } + } + + /** Create an empty context. + * + * @return the context. + * @since 0.10 + */ + IActionPrototypeContext createContext(); } diff --git a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/typesystem/SARLOperationHelper.java b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/typesystem/SARLOperationHelper.java index 25f3bebddf..8534c25dc6 100644 --- a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/typesystem/SARLOperationHelper.java +++ b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/typesystem/SARLOperationHelper.java @@ -223,6 +223,8 @@ private InferredPrototype getInferredPrototype(XtendFunction operation) { // Compute the different action prototypes associated to the action to create. final boolean isVarArgs = Utils.isVarArg(operation.getParameters()); return this.actionPrototypes.createPrototypeFromSarlModel( + // TODO more general context? + this.actionPrototypes.createContext(), actionKey, isVarArgs, operation.getParameters()); } @@ -235,6 +237,8 @@ private InferredPrototype getInferredPrototype(JvmOperation operation) { operation.getDeclaringType(), operation.getSimpleName()); // Compute the different action prototypes associated to the action to create. return this.actionPrototypes.createPrototypeFromJvmModel( + // TODO more general context? + this.actionPrototypes.createContext(), actionKey, operation.isVarArgs(), operation.getParameters()); } diff --git a/tests/io.sarl.lang.tests/src/test/java/io/sarl/lang/tests/modules/actionprototype/DefaultActionPrototypeProviderTest.java b/tests/io.sarl.lang.tests/src/test/java/io/sarl/lang/tests/modules/actionprototype/DefaultActionPrototypeProviderTest.java index 7f4d1e7927..c02e8d4627 100644 --- a/tests/io.sarl.lang.tests/src/test/java/io/sarl/lang/tests/modules/actionprototype/DefaultActionPrototypeProviderTest.java +++ b/tests/io.sarl.lang.tests/src/test/java/io/sarl/lang/tests/modules/actionprototype/DefaultActionPrototypeProviderTest.java @@ -20,12 +20,6 @@ */ package io.sarl.lang.tests.modules.actionprototype; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import static org.mockito.Mockito.when; import java.util.ArrayList; @@ -68,11 +62,13 @@ import io.sarl.lang.sarl.actionprototype.ActionPrototype; import io.sarl.lang.sarl.actionprototype.DefaultActionPrototypeProvider; import io.sarl.lang.sarl.actionprototype.FormalParameterProvider; +import io.sarl.lang.sarl.actionprototype.IActionPrototypeContext; import io.sarl.lang.sarl.actionprototype.InferredPrototype; import io.sarl.lang.sarl.actionprototype.InferredStandardParameter; import io.sarl.lang.sarl.actionprototype.InferredValuedParameter; import io.sarl.lang.sarl.actionprototype.QualifiedActionName; import io.sarl.tests.api.AbstractSarlTest; +import io.sarl.tests.api.Nullable; /** * @author $Author: sgalland$ @@ -85,7 +81,7 @@ DefaultActionPrototypeProviderTest.NoDefaultValues.class, DefaultActionPrototypeProviderTest.DefaultValues.class, }) -@SuppressWarnings("all") +@SuppressWarnings({"javadoc", "nls", "incomplete-switch"}) public class DefaultActionPrototypeProviderTest extends AbstractSarlTest { static int index; @@ -218,7 +214,7 @@ static void assertPrototypes( Object... expected) { if (!matchPrototype(elements, expected)) { fail("Expected elements: " + toString(expected) - + "; but is: " + elements.toString()); + + "; but is: " + elements.toString()); } } @@ -233,15 +229,21 @@ public static class NoDefaultValues extends AbstractSarlTest { @Inject private DefaultActionPrototypeProvider provider; + @Nullable + private IActionPrototypeContext context; + + @Nullable private FormalParameterProvider parameterProvider; + @Nullable private EList sarlParameters; + @Nullable private EList jvmParameters; @Before public void setUp() throws Exception { - this.provider.clear(); + this.context = this.provider.createContext(); this.parameterProvider = mock(FormalParameterProvider.class); when(this.parameterProvider.getFormalParameterCount()).thenReturn(3); when(this.parameterProvider.getFormalParameterName(ArgumentMatchers.anyInt())).thenAnswer(new Answer() { @@ -260,19 +262,19 @@ public String answer(InvocationOnMock invocation) throws Throwable { }); when(this.parameterProvider.getFormalParameterType(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenAnswer(new Answer() { - @Override - public String answer(InvocationOnMock invocation) throws Throwable { - switch(((Integer) invocation.getArguments()[0]).intValue()) { - case 0: - return "java.lang.String"; - case 1: - return "float"; - case 2: - return "java.lang.Object[]"; - } - return null; - } - }); + @Override + public String answer(InvocationOnMock invocation) throws Throwable { + switch(((Integer) invocation.getArguments()[0]).intValue()) { + case 0: + return "java.lang.String"; + case 1: + return "float"; + case 2: + return "java.lang.Object[]"; + } + return null; + } + }); // SarlFormalParameter p; this.sarlParameters = new BasicEList<>(); @@ -625,7 +627,7 @@ public void createPrototypeFromSarlModel_void() { QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); EList params = new BasicEList<>(); // - InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(qn, false, params); + InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(this.context, qn, false, params); assertNotNull(prototype); assertEquals("myfct", prototype.getActionName().getActionName()); assertSameFormalParameters(params, prototype.getFormalParameters()); @@ -641,7 +643,7 @@ public void createPrototypeFromSarlModel_noVarArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); // - InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(qn, false, this.sarlParameters); + InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(this.context, qn, false, this.sarlParameters); assertNotNull(prototype); assertEquals("myfct", prototype.getActionName().getActionName()); assertSameFormalParameters(this.sarlParameters, prototype.getFormalParameters()); @@ -659,7 +661,7 @@ public void createPrototypeFromSarlModel_varArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); // - InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(qn, true, this.sarlParameters); + InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(this.context, qn, true, this.sarlParameters); assertNotNull(prototype); assertEquals("myfct", prototype.getActionName().getActionName()); assertSameFormalParameters(this.sarlParameters, prototype.getFormalParameters()); @@ -676,7 +678,7 @@ public void createPrototypeFromJvmModel_void() { QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); EList params = new BasicEList<>(); // - InferredPrototype prototype = this.provider.createPrototypeFromJvmModel(qn, false, params); + InferredPrototype prototype = this.provider.createPrototypeFromJvmModel(this.context, qn, false, params); assertNotNull(prototype); assertEquals("myfct", prototype.getActionName().getActionName()); assertSameJvmFormalParameters(params, prototype.getFormalParameters()); @@ -692,7 +694,7 @@ public void createPrototypeFromJvmModel_noVarArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); // - InferredPrototype prototype = this.provider.createPrototypeFromJvmModel(qn, false, this.jvmParameters); + InferredPrototype prototype = this.provider.createPrototypeFromJvmModel(this.context, qn, false, this.jvmParameters); assertNotNull(prototype); assertEquals("myfct", prototype.getActionName().getActionName()); assertSameJvmFormalParameters(this.jvmParameters, prototype.getFormalParameters()); @@ -710,7 +712,7 @@ public void createPrototypeFromJvmModel_varArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); // - InferredPrototype prototype = this.provider.createPrototypeFromJvmModel(qn, true, this.jvmParameters); + InferredPrototype prototype = this.provider.createPrototypeFromJvmModel(this.context, qn, true, this.jvmParameters); assertNotNull(prototype); assertEquals("myfct", prototype.getActionName().getActionName()); assertSameJvmFormalParameters(this.jvmParameters, prototype.getFormalParameters()); @@ -726,7 +728,7 @@ public void getPrototypesQualifiedActionName_noCreatedPrototype() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); // - Iterable iterable = this.provider.getPrototypes(qn); + Iterable iterable = this.provider.getPrototypes(this.context, qn); assertNotNull(iterable); assertFalse(iterable.iterator().hasNext()); } @@ -735,9 +737,9 @@ public void getPrototypesQualifiedActionName_noCreatedPrototype() { public void getPrototypesQualifiedActionName_createdPrototype_noVarArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); - InferredPrototype expected = this.provider.createPrototypeFromSarlModel(qn, false, this.sarlParameters); + InferredPrototype expected = this.provider.createPrototypeFromSarlModel(this.context, qn, false, this.sarlParameters); // - Iterable iterable = this.provider.getPrototypes(qn); + Iterable iterable = this.provider.getPrototypes(this.context, qn); assertNotNull(iterable); Iterator iterator = iterable.iterator(); assertTrue(iterator.hasNext()); @@ -750,9 +752,9 @@ public void getPrototypesQualifiedActionName_createdPrototype_noVarArg() { public void getPrototypesQualifiedActionName_createdPrototype_varArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); - InferredPrototype expected = this.provider.createPrototypeFromSarlModel(qn, true, this.sarlParameters); + InferredPrototype expected = this.provider.createPrototypeFromSarlModel(this.context, qn, true, this.sarlParameters); // - Iterable iterable = this.provider.getPrototypes(qn); + Iterable iterable = this.provider.getPrototypes(this.context, qn); assertNotNull(iterable); Iterator iterator = iterable.iterator(); assertTrue(iterator.hasNext()); @@ -767,7 +769,7 @@ public void getPrototypesQualifiedActionNameActionParameterTypes_noCreatedProtot QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); ActionParameterTypes types = this.provider.createParameterTypesFromSarlModel(false, this.sarlParameters); // - InferredPrototype prototype = this.provider.getPrototypes(qn, types); + InferredPrototype prototype = this.provider.getPrototypes(this.context, qn, types); assertNull(prototype); } @@ -776,9 +778,9 @@ public void getPrototypesQualifiedActionNameActionParameterTypes_createdPrototyp JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); ActionParameterTypes types = this.provider.createParameterTypesFromSarlModel(false, this.sarlParameters); - InferredPrototype expected = this.provider.createPrototypeFromSarlModel(qn, false, this.sarlParameters); + InferredPrototype expected = this.provider.createPrototypeFromSarlModel(this.context, qn, false, this.sarlParameters); // - InferredPrototype prototype = this.provider.getPrototypes(qn, types); + InferredPrototype prototype = this.provider.getPrototypes(this.context, qn, types); assertNotNull(prototype); assertSame(expected, prototype); } @@ -788,9 +790,9 @@ public void getPrototypesQualifiedActionNameActionParameterTypes_createdPrototyp JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); ActionParameterTypes types = this.provider.createParameterTypesFromSarlModel(true, this.sarlParameters); - InferredPrototype expected = this.provider.createPrototypeFromSarlModel(qn, true, this.sarlParameters); + InferredPrototype expected = this.provider.createPrototypeFromSarlModel(this.context, qn, true, this.sarlParameters); // - InferredPrototype prototype = this.provider.getPrototypes(qn, types); + InferredPrototype prototype = this.provider.getPrototypes(this.context, qn, types); assertNotNull(prototype); assertSame(expected, prototype); } @@ -800,10 +802,11 @@ public void resetPrototypes_noCreatedProtype() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); ActionParameterTypes types = this.provider.createParameterTypesFromSarlModel(false, this.sarlParameters); + assertNotNull(types); // - assertFalse(this.provider.getPrototypes(qn).iterator().hasNext()); - this.provider.clear(container); - assertFalse(this.provider.getPrototypes(qn).iterator().hasNext()); + assertFalse(this.provider.getPrototypes(this.context, qn).iterator().hasNext()); + this.context.release(); + assertFalse(this.provider.getPrototypes(this.context, qn).iterator().hasNext()); } @Test @@ -811,11 +814,13 @@ public void resetPrototypes_createdProtype_noVarArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); ActionParameterTypes types = this.provider.createParameterTypesFromSarlModel(false, this.sarlParameters); - InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(qn, false, this.sarlParameters); + assertNotNull(types); + InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(this.context, qn, false, this.sarlParameters); + assertNotNull(prototype); // - assertTrue(this.provider.getPrototypes(qn).iterator().hasNext()); - this.provider.clear(container); - assertFalse(this.provider.getPrototypes(qn).iterator().hasNext()); + assertTrue(this.provider.getPrototypes(this.context, qn).iterator().hasNext()); + this.context.release(); + assertFalse(this.provider.getPrototypes(this.context, qn).iterator().hasNext()); } @Test @@ -823,11 +828,13 @@ public void resetPrototypes_createdProtype_varArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); ActionParameterTypes types = this.provider.createParameterTypesFromSarlModel(true, this.sarlParameters); - InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(qn, true, this.sarlParameters); + assertNotNull(types); + InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(this.context, qn, true, this.sarlParameters); + assertNotNull(prototype); // - assertTrue(this.provider.getPrototypes(qn).iterator().hasNext()); - this.provider.clear(container); - assertFalse(this.provider.getPrototypes(qn).iterator().hasNext()); + assertTrue(this.provider.getPrototypes(this.context, qn).iterator().hasNext()); + this.context.release(); + assertFalse(this.provider.getPrototypes(this.context, qn).iterator().hasNext()); } } @@ -843,52 +850,58 @@ public static class DefaultValues extends AbstractSarlTest { @Inject private DefaultActionPrototypeProvider provider; + @Nullable + private IActionPrototypeContext context; + + @Nullable private FormalParameterProvider parameterProvider; + @Nullable private EList sarlParameters; + @Nullable private EList jvmParameters; @Before public void setUp() throws Exception { - this.provider.clear(); + this.context = this.provider.createContext(); this.parameterProvider = mock(FormalParameterProvider.class); when(this.parameterProvider.getFormalParameterCount()).thenReturn(4); when(this.parameterProvider.getFormalParameterName(ArgumentMatchers.anyInt())).thenAnswer((invocation) -> { - switch(((Integer) invocation.getArguments()[0]).intValue()) { - case 0: - return "firstarg"; - case 1: - return "secondarg"; - case 2: - return "thirdarg"; - case 3: - return "fourtharg"; - } - return null; - }); + switch(((Integer) invocation.getArguments()[0]).intValue()) { + case 0: + return "firstarg"; + case 1: + return "secondarg"; + case 2: + return "thirdarg"; + case 3: + return "fourtharg"; + } + return null; + }); when(this.parameterProvider.getFormalParameterType(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenAnswer((invocation) -> { - switch(((Integer) invocation.getArguments()[0]).intValue()) { - case 0: - return "java.lang.String"; - case 1: - return "int"; - case 2: - return "float"; - case 3: - return "java.lang.Object[]"; - } - return null; - }); + switch(((Integer) invocation.getArguments()[0]).intValue()) { + case 0: + return "java.lang.String"; + case 1: + return "int"; + case 2: + return "float"; + case 3: + return "java.lang.Object[]"; + } + return null; + }); when(this.parameterProvider.hasFormalParameterDefaultValue(ArgumentMatchers.anyInt())).thenAnswer((invocation) -> { - switch(((Integer) invocation.getArguments()[0]).intValue()) { - case 0: - case 2: - return Boolean.TRUE; - } - return Boolean.FALSE; - }); + switch(((Integer) invocation.getArguments()[0]).intValue()) { + case 0: + case 2: + return Boolean.TRUE; + } + return Boolean.FALSE; + }); // SarlFormalParameter p; this.sarlParameters = new BasicEList<>(); @@ -1290,7 +1303,7 @@ public void createPrototypeFromSarlModel_void() { QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); EList params = new BasicEList<>(); // - InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(qn, false, params); + InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(this.context, qn, false, params); assertNotNull(prototype); assertEquals("myfct", prototype.getActionName().getActionName()); assertSameFormalParameters(params, prototype.getFormalParameters()); @@ -1306,7 +1319,7 @@ public void createPrototypeFromSarlModel_noVarArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); // - InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(qn, false, this.sarlParameters); + InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(this.context, qn, false, this.sarlParameters); assertNotNull(prototype); assertEquals("myfct", prototype.getActionName().getActionName()); assertSameFormalParameters(this.sarlParameters, prototype.getFormalParameters()); @@ -1320,65 +1333,65 @@ public void createPrototypeFromSarlModel_noVarArg() { "int,float,java.lang.Object", "int,java.lang.Object"); assertPrototypes(prototype.getOriginalParameterTypes(), - InferredStandardParameter.class, - "java.lang.String", - "firstarg", - InferredStandardParameter.class, - "int", - "secondarg", - InferredStandardParameter.class, - "float", - "thirdarg", - InferredStandardParameter.class, - "java.lang.Object", - "fourtharg"); + InferredStandardParameter.class, + "java.lang.String", + "firstarg", + InferredStandardParameter.class, + "int", + "secondarg", + InferredStandardParameter.class, + "float", + "thirdarg", + InferredStandardParameter.class, + "java.lang.Object", + "fourtharg"); assertPrototypes(prototype.getInferredParameterTypes(), new Object[] { - InferredStandardParameter.class, - "java.lang.String", - "firstarg", - InferredStandardParameter.class, - "int", - "secondarg", - InferredValuedParameter.class, - "float", - "thirdarg", - "io.sarl.tests.Stub" + index + "#MYFCT_1", - InferredStandardParameter.class, - "java.lang.Object", - "fourtharg", - }, + InferredStandardParameter.class, + "java.lang.String", + "firstarg", + InferredStandardParameter.class, + "int", + "secondarg", + InferredValuedParameter.class, + "float", + "thirdarg", + "io.sarl.tests.Stub" + index + "#MYFCT_1", + InferredStandardParameter.class, + "java.lang.Object", + "fourtharg", + }, new Object[] { - InferredValuedParameter.class, - "java.lang.String", - "firstarg", - "io.sarl.tests.Stub" + index + "#MYFCT_0", - InferredStandardParameter.class, - "int", - "secondarg", - InferredStandardParameter.class, - "float", - "thirdarg", - InferredStandardParameter.class, - "java.lang.Object", - "fourtharg", - }, + InferredValuedParameter.class, + "java.lang.String", + "firstarg", + "io.sarl.tests.Stub" + index + "#MYFCT_0", + InferredStandardParameter.class, + "int", + "secondarg", + InferredStandardParameter.class, + "float", + "thirdarg", + InferredStandardParameter.class, + "java.lang.Object", + "fourtharg", + }, new Object[] { - InferredValuedParameter.class, - "java.lang.String", - "firstarg", - "io.sarl.tests.Stub" + index + "#MYFCT_0", - InferredStandardParameter.class, - "int", - "secondarg", - InferredValuedParameter.class, - "float", - "thirdarg", - "io.sarl.tests.Stub" + index + "#MYFCT_1", - InferredStandardParameter.class, - "java.lang.Object", - "fourtharg", - }); + InferredValuedParameter.class, + "java.lang.String", + "firstarg", + "io.sarl.tests.Stub" + index + "#MYFCT_0", + InferredStandardParameter.class, + "int", + "secondarg", + InferredValuedParameter.class, + "float", + "thirdarg", + "io.sarl.tests.Stub" + index + "#MYFCT_1", + InferredStandardParameter.class, + "java.lang.Object", + "fourtharg", + }); } @Test @@ -1386,7 +1399,7 @@ public void createPrototypeFromSarlModel_varArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); // - InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(qn, true, this.sarlParameters); + InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(this.context, qn, true, this.sarlParameters); assertNotNull(prototype); assertEquals("myfct", prototype.getActionName().getActionName()); assertSameFormalParameters(this.sarlParameters, prototype.getFormalParameters()); @@ -1412,51 +1425,51 @@ public void createPrototypeFromSarlModel_varArg() { "fourtharg"); assertPrototypes(prototype.getInferredParameterTypes(), new Object[] { - InferredStandardParameter.class, - "java.lang.String", - "firstarg", - InferredStandardParameter.class, - "int", - "secondarg", - InferredValuedParameter.class, - "float", - "thirdarg", - "io.sarl.tests.Stub" + index + "#MYFCT_1", - InferredStandardParameter.class, - "java.lang.Object[]", - "fourtharg", - }, + InferredStandardParameter.class, + "java.lang.String", + "firstarg", + InferredStandardParameter.class, + "int", + "secondarg", + InferredValuedParameter.class, + "float", + "thirdarg", + "io.sarl.tests.Stub" + index + "#MYFCT_1", + InferredStandardParameter.class, + "java.lang.Object[]", + "fourtharg", + }, new Object[] { - InferredValuedParameter.class, - "java.lang.String", - "firstarg", - "io.sarl.tests.Stub" + index + "#MYFCT_0", - InferredStandardParameter.class, - "int", - "secondarg", - InferredStandardParameter.class, - "float", - "thirdarg", - InferredStandardParameter.class, - "java.lang.Object[]", - "fourtharg", - }, + InferredValuedParameter.class, + "java.lang.String", + "firstarg", + "io.sarl.tests.Stub" + index + "#MYFCT_0", + InferredStandardParameter.class, + "int", + "secondarg", + InferredStandardParameter.class, + "float", + "thirdarg", + InferredStandardParameter.class, + "java.lang.Object[]", + "fourtharg", + }, new Object[] { - InferredValuedParameter.class, - "java.lang.String", - "firstarg", - "io.sarl.tests.Stub" + index + "#MYFCT_0", - InferredStandardParameter.class, - "int", - "secondarg", - InferredValuedParameter.class, - "float", - "thirdarg", - "io.sarl.tests.Stub" + index + "#MYFCT_1", - InferredStandardParameter.class, - "java.lang.Object[]", - "fourtharg", - }); + InferredValuedParameter.class, + "java.lang.String", + "firstarg", + "io.sarl.tests.Stub" + index + "#MYFCT_0", + InferredStandardParameter.class, + "int", + "secondarg", + InferredValuedParameter.class, + "float", + "thirdarg", + "io.sarl.tests.Stub" + index + "#MYFCT_1", + InferredStandardParameter.class, + "java.lang.Object[]", + "fourtharg", + }); } @Test @@ -1465,7 +1478,7 @@ public void createPrototypeFromJvmModel_void() { QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); EList params = new BasicEList<>(); // - InferredPrototype prototype = this.provider.createPrototypeFromJvmModel(qn, false, params); + InferredPrototype prototype = this.provider.createPrototypeFromJvmModel(this.context, qn, false, params); assertNotNull(prototype); assertEquals("myfct", prototype.getActionName().getActionName()); assertSameJvmFormalParameters(params, prototype.getFormalParameters()); @@ -1481,7 +1494,7 @@ public void createPrototypeFromJvmModel_noVarArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); // - InferredPrototype prototype = this.provider.createPrototypeFromJvmModel(qn, false, this.jvmParameters); + InferredPrototype prototype = this.provider.createPrototypeFromJvmModel(this.context, qn, false, this.jvmParameters); assertNotNull(prototype); assertEquals("myfct", prototype.getActionName().getActionName()); assertSameJvmFormalParameters(this.jvmParameters, prototype.getFormalParameters()); @@ -1509,51 +1522,51 @@ public void createPrototypeFromJvmModel_noVarArg() { "fourtharg"); assertPrototypes(prototype.getInferredParameterTypes(), new Object[] { - InferredStandardParameter.class, - "java.lang.String", - "firstarg", - InferredStandardParameter.class, - "int", - "secondarg", - InferredValuedParameter.class, - "float", - "thirdarg", - "io.sarl.tests.Stub" + index + "#MYFCT_1", - InferredStandardParameter.class, - "java.lang.Object[]", - "fourtharg", - }, + InferredStandardParameter.class, + "java.lang.String", + "firstarg", + InferredStandardParameter.class, + "int", + "secondarg", + InferredValuedParameter.class, + "float", + "thirdarg", + "io.sarl.tests.Stub" + index + "#MYFCT_1", + InferredStandardParameter.class, + "java.lang.Object[]", + "fourtharg", + }, new Object[] { - InferredValuedParameter.class, - "java.lang.String", - "firstarg", - "io.sarl.tests.Stub" + index + "#MYFCT_0", - InferredStandardParameter.class, - "int", - "secondarg", - InferredStandardParameter.class, - "float", - "thirdarg", - InferredStandardParameter.class, - "java.lang.Object[]", - "fourtharg", - }, + InferredValuedParameter.class, + "java.lang.String", + "firstarg", + "io.sarl.tests.Stub" + index + "#MYFCT_0", + InferredStandardParameter.class, + "int", + "secondarg", + InferredStandardParameter.class, + "float", + "thirdarg", + InferredStandardParameter.class, + "java.lang.Object[]", + "fourtharg", + }, new Object[] { - InferredValuedParameter.class, - "java.lang.String", - "firstarg", - "io.sarl.tests.Stub" + index + "#MYFCT_0", - InferredStandardParameter.class, - "int", - "secondarg", - InferredValuedParameter.class, - "float", - "thirdarg", - "io.sarl.tests.Stub" + index + "#MYFCT_1", - InferredStandardParameter.class, - "java.lang.Object[]", - "fourtharg", - }); + InferredValuedParameter.class, + "java.lang.String", + "firstarg", + "io.sarl.tests.Stub" + index + "#MYFCT_0", + InferredStandardParameter.class, + "int", + "secondarg", + InferredValuedParameter.class, + "float", + "thirdarg", + "io.sarl.tests.Stub" + index + "#MYFCT_1", + InferredStandardParameter.class, + "java.lang.Object[]", + "fourtharg", + }); } @Test @@ -1561,7 +1574,7 @@ public void createPrototypeFromJvmModel_varArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); // - InferredPrototype prototype = this.provider.createPrototypeFromJvmModel(qn, true, this.jvmParameters); + InferredPrototype prototype = this.provider.createPrototypeFromJvmModel(this.context, qn, true, this.jvmParameters); assertNotNull(prototype); assertEquals("myfct", prototype.getActionName().getActionName()); assertSameJvmFormalParameters(this.jvmParameters, prototype.getFormalParameters()); @@ -1589,51 +1602,51 @@ public void createPrototypeFromJvmModel_varArg() { "fourtharg"); assertPrototypes(prototype.getInferredParameterTypes(), new Object[] { - InferredStandardParameter.class, - "java.lang.String", - "firstarg", - InferredStandardParameter.class, - "int", - "secondarg", - InferredValuedParameter.class, - "float", - "thirdarg", - "io.sarl.tests.Stub" + index + "#MYFCT_1", - InferredStandardParameter.class, - "java.lang.Object[]", - "fourtharg", - }, + InferredStandardParameter.class, + "java.lang.String", + "firstarg", + InferredStandardParameter.class, + "int", + "secondarg", + InferredValuedParameter.class, + "float", + "thirdarg", + "io.sarl.tests.Stub" + index + "#MYFCT_1", + InferredStandardParameter.class, + "java.lang.Object[]", + "fourtharg", + }, new Object[] { - InferredValuedParameter.class, - "java.lang.String", - "firstarg", - "io.sarl.tests.Stub" + index + "#MYFCT_0", - InferredStandardParameter.class, - "int", - "secondarg", - InferredStandardParameter.class, - "float", - "thirdarg", - InferredStandardParameter.class, - "java.lang.Object[]", - "fourtharg", - }, + InferredValuedParameter.class, + "java.lang.String", + "firstarg", + "io.sarl.tests.Stub" + index + "#MYFCT_0", + InferredStandardParameter.class, + "int", + "secondarg", + InferredStandardParameter.class, + "float", + "thirdarg", + InferredStandardParameter.class, + "java.lang.Object[]", + "fourtharg", + }, new Object[] { - InferredValuedParameter.class, - "java.lang.String", - "firstarg", - "io.sarl.tests.Stub" + index + "#MYFCT_0", - InferredStandardParameter.class, - "int", - "secondarg", - InferredValuedParameter.class, - "float", - "thirdarg", - "io.sarl.tests.Stub" + index + "#MYFCT_1", - InferredStandardParameter.class, - "java.lang.Object[]", - "fourtharg", - }); + InferredValuedParameter.class, + "java.lang.String", + "firstarg", + "io.sarl.tests.Stub" + index + "#MYFCT_0", + InferredStandardParameter.class, + "int", + "secondarg", + InferredValuedParameter.class, + "float", + "thirdarg", + "io.sarl.tests.Stub" + index + "#MYFCT_1", + InferredStandardParameter.class, + "java.lang.Object[]", + "fourtharg", + }); } @Test @@ -1641,7 +1654,7 @@ public void getPrototypesQualifiedActionName_noCreatedPrototype() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); // - Iterable iterable = this.provider.getPrototypes(qn); + Iterable iterable = this.provider.getPrototypes(this.context, qn); assertNotNull(iterable); assertFalse(iterable.iterator().hasNext()); } @@ -1650,9 +1663,9 @@ public void getPrototypesQualifiedActionName_noCreatedPrototype() { public void getPrototypesQualifiedActionName_createdPrototype_noVarArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); - InferredPrototype expected = this.provider.createPrototypeFromSarlModel(qn, false, this.sarlParameters); + InferredPrototype expected = this.provider.createPrototypeFromSarlModel(this.context, qn, false, this.sarlParameters); // - Iterable iterable = this.provider.getPrototypes(qn); + Iterable iterable = this.provider.getPrototypes(this.context, qn); assertNotNull(iterable); Iterator iterator = iterable.iterator(); assertTrue(iterator.hasNext()); @@ -1665,9 +1678,9 @@ public void getPrototypesQualifiedActionName_createdPrototype_noVarArg() { public void getPrototypesQualifiedActionName_createdPrototype_varArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); - InferredPrototype expected = this.provider.createPrototypeFromSarlModel(qn, true, this.sarlParameters); + InferredPrototype expected = this.provider.createPrototypeFromSarlModel(this.context, qn, true, this.sarlParameters); // - Iterable iterable = this.provider.getPrototypes(qn); + Iterable iterable = this.provider.getPrototypes(this.context, qn); assertNotNull(iterable); Iterator iterator = iterable.iterator(); assertTrue(iterator.hasNext()); @@ -1682,7 +1695,7 @@ public void getPrototypesQualifiedActionNameActionParameterTypes_noCreatedProtot QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); ActionParameterTypes types = this.provider.createParameterTypesFromSarlModel(false, this.sarlParameters); // - InferredPrototype prototype = this.provider.getPrototypes(qn, types); + InferredPrototype prototype = this.provider.getPrototypes(this.context, qn, types); assertNull(prototype); } @@ -1691,9 +1704,9 @@ public void getPrototypesQualifiedActionNameActionParameterTypes_createdPrototyp JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); ActionParameterTypes types = this.provider.createParameterTypesFromSarlModel(false, this.sarlParameters); - InferredPrototype expected = this.provider.createPrototypeFromSarlModel(qn, false, this.sarlParameters); + InferredPrototype expected = this.provider.createPrototypeFromSarlModel(this.context, qn, false, this.sarlParameters); // - InferredPrototype prototype = this.provider.getPrototypes(qn, types); + InferredPrototype prototype = this.provider.getPrototypes(this.context, qn, types); assertNotNull(prototype); assertSame(expected, prototype); } @@ -1703,9 +1716,9 @@ public void getPrototypesQualifiedActionNameActionParameterTypes_createdPrototyp JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); ActionParameterTypes types = this.provider.createParameterTypesFromSarlModel(true, this.sarlParameters); - InferredPrototype expected = this.provider.createPrototypeFromSarlModel(qn, true, this.sarlParameters); + InferredPrototype expected = this.provider.createPrototypeFromSarlModel(this.context, qn, true, this.sarlParameters); // - InferredPrototype prototype = this.provider.getPrototypes(qn, types); + InferredPrototype prototype = this.provider.getPrototypes(this.context, qn, types); assertNotNull(prototype); assertSame(expected, prototype); } @@ -1715,10 +1728,11 @@ public void resetPrototypes_noCreatedProtype() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); ActionParameterTypes types = this.provider.createParameterTypesFromSarlModel(false, this.sarlParameters); + assertNotNull(types); // - assertFalse(this.provider.getPrototypes(qn).iterator().hasNext()); - this.provider.clear(container); - assertFalse(this.provider.getPrototypes(qn).iterator().hasNext()); + assertFalse(this.provider.getPrototypes(this.context, qn).iterator().hasNext()); + this.context.release(); + assertFalse(this.provider.getPrototypes(this.context, qn).iterator().hasNext()); } @Test @@ -1726,11 +1740,13 @@ public void resetPrototypes_createdProtype_noVarArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); ActionParameterTypes types = this.provider.createParameterTypesFromSarlModel(false, this.sarlParameters); - InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(qn, false, this.sarlParameters); + assertNotNull(types); + InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(this.context, qn, false, this.sarlParameters); + assertNotNull(prototype); // - assertTrue(this.provider.getPrototypes(qn).iterator().hasNext()); - this.provider.clear(container); - assertFalse(this.provider.getPrototypes(qn).iterator().hasNext()); + assertTrue(this.provider.getPrototypes(this.context, qn).iterator().hasNext()); + this.context.release(); + assertFalse(this.provider.getPrototypes(this.context, qn).iterator().hasNext()); } @Test @@ -1738,11 +1754,13 @@ public void resetPrototypes_createdProtype_varArg() { JvmIdentifiableElement container = createJvmIdentifiableElementStub(); QualifiedActionName qn = this.provider.createQualifiedActionName(container, "myfct"); ActionParameterTypes types = this.provider.createParameterTypesFromSarlModel(true, this.sarlParameters); - InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(qn, true, this.sarlParameters); + assertNotNull(types); + InferredPrototype prototype = this.provider.createPrototypeFromSarlModel(this.context, qn, true, this.sarlParameters); + assertNotNull(prototype); // - assertTrue(this.provider.getPrototypes(qn).iterator().hasNext()); - this.provider.clear(container); - assertFalse(this.provider.getPrototypes(qn).iterator().hasNext()); + assertTrue(this.provider.getPrototypes(this.context, qn).iterator().hasNext()); + this.context.release(); + assertFalse(this.provider.getPrototypes(this.context, qn).iterator().hasNext()); } }