antlr / stringtemplate4

StringTemplate 4
http://www.stringtemplate.org
Other
956 stars 231 forks source link

ST4 ObjectModelAdaptor unable to find Boolean kotlin property starting with "is" #219

Closed ghost closed 5 years ago

ghost commented 5 years ago

Affected ST4 version: 4.0.2

Lets create simple

class PojoKotlin(var isTrue: Boolean = true) 

object with isTrue set to "true"

If i want to render following template:

render_pojo(pojo) ::= <<
<if(pojo.isTrue)>
property is true
<else>
property is false
<endif>
>>

then "property is false" is rendered.

This happens because ObjectModelAdaptor unable to find isTrue property when kotlinc compiler is used to fullfill reflection data. If property starts with "is" then "isTrue()" getter is generated but ST4 expects either "getIsTrue" or "isIsTrue". If you remove "is" prefix or use Java class then ST4 handles it perfectly.

Please check my debug screenshot:

kotlin-bug

parrt commented 5 years ago

Oh that's a drag. Not sure I should change this so it works with Kotlin. won't that break the Java connection?

ghost commented 5 years ago

You can add extra if statement which checks whether methodSuffix starts with "is" if so then try to look it up. I can create PR with tests covered. This should not break compatibility with Java.

Not sure I should change this so it works with

Not a big problem, just FYI. You may close the issue

Thanks

parrt commented 5 years ago

ok, thanks.