Tuesday, June 30, 2015

[ANN] gwt-places: the PlaceHistoryMapper generator ported as an annotation processor

Hi all,

I just pushed out gwt-places to GitHub: https://github.com/tbroyer/gwt-places
This is a port of the PlaceHistoryMapper generator as an annotation processor: I copied the code from GWT proper and replaced uses of com.google.gwt.core.ext. with javax.lang.model. and javax.annotation.processing; and code generation with JavaPoet.
The tests have been copied almost verbatim, only adapted to JUnit 4 and compile-testing (along with Truth assertions and a bit of Mockito), and Maven (using the maven-invoker-plugin to replace the GWTTestCase machinery and trigger the annotation processor).

This is more of an experiment for now, in preparation for GWT 3.0 which will nuke generators.

The annotation processor is triggered by the presence of the @WithTokenizers annotation. It means that if you use PlaceHistoryMapperWithFactory, you have to annotation your interface with @WithTokenizers even if all your tokenizers come from the factory; just use an empty list in this case: @WithTokenizers({}).
The annotation processor generates a class with the same name as the GWT generator (i.e. the name of your PlaceHistoryMapper subinterface with an "Impl" suffix), so you just have to replace GWT.create(MyPlaceHistoryMapper.class) with new MyPlaceHistoryMapperImpl().

I also added a quick check of @Prefix annotations, but it'll only emit warnings and won't fail the build.

The JAR is available in Sonatype OSSRH snapshots repository at net.ltgt.gwt:gwt-places:1.0-SNAPSHOT; its only dependency is gwt-user.
It's an annotation processor, so usage will depend on your build tool. Ideally you'd put it (along with gwt-user) in your "processor path" (e.g. using the 'apt' configuration in Gradle with my net.ltgt.apt plugin), but if you can't (e.g. if you're using Maven), just add it to your compile classpath.
Note that I only verified that the tests passed, I've not used it anywhere (yet).

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment