I have some concerns (sorry, not had time to look through the patch yet).
1) The TypeSafeMatcher implements vital functionality -- type checking
and null checking. How do you make the matchers safe with a
do-nothing implementation? Perhaps we need to revisit how that is
implemented and, instead, force subclasses to pass the expected class
to the super constructor. The whole injection thing makes me
uncomfortable -- it looks like a potential maintenance and testing
problem for the future. Which brings me to...
2) How can we ensure future changes to Hamcrest don't break the GWT
version? Can we make the build compile to Javascript and run tests in
GWT somehow?
--Nat
2008/8/26 Pascal Muetschard <pmuet...@google.com>:
I'd prefer to share as much as possible, ideally everything, between
the GWT and Java versions.
> 1. About TypeSafeMatcher. Yes, checking for the right type and null is an
> important part of those matchers and is, of course, maintained in GWT...
...
> GWT does not have reflection (or at least only very
> very partial reflection). So, this means that Class.isAssignableFrom and
> Class.isInstance are not available.
That's a pain.
> On the other hand, the "instanceof" operator is.
How strange, since they do the same thing and Javascript is entirely dynamic.
> Now, to use the instanceof operator, we need to know the type
> at compile time. The funny thing is, for all of the library matchers that
> extend TypeSafeMatcher, we do know the type at compile time. So, in order to
> not loose the functionality of all those matchers, I added "intermediate"
> classes, such as StringTypeSafeMatcher, which explicitly state at compile
> time what type they are looking for. This means that when running in plain
> old Java, the TypeSafeMatcher does all the work using reflection (as it does
> now) and the StringTypeSafeMatcher and its cohorts are empty. Whereas for
> GWT, the TypeSafeMatcher is empty and the StringTypeSafeMatcher and its
> cohorts do all the work since at compile time they will use "item instanceof
> <whatever>". I hope that makes more sense.
That's what I'm uncomfortable with. I'd actually prefer that the GWT
and Java versions were the same.
I think that the matchers provided by the Hamcrest should extend
StringTypeSafeMatcher, DoubleTypeSafeMatcher etc. to be GWT-compatible
and TypeSafeMatcher<T> should remain in the library for Java
programmers to extend when writing their own matchers.
(Actually I'd prefer the names StringMatcher, DoubleMatcher, etc.)
> 2. This is a very good question. I have been thinking about this and the
> best solution would be to do a JS compile of the GWT library in ant.
> However, this means adding a dependency in the build libraries on GWT (which
> might not be that bad) and at least an additional 30seconds of build time,
> which sucks since a clean build including running junit currently takes less
> than 10 seconds. If we can live with both (we can always make the GWT
> compile an optional operation for the all target) I will be happy to add
> that to the ant script.
An separate build target that compiles and tests the GWT version would
be great. Adding the GWT libraries as a dependency is not a problem.
--Nat
On 26 Aug 2008, at 23:31, Nat Pryce wrote:
> I think that the matchers provided by the Hamcrest should extend
> StringTypeSafeMatcher, DoubleTypeSafeMatcher etc. to be GWT-compatible
> and TypeSafeMatcher<T> should remain in the library for Java
> programmers to extend when writing their own matchers.
>
> (Actually I'd prefer the names StringMatcher, DoubleMatcher, etc.)
So, GWT users might write their own type safe extensions, but not
using the TypeSafeMatcher? We'd need to make clear which parts are GWT-
safe and which not.
>> 2. This is a very good question. I have been thinking about this
>> and the
>> best solution would be to do a JS compile of the GWT library in ant.
>> However, this means adding a dependency in the build libraries on
>> GWT (which
>> might not be that bad) and at least an additional 30seconds of
>> build time,
>> which sucks since a clean build including running junit currently
>> takes less
>> than 10 seconds. If we can live with both (we can always make the GWT
>> compile an optional operation for the all target) I will be happy
>> to add
>> that to the ant script.
>
> An separate build target that compiles and tests the GWT version would
> be great. Adding the GWT libraries as a dependency is not a problem.
Again, we should be clear about what the different environments need
to run. It should be obvious to "normal" users that they don't need
the GWT libraries, so we should make an effort to package nicely.
We should also resolve the difference reporting API before this
happens (or during).
S.
Steve Freeman
Winner of the Agile Alliance Gordon Pask award 2006
M3P Limited.
Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
Company registered in England & Wales. Number 03689627
Nat's away for a couple of weeks, so we can discuss when everyone gets
back.
S
Steve Freeman
--Nat
2008/10/2 Pascal Muetschard <pmuet...@google.com>: