pivot-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Brown <gkbr...@mac.com>
Subject Automated support for enums
Date Tue, 07 Sep 2010 00:24:03 GMT
I was thinking about how we might add support for automatically converting strings to enum
values, and I came up with something that might work (though I have not prototyped it). We
might be able to use reflection to get the valueOf() method on a particular enum type, and
then invoke it with the string value. We could potentially do this in BeanAdapter.coerce(),
since all BXML type coercion ultimately flows through this method.

However, there's one minor issue with the concept. All of our enum conversion overloads currently
call toUpperCase() on the value. We do this primarily so we can use lower case values in BXML
(for readability). We'd have to do the same thing in coerce() in order to eliminate the overloads.
In general, developers seem to adhere to the all caps/underscore convention when naming enum
values, but it isn't strictly enforced. We'd therefore be imposing a slight limitation on
the use of coerce().

I'm on the fence about it. BeanAdapter and BeanMonitor currently rely on other naming conventions
(getter and setter methods, getXXXListeners(), etc.), so it's not that far-fetched. If the
reflection approach works, is the case conversion a limitation that we can live with?


View raw message