You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Iskander Absalyamov <ab...@gmail.com> on 2012/07/25 05:42:30 UTC

[jexl] Number coercion in assignments and method calls

What is a good way to make JEXL 2.1 coerce int/double values to
BigDecimal outside arithmetic expressions? So that one could write:
    someBean.someBigDecimalProperty = 1;
instead of:
    someBean.someBigDecimalProperty = 1.0b;

This is needed because non-technical users don't understand the
difference. Also, this seems a reasonable requirement because
JexlArithmetic does it already.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [jexl] Number coercion in assignments and method calls

Posted by Iskander Absalyamov <ab...@gmail.com>.
Thank you, Henri!

I'll add:
/** Use only in JEXL scripts. */
@Deprecated
public void setSomeBigDecimalProperty(Number n) {...}

With overriding Interpreter.setAttribute(...), one would also need to
override methods instantiating it.

I can't use snapshots.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [jexl] Number coercion in assignments and method calls

Posted by henrib <he...@apache.org>.
Hi;
The easiest solution would be by flanking the problem altogether by adding a
'public void setSomeBigDecimalProperty(Number n)' or 'public void
setSomeBigDecimalProperty(double d)' method  to your 'someBean' class.

The other possible solutions:
1/ derive the Interpreter to override the 'setAttribute' method to 'widen'
(on top of trying to 'narrow') the method argument when dealing with a
number property, i.e. try to find a method by casting the argument to
BigDecimal (uberspect.getPropertySet(...)).
2/ some way to define the default number literal class (so 1 is indeed
evaluated as BigDecimal("1")) but there is no such thing in 2.1; I can try
adding this in 3.0 if you can use snapshots.

Cheers,
Henrib



--
View this message in context: http://apache-commons.680414.n4.nabble.com/jexl-Number-coercion-in-assignments-and-method-calls-tp4636999p4637008.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org