getListArg method returns bad results with `name` argument #2014

Closed
gnoubi opened this Issue Oct 4, 2016 · 5 comments

Projects

None yet

2 participants

@gnoubi
gnoubi commented Oct 4, 2016

Steps to reproduce

  1. develop a skill that contains statement with a argument of type list
  2. test the skill
    list tata <- ["toto","titi"];
    do expose names:tata;
  3. get "names" parameter with the JAVA instruction:
    GamaList varNames = (GamaList)scope.getListArg("names");

Expected behavior

a list of string that contains "toto" and "titi"

Actual behavior

a list of string that contains "tata", the name of the variable. Not that writing 'do expose names:["toto","titi"]'; is not allowed

System and version

The last version of gama

@AlexisDrogoul
Member

Is it possible to have a look at the way the primitive is defined ?

@AlexisDrogoul
Member

I just tried it and it works without problems. I have defined the following:

    @action(name = "expose", args = { @arg(name = "names", type = IType.LIST) })
    public Object expose(final IScope scope) {
        return scope.getListArg("names");
    }

and it correctly accepts literal lists or variables, and getListArg correctly returns the passed arguments.

Be sure to verify to clean your projects before running GAMA (if you use the Eclipse version)

@gnoubi
gnoubi commented Oct 4, 2016

The problem happens when VAR_NAME=« name ». When you change the value of « VAR_NAME » it works.

Thanks for the solution

@action(name = IRemoteGUISkill.EXPOSE_VAR, args = {
        @arg(name = IRemoteGUISkill.VAR_NAME, type = IType.LIST, optional = false, doc = @doc("server nameL")),
        @arg(name = IRemoteGUISkill.EXPOSED_NAME, type = IType.STRING, optional = false, doc = @doc("server nameL"))
     }, doc = @doc(value = "", returns = "", examples = { @example("") }))
public void exposeToRemoteGui(IScope scope)
{


    IAgent agt = scope.getAgent();

    String url = (String)agt.getAttribute(IRemoteGUISkill.SERVER_URL);
    String login = (String)agt.getAttribute(IRemoteGUISkill.LOGIN);
    String pass = (String) agt.getAttribute(IRemoteGUISkill.PASSWORD);
    @SuppressWarnings("unchecked")
    ArrayList<String> varName =  (ArrayList<String>)scope.getListArg(IRemoteGUISkill.VAR_NAME); //scope.getArg(IRemoteGUISkill.VAR_NAME,IType.MAP);
    String exposedName = (String )scope.getArg(IRemoteGUISkill.EXPOSED_NAME,IType.STRING);

try {
        SharedVariable varS = new SharedVariable(agt, (ArrayList<String>) varName, exposedName, connection,SharedVariable.EXPOSED_VARIABLE);
        this.getShareVariables(scope).add(varS);
    } catch (MqttException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Nicolas Marilleau
UMI 209 UMMISCO Institut de Recherche pour le Développement
Chercheur invité DISC/ Femto-ST Université de Franche-Comté

32 rue Henri Varagnat
93143 Bondy Cedex
tel : 01.48.02.79.01
mobile : 06.88.33.49.06

Le 4 oct. 2016 à 18:26, Alexis Drogoul notifications@github.com a écrit :

I just tried it and it works without problems. I have defined the following:

@action(name = "expose", args = { @arg(name = "names", type = IType.LIST) })
public Object expose(final IScope scope) {
    return scope.getListArg("names");
}

and it correctly accepts literal lists or variables, and getListArg correctly returns the passed arguments.

Be sure to verify to clean your projects before running GAMA (if you use the Eclipse version)


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #2014 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AF0pHkV0Bd6pBk44ZrxFDh2igldVV62yks5qwn5LgaJpZM4KNqJi.

@AlexisDrogoul
Member

Well. With name, effectively, the problem is not in the way the arguments are passed, but in the call: when you write do expose name: tata, this facet is transformed into a label automatically (that's an automated transformation deep inside the grammar). However, if you write do expose(name: tata) or do expose(tata) it should work as expected. I'll see if I can circumvent this default behavior.

@AlexisDrogoul
Member

I've verified it. name, like keyword or returns, is a special facet that is directly defined as either an identifier or a string at the syntactic level. So it won't accept anything else, and will directly compile whatever is passed as an identifier or a string. So if you use the facility represented by passing arguments like facets (i.e. do expose name: tata), then tata is treated as an identifier and not a variable. However, using the two other functional forms works as expected. I'm afraid there is nothing I can do easily to fix this... Maybe emitting a warning in the Java code would be the solution ?

@AlexisDrogoul AlexisDrogoul changed the title from getListArg method returns unexpected results to getListArg method returns bad results with `name` argument Oct 6, 2016
@AlexisDrogoul AlexisDrogoul added a commit that closed this issue Nov 9, 2016
@AlexisDrogoul AlexisDrogoul Fixes #2014 by emitting a warning at compilation time in Java.
Signed-off-by: AlexisDrogoul <alexis.drogoul@gmail.com>
09cbca4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment