FreeMarker dynamic variables

Hello,

I'm using several FreeMarker templates in my project.  One of the objects added to the template is a wrapper around a record returned from a database (no ORM in this project because the code is generic with no fixed schema), and implements the "any-return-type get(String)" approach described here : http://freemarker.org/docs/pgui_misc_beanwrapper.html

This makes it possible in the template to write this:
record.COLUMNNAME.value

...instead of:
record.getColumn("COLUMNNAME").value

...where "record" is always a specific type (called IItem) and the return type of the "get" method is always another specific type (always IData, or a subinterface, but always with "getValue()").

I can use the intention "Define implicit variable" on record, which adds the following comment to the ".ftl" file:
[#-- @ftlvariable name="record" type="packagename.IItem" --]

...but I can't make it resolve COLUMNNAME (it's underlined with a wavy grey line).  The closest I can get is the intention "Create dynamic method getCOLUMNNAME", which generates a class file (in the default package) like this:

----------------------------------------------------------------------
[#ftl]
[#-- @implicitly included --]


import packagename.IData;
import packagename.IItem;


class FreeMarkerDynamicMethods
{
    static IData getCOLUMNNAME(IItem item)
    {
    }
}

----------------------------------------------------------------------

...but it only works for COLUMNNAME, requires that I bundle source code with the templates, not *any* column name.

Given that the rules for resolving "get" are formalized with FreeMarker (see my link above), and that I've specified the return type, is there any way to make IntelliJ resolve this correctly?

Thanks

1 comment

Hi,

Currently it's not supported. Please file a YouTrack request for this, better with some IItem/IData/subinterface Java code samples.

In the meantime, you can also define an expression type in comment:
[#-- @ftlvariable name="record.COLUMNNAME" type="..." --]
But you have to do this for every column.

0

Please sign in to leave a comment.