Community
Participate
Working Groups
20041017 I just updated the JDT UI label provider for var-args. In the Java Models 'IMethod', Var args are signalled in a bit in the method's flags (Flags.isVarargs(method.getFlags()). If this bit is set, this means that parameter types (method.getParameterTypes()) have to be rendered differently. foo(Object x, Object... y) returns parameter types 'Object,Object[]'. The renderer has then to substract one dimension from the last parameters type and render ellipses instead. I understand why this like that and I shows you a lot about how the new construct is internally modelled. But for the Java model being is a source model - Wouldn't it be better to have the varargs information in the signature of the last parameter type? - Flags.toString() now says you have to pass 'flags & ~AccVarargs'. The current implementation doesn't add 'varargs' yet, but if it would, clients would all have to update the code that uses the result directly in code. I think having the varargs information in the last parameter types signature would make it much easier for Java model clients. As Signature.asString(typeSig) does return the correct type string, they would not even have to change something. Also note that the AST also has the information in the parameter node.
We are actually following the language spec which dictates this behavior. The varargs modifier is carried by the method itself.
Dirk, your opinion? I like the solution chosen for the DOM AST. When you ask a IMethod for its parameter types, it should return what is found in the source and not how the compiler sees the thing.
Then how would you represent the signature of a vararg parameter ? Beside, on signature front, you have to be prepared to the fact that AccVarargs is colliding with AccTransient (for fields), and do the adequate change if you don't want to see transient methods !? This is no different from what is occurring in the binaries, and is sticking close to the language spec spirit. The DOM AST doesn't need to harmonize with binaries.