Skip to content

stephenh/gwt-mpv-apt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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/XxxResult DTOs for gwt-dispatch as you change the XxxSpec class annotated with @GenDispatch
  • XxxEvent/XxxHandler events for GWT events as you change the XxxEventSpec class annotated with @GenEvent
  • XxxPlace classes for gwt-mpv places

Also see these blog posts:

Install

  • Download gwt-mpv-apt.jar, put it in your project's classpath
  • 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 with Action and Result
  • The @In(1)/@In(2) annotations are required for deterministic ordering due to an Eclipse bug
  • You can configure where Eclipse/javac puts the generated source code, which the GWT compiler will need access to
  • gwt-mpv-apt should auto-detect whether you are using gwt-dispatch or gwt-platform and use the respective Action/Result interfaces

@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 with Event and Handler
  • Per @GenDispatch, the @Param(1)/@Param(2) annotations are to enforce deterministic ordering
  • Per @GenDispatch, you can configure where Eclipse/javac puts 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 serialVersionUID fields
    • Now available in the Maven central repository
  • 2.1 - 2011-05-26
    • Deleting XxxSpec classes now automatically deletes the derived artifacts (used to require a clean build)
  • 2.0 - 2011-05-26
    • Add support for com.google.web.bindery events--by default all events extend the new Event unless @GenEvent(gwtEvent = true) is used
  • 1.12 - 2010-11-30
    • Add EventBus parameter to generated DispatchUiCommands
  • 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.NAME field for accessing place names
  • 1.9 - 2010-09-18
    • Add a static fire method for each available event bus (HandlerManager, gwt-presenter, gwt-mpv, etc.)
  • 1.8 - 2010-09-18
    • Add newRequest static method to generated places
  • 1.7 - 2010-09-14
    • Add @GenPlace annotation for generating gwt-mpv places
  • 1.6 - 2010-07-22
    • Add static XxxEvent.fire method for @GenEvent events
  • 1.5 - 2010-07-22
    • Update for gwt-platform 0.3 package name change
  • 1.4 - 2010-07-22
    • Add @In/@Out field annotations for @GenDispatch
    • Add @Param field annotation for @GenEvent
  • 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 @GenDispatch baseAction and baseResult parameters
    • Fix corrupted 1.1 release jar
  • 1.1 - 2010-06-27
    • Add auto-detection of gwt-dispatch for @GenDispatch-generated DTOs
    • Add ivy to build.xml for downloading jars and publishing to the maven repo
  • 1.0 - 2010-06-06
    • Project renamed from gwtasyncgen to gwt-mpv-apt

About

an annotation processor to generate GWT events and action/result DTOs

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages