Skip to content

Commit

Permalink
[lang] Create a signature building function from a formal parameter p…
Browse files Browse the repository at this point in the history
…rovider.

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Jan 8, 2015
1 parent 65a031f commit 81cd7bc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Expand Up @@ -75,6 +75,14 @@ public interface ActionSignatureProvider {
*/
SignatureKey createSignatureIDFromJvmModel(boolean isVarargs, EList<JvmFormalParameter> parameters);

/** Build an identifier for the given parameters.
*
* @param isVarargs - indicates if the signature has a variatic parameter.
* @param provider - the provider of the formal parameters.
* @return the id.
*/
SignatureKey createSignatureID(boolean isVarargs, FormalParameterProvider provider);

/** Build an identifier for the given parameters.
* <p>
* The given parameter must following the format of the value given
Expand Down Expand Up @@ -126,4 +134,36 @@ public interface ActionSignatureProvider {
*/
InferredActionSignature getSignatures(ActionNameKey actionID, SignatureKey signatureID);

/** An object able to provide the name and the type of a formal parameter.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
public interface FormalParameterProvider {

/** Replies the number of formal parameters.
*
* @return the number of formal parameters.
*/
int getFormalParameterCount();

/** Replies the name of the formal parameter at the given position.
*
* @param position - the position of the formal parameter.
* @return the name of the formal parameter.
*/
String getFormalParameterName(int position);

/** Replies the type of the formal parameter at the given position.
*
* @param position - the position of the formal parameter.
* @param isVarargs - indicates if the parameter should be considered as a vararg parameter.
* @return the type of the formal parameter.
*/
String getFormalParameterType(int position, boolean isVarargs);

}

}
Expand Up @@ -240,6 +240,27 @@ public SignatureKey createSignatureIDFromJvmModel(boolean isVarargs, EList<JvmFo
return sig;
}

@Override
public SignatureKey createSignatureID(boolean isVarargs,
FormalParameterProvider provider) {
int count = provider.getFormalParameterCount();
SignatureKey sig = new SignatureKey(isVarargs, count);
if (count > 0) {
if (isVarargs) {
--count;
for (int i = 0; i < count; ++i) {
sig.add(provider.getFormalParameterType(i, false));
}
sig.add(provider.getFormalParameterType(count, true));
} else {
for (int i = 0; i < count; ++i) {
sig.add(provider.getFormalParameterType(i, false));
}
}
}
return sig;
}

@Override
public SignatureKey createSignatureIDForVoid() {
return new SignatureKey(false, 0);
Expand Down

0 comments on commit 81cd7bc

Please sign in to comment.