Hi all,
I'm new for freemarker. I tried to create my customized directive as
below but could not run it in a right way:
public class TypeSimpleNameDirective implements TemplateDirectiveModel {
private static final String PARAM_CLAZZ = "clazz";
@Override
public void execute(Environment env, Map params, TemplateModel[]
loopVars, TemplateDirectiveBody body) throws TemplateException,
IOException {
// Check if no parameters were given:
if (!params.containsKey(PARAM_CLAZZ)) {
throw new TemplateModelException(
"typeSimpleName required parameter clazz.");
}
if (!(params.get(PARAM_CLAZZ) instanceof ClassDescription)) {
throw new TemplateModelException(
"clazz should be a instance of ClassDescription but " +
ClassUtils.getShortClassName(params.get(PARAM_CLAZZ), "null") + " is
given.");
}
ClassDescription cls = (ClassDescription) params.get(PARAM_CLAZZ);
......
}
And then I used it like this:
<@typeSimpleName clazz=api.returnType></@typeSimpleName>
The api.returnType is ClassDescription.
Then it threw an error:
> clazz should be a instance of ClassDescription but StringModel is given.
Any help is appreciated.