Re: Varargs
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Is using unreleased version is a problem for you? Because I'm not sure
if when Attila will be available if he will be at all, so I can go
ahead and fix this, then you can start using it, see if it breaks
something. The more people field-tests something the better. (I don't
even use FM nowadays...)
Thursday, August 4, 2011, 6:25:29 PM, Brian Pontarelli wrote:
> Thanks for the reply. I'll let you guys take it from here ;)
>
> -bp
>
> On Aug 4, 2011, at 3:46 AM, Daniel Dekany wrote:
>
>> OK, I have looked into this, and it seems that this feature (varargs)
>> has never worked in 2.3. FM 2.3.12 has just made things worse, as not
>> even explicitly passing an array (like hasRoles(['foo', 'bar'])) works
>> starting from there, while before 2.3.12 it certainly did. How nobody
>> ran into this and reported for 4.5 years is beyond be. Also, varags
>> has no test coverage in 2.3/2.4...
>>
>> And now I will mostly talk to Attila (the author of BeansWrapper). The
>> problem is this: BeansWrapper.populateClassMapWithBeanInfo(Class) in
>> FM 3.0 calls componentizeLastArg(publicMethod.getParameterTypes(),
>> publicMethod.isVarArgs())) to calculate SimpleMemberModel.argTypes,
>> while 2.3/2.4 just calls publicMethod.getParameterTypes(). The
>> componentizeLastArg method changes the vararg's type from array<T> to
>> T. Thus in 2.3/2.4 the type of the vararg argument, according to
>> SimpleMemberModel.argTypes[theIndexOfTheVarArg], will be array<T>,
>> while in 3.0 it will be T. But all the other parts of the algorithm is
>> the same as in 3.0, so the method call will fail both with
>> hasRoles(["foo", "bar"]) and hasRoles("foo", "bar").
>>
>> Would adding componentizeLastArg to 2.3/2.4 and calling it at the same
>> two places as in 3.0 be a sufficient fix? Would it be backward
>> compatible? I guess it would be, but you are still the one who knows
>> this stuff inside out...
>>
>> --
>> Best regards,
>> Daniel Dekany
>>
>>
>> Wednesday, August 3, 2011, 6:19:59 PM, Brian Pontarelli wrote:
>>
>>> On Aug 3, 2011, at 2:07 AM, Daniel Dekany wrote:
>>>
>>>> Tuesday, August 2, 2011, 9:20:43 PM, Brian Pontarelli wrote:
>>>>
>>>>> I've read that vararg method calls were added to 2.4.12 but I can't
>>>>> find any good docs on how to use them and if there are any special
>>>>> requirements. I have a varargs method that I'm trying to invoke from
>>>>> a template and I'm getting an argument type mismatch exception:
>>>>>
>>>>> public boolean hasRoles(String... roles) {
>>>>> ...
>>>>> }
>>>>>
>>>>>
>>>>> [#if user.hasRoles(["foo", "bar"])]
>>>>> …
>>>>> [/#if]
>>>>>
>>>>> Anyone know how to fix this?
>>>>
>>>> AFAR it's supposed to Just Work (assuming you are using some
>>>> BeansWrapper subclass as the object_wrapper setting, and it's 99% that
>>>> you do). Have you tried user.hasRoles("foo", "bar"), without the []?
>>>
>>> Yeah, tried that. It then complains about trying to convert String
>>> to String[]. I do have a BeansWrapper sub-class, but all it does is set these two options:
>>>
>>> setExposeFields(true);
>>> setSimpleMapWrapper(true);
>>>
>>> Not sure how to fix it, but I changed the method to take an
>>> Iterable<String> and it is working.
>>>
>>> -bp
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
>>> The must-attend event for mobile developers. Connect with experts.
>>> Get tools for creating Super Apps. See the latest technologies.
>>> Sessions, hands-on labs, demos & much more. Register early & save!
>>> http://p.sf.net/sfu/rim-blackberry-1
>>> _______________________________________________
>>> FreeMarker-user mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>>>
>>
>
>
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts.
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1