groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcin ZajÄ…czkowski <>
Subject Custom implicit type conversion on assignment
Date Fri, 31 Mar 2017 14:02:33 GMT

To simplify initialization of my production Money object in tests I've written an extension
module to use explicit coercion:

> Money tenDolars = 10.0 as Money	//works fine, but could be shorter

It works fine, but it's Groovy so I would like to achieve more :).

My idea is to be able to write:

> Money tenDolars = 10.0	//desired construction

I was thinking about AST transformation (global or annotation based) to modify assignments
like those (with Money on the left side and BigDecimal on the right) in a given class (or
globally in a test context) to add explicit coercion automatically.

Unfortunately, usually AST transformations I've found deal with adding methods or statements
in a method.

Could you point a Groovy build-in transformation or a place in Groovy code which deals with
implicit coercion?


-- - Working code is not enough

View raw message