rocker icon indicating copy to clipboard operation
rocker copied to clipboard

Informative toString() for DefaultRockerModel.

Open ldaley opened this issue 9 years ago • 3 comments

The current implementation of DefaultRockerModel#toString() throws an exception. This is generally suboptimal practice as toString() can be called in surprising circumstances.

I propose to submit a patch that does the following:

  1. Adds Map<String, ?> getArguments() to RockerModel
  2. Update JavaGenerator to implement this method, that constructs such a map on each invocation (i.e. no caching)
  3. Change DefaultRockerModel#toString() to emit something like:
TemplateClassSimpleName[arg1=value1,arg2=value2]

This would be much more useful in exception messages and debugger UIs.

ldaley avatar Jul 14 '16 02:07 ldaley

Sounds like a reasonable enhancement. Couldn't JavaGenerator build a nice toString() method w/o requiring a Map though?

jjlauer avatar Jul 15 '16 20:07 jjlauer

It certainly could. The getArguments() method seems like a reasonable thing to add though for other tooling.

ldaley avatar Jul 16 '16 02:07 ldaley

I originally did think about exposing the arguments via a getter method, but Java's standard reflection utilities accomplish the same result. https://github.com/fizzed/rocker/blob/master/runtime/src/main/java/com/fizzed/rocker/BindableRockerModel.java needs to access a model's arguments and it is implemented using standard reflection. I never measured performance I suppose, but even if you get the arguments, you'd still need to use reflection to set/get the values.

jjlauer avatar Jul 18 '16 13:07 jjlauer