gwt-mpv-apt
gwt-mpv-apt copied to clipboard
an annotation processor to generate GWT events and action/result DTOs
Note: As of December 2011, gwt-mpv-apt was merged into it's sister project, gwt-mpv, which was renamed Tessell. See tessell.org for more information. The tessell-apt 2.0.0 release (which syncs the version number with the rest of Tessell) is functionality equivalent to the gwt-mpv-apt 2.2 release, except with org.tessell package names.
This does not necessarily mean gwt-mpv-apt is dead. If gwt-mpv-apt users need any bug fixes or future features done here instead of migrating to tessell-apt, post-2.2 releases are still possible, just somewhat unlikely given the gwt-mpv-ap codebase was already fairly mature and stable.
gwt-mpv-apt is a Java 6 annotation processor to help generate some of the boilerplate code involved in GWT projects.
Annotation processors enable compiler-/IDE-driven generated-as-you-type code generation based on Java files in your project.
gwt-mpv-apt currently will generate:
XxxAction/XxxResultDTOs for gwt-dispatch as you change theXxxSpecclass annotated with@GenDispatchXxxEvent/XxxHandlerevents for GWT events as you change theXxxEventSpecclass annotated with@GenEventXxxPlaceclasses for gwt-mpv places
Also see these blog posts:
Install
- Download
gwt-mpv-apt.jar, put it in your project's classpath- See the downloads page or the central maven repo search
- In Eclipse, go to Project Settings, Java Compiler, Annotation Processing, and hit "Enable processing specific settings". Go to Factory path and hit "Enable project specific settings". Select the
gwt-mpv-apt.jar, hit Okay. - For
javac, use JDK6 and it will pick up the processor from your classpath automatically
Maven
To work with annotation processors in Maven, your pom.xml should look vaguely like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<generatedSourcesDirectory>${project.build.directory}/generated-sources/apt</generatedSourcesDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/apt</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
(Thanks to Andrew Green.)
Examples
@GenDispatch
If you type:
@GenDispatch
public class SubmitUserSpec {
@In(1)
Integer id;
@In(2)
String name;
@Out(1)
boolean success;
@Out(2)
String[] messages;
}
gwt-mpv-apt will generate two classes, SubmitUserAction and SubmitUserResult. SubmitUserAction will have fields, getters, and a constructor (or two as needed for serialization) for id and name. SubmitResultResult will have the same for success, and messages. equals and hashCode are also correctly implemented if you need it for caching/etc. purposes.
All told, this is ~100 lines of boilerplate code generated from ~8 lines in the spec class.
Notes:
- You must end your class name in
Spec--it will be stripped and replaced withActionandResult - The
@In(1)/@In(2)annotations are required for deterministic ordering due to an Eclipse bug - You can configure where Eclipse/
javacputs the generated source code, which the GWT compiler will need access to gwt-mpv-aptshould auto-detect whether you are usinggwt-dispatchorgwt-platformand use the respectiveAction/Resultinterfaces
@GenEvent
If you type:
@GenEvent
public class FooChangedEventSpec {
@Param(1)
Foo foo;
@Param(2)
boolean originator;
}
gwt-mpv-apt will generate two classes, FooChangedEvent and FooChangedHandler. FooChangedEvent will have fields, getters, and a constructor for foo and originator, plus static getType(), instance dispatch, etc., for it to function correctly as a GwtEvent. FooChangedHandler will be an interface with a onFooChanged method that takes a FooChangedEvent parameter.
Notes:
- You must end your class name in
EventSpec--it will be stripped and replaced withEventandHandler - Per
@GenDispatch, the@Param(1)/@Param(2)annotations are to enforce deterministic ordering - Per
@GenDispatch, you can configure where Eclipse/javacputs the generated source code, which GWT will need access to
Caveats
Eclipse
In Eclipse, you must be running Eclipse on a JDK6 JRE. This does not mean running Eclipse on JDK5 and pointing it at a JDK6 installation in "Installed JREs". For Eclipse's code-generation-as-you-type to work, Eclipse must be on a JDK6 JRE.
For Mac users, this means you need Eclipse 3.5 64-bit because it is compatible with Apple's 64-bit-only JDK6. You will not be able to run Eclipse 3.3/3.4 on Apple's 64-bit JDK6 because the Eclipse 3.3/3.4 SWT bindings are only 32-bit.
IntelliJ
Has mediocre/near-useless annotation processor support last I checked.
Community
For discussion or feedback, either:
- Post on the gwt-mpv-apt mailing list
- File bugs over in issues if you come across them
Credits
gwt-mpv-apt grew out of projects at Bizo, a business demographics advertising company. Thanks to Bizo for their initial and continued support of the project.
Todo
- Handle base classes (done for
@GenDispatch) - Builder/fluent methods?
- Default values in the spec
- Mutable fields on the event, e.g. claimed
Changelog
- 2.2 - 2011-08-22
- Remove unneeded
serialVersionUIDfields - Now available in the Maven central repository
- Remove unneeded
- 2.1 - 2011-05-26
- Deleting
XxxSpecclasses now automatically deletes the derived artifacts (used to require a clean build)
- Deleting
- 2.0 - 2011-05-26
- Add support for
com.google.web.binderyevents--by default all events extend the newEventunless@GenEvent(gwtEvent = true)is used
- Add support for
- 1.12 - 2010-11-30
- Add
EventBusparameter to generatedDispatchUiCommands
- Add
- 1.11 - 2010-10-12
- Make handlers their own top-level class (works better for code completion)
- Add
SuppressWarnings("all")for HandlerManager deprecation - Remove gwt-mpv event bus
- 1.10 - 2010-09-21
- Add a static
XxxPlace.NAMEfield for accessing place names
- Add a static
- 1.9 - 2010-09-18
- Add a static
firemethod for each available event bus (HandlerManager, gwt-presenter, gwt-mpv, etc.)
- Add a static
- 1.8 - 2010-09-18
- Add
newRequeststatic method to generated places
- Add
- 1.7 - 2010-09-14
- Add
@GenPlaceannotation for generating gwt-mpv places
- Add
- 1.6 - 2010-07-22
- Add static
XxxEvent.firemethod for@GenEventevents
- Add static
- 1.5 - 2010-07-22
- Update for gwt-platform 0.3 package name change
- 1.4 - 2010-07-22
- Add
@In/@Outfield annotations for@GenDispatch - Add
@Paramfield annotation for@GenEvent
- Add
- 1.3 - 2010-07-02
- Fix error reporting so it shows up in Eclipse Problems view (Robert Munteanu)
- Use a new pom that does not include the jarjar'd dependencies (Robert Munteanu)
- 1.2 - 2010-06-30
- Add auto-detection of
gwt-platform - Add
@GenDispatchbaseActionandbaseResultparameters - Fix corrupted 1.1 release jar
- Add auto-detection of
- 1.1 - 2010-06-27
- Add auto-detection of
gwt-dispatchfor@GenDispatch-generated DTOs - Add ivy to
build.xmlfor downloading jars and publishing to the maven repo
- Add auto-detection of
- 1.0 - 2010-06-06
- Project renamed from
gwtasyncgentogwt-mpv-apt
- Project renamed from