2.4: Defaults handling; string conversion inconsistencies; and laziness vs annotations
Attila Szegedi <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Folks,
I made quite a lot of changes last night in the 2.4 tree to support
handling of defaults-relying-on-other-parameters in macro parameters
lists. In 2.4, the situation is of course more tricky, as defaults can
also be specified in Java annotations for directive, method, and
transform models. This all now works. In the course of it, I did
discover and fix few other bugs, namely:
- defaults in annotations weren't filled in at all when the directive/
transform was called with no arguments, i.e. if there was a
@Parameters("a=1 b=2")
public class FooDirective implements TemplateDirectiveModel {
...
}
and it was invoked as
<@foo/>
then defaults weren't filled in. If there was at least one argument:
<@foo a=2/>
then the defaults were filled in correctly. This had to do with an
unfortunate use of null for no-args. I solved it by introducing a
special "EmptyArgs" class extending ArgsList (arguably, I could've
just used a zero-arg NamedArgsList, but this also allowed for using a
faster call path).
Also, the model->string conversion needed for TemplateMethodModel that
is not a TemplateMethodModelEx worked differently for non-annotated
methods than for annotated methods. For non-annotated ones, it used
Expression.getStringValue(model, expression, environment) (correctly,
as it did in 2.3.x). For annotated ones, it used
((TemplateScalarModel)model).getAsString(). I fixed that.
Finally, if a method class that implements LazilyEvaluatableArguments
has a Parameters annotation, then its arguments will be eagerly
evaluated. I'll say I can live with this limitation for the time
being; I've just documented it it in the LazilyEvaluatableArguments
JavaDoc; if you agree.
Attila.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/