Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 337052 - Parameter with Upper Bound -1 as varargs
Summary: Parameter with Upper Bound -1 as varargs
Status: NEW
Alias: None
Product: EMF
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Ed Merks CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-13 03:46 EST by Thomas Hallgren CLA
Modified: 2021-11-21 09:58 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Hallgren CLA 2011-02-13 03:46:40 EST
I would like to be able to generate a Java varargs declaration when the last parameter in an operation is declared with an upper bound of -1. At present, it is declared as an EList<T> instead and there's no way for me to override it.
Comment 1 Ed Merks CLA 2011-02-13 04:23:18 EST
We can't just change the meaning for existing constructs...  It definitely would be nice to be able to express varargs though (which are really much like an array type, not a list).
Comment 2 Thomas Hallgren CLA 2011-02-13 04:52:46 EST
Perhaps you could add a condition to the genmodel that would allow the parameter to be generated differently? The default behavior would of course remain the same as today.
Comment 3 Ed Merks CLA 2011-06-05 14:06:32 EDT
It would make sense to include an annotation on either the operation or the parameter (only the last parameter can be a vararg) that would generate X... instead of X[].  A vararg is after all purely syntactic sugar for implicit array literals so it seems best to stick with an EDataType representing an array rather than contorting the meaning for unbounded...
Comment 4 Thomas Hallgren CLA 2011-06-06 03:35:51 EDT
The syntax also affects the caller so I think a request to support varargs makes a lot of sense. The method declarations:

 void foo(String[] args) {
 }

and:

 void foo(String...args) {
 }

will impose different requirements on how a call must be written. If you write:

 foo("", "");

to call the first form, you'll get the error "The method foo(String[]) in the type SampleClass is not applicable for the arguments (String, String).

Supporting arrays would of course be a good first step but forcing all calls to be in the form:

 foo(new String[] { "", "" })

just because it's more pure would be bad IMO. Why not support both forms?
Comment 5 Ed Merks CLA 2011-06-06 12:34:33 EDT
What I was suggesting was to support an annotation that would make the final parameter, if it's an EDataType that's an array (i.e., if the instance type name ends with []), be generated as ... instead of [].  This way, reflectively, i.e., for EObject.eInvoke, there's really nothing special needed.