Bug 527857 - Default value assigned to the optional parameter using @ScriptParameter annotation doesn't work in groovy engine.
Summary: Default value assigned to the optional parameter using @ScriptParameter annot...
Status: CLOSED MOVED
Alias: None
Product: Ease
Classification: Technology
Component: Engines (show other bugs)
Version: 0.4.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: accessibility, helpwanted, usability
Depends on:
Blocks:
 
Reported: 2017-11-28 07:11 EST by Subitsha Unnikrishnan CLA
Modified: 2023-11-21 12:56 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Subitsha Unnikrishnan CLA 2017-11-28 07:11:25 EST
Groovy engine doesn't consider the default value assigned to the optional parameter. (engine id: org.eclipse.ease.engine.groovy)

Example:
In scripting perspective switch to the groovy engine. And then load the launch module as follows.
	loadModule('/System/Launch');
	
After loading the module try to access the launch method in it. 

launch method has two parameters in which the second one is optional. So the expectation is, even if we pass only one parameter the method should get invoked.

But for the following script it throws error like No signature of method.
	
	loadModule('/System/Launch');
	launch(launchConfig)
	
Error message:
No signature of method: Wrapping_org_eclipse_ease_modules_platform_debug$_run_closure5.call() is applicable for argument types: (null) values: [null]
Possible solutions: any(), any(), any(groovy.lang.Closure), each(groovy.lang.Closure), any(groovy.lang.Closure), each(groovy.lang.Closure)
	
It works fine if we pass two arguments.

This case happens only, if we have more than one parameters in the module. 
	

In other case, if we have a method which has only one parameter, which is mandatory, it accepts the method call without any argument.  
For Example,
Call the install method after loading p2 module.
 loadModule('/System/P2');
 install()
	
	
install method has one mandatory parameter. 
But without passing any parameter that method got invoked.
No error message was thrown.
Comment 1 Christian Pontesegger CLA 2017-11-28 13:07:23 EST
Optional parameter support is currently not implemented.
Any commit on groovy are very welcome.
Comment 2 rgra Missing name CLA 2018-10-21 11:11:32 EDT
This should fix it:

org.eclipse.ease.lang.groovy.GroovyCodeFactory.createFunctionWrapper
// build parameter string
final StringBuilder parameterList = new StringBuilder();
for (final Parameter parameter : parameters) {
  parameterList.append(", ").append(parameter.getName());
  if (parameter.isOptional()) {
    parameterList.append("=").append(getDefaultValue(parameter));
  }
}

I don't understand what
org.eclipse.ease.lang.groovy.GroovyCodeFactory.classInstantiation()
is for. It adds some import Code stuff when using optional. Worked for me so far when I return "null". But maybe Christian can explain what it was needed for?
Comment 3 Christian Pontesegger CLA 2018-10-29 05:29:28 EDT
@Rabea: would you mind to commit this to gerrit?
Comment 4 Eclipse Genie CLA 2019-01-20 05:23:21 EST
New Gerrit change created: https://git.eclipse.org/r/135408
Comment 5 Frederic Gurr CLA 2023-11-21 12:56:18 EST
This issue has been migrated to https://gitlab.eclipse.org/eclipse/ease/ease/-/issues/126.