Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(94)

Issue 912042: Add code generator plugin helpers

Can't Edit
Can't Publish+Mail
Start Review
Created:
4 years ago by t.broyer
Modified:
1 year, 8 months ago
Reviewers:
kenton, Scott Blum
Base URL:
http://protobuf.googlecode.com/svn/trunk/
Visibility:
Public.

Description

In C++, writing a code generator plugin is as easy as implementing CodeGenerator
and passing an instance to google::protobuf::compiler::PluginMain; it shouldn't
be any harder in Java (or Python BTW).

This patch adds a JavaHelpers class which is just a port of
google/protobuf/compiler/java/java_helpers.{h,cc} with a few additional helper
methods; and the abstract Plugin class.

To implement a protoc plugin in Java, simply write an implementation of Plugin,
then create a main() method like:
  public static void main(String[] args) {
    new MyPlugin().run(args);
  }

The main difference with C++ is that the Java code needs to be launched from a
shell/batch script (the patch includes a sample batch file for Windows), and
expects that the name of the script be passed as the first command-line
argument.

The code currently lacks JavaDoc and unit tests but I'm providing it here for an
early review.

Patch Set 1 #

Patch Set 2 : Fixes getDefaultValue for enum fields, and parseGeneratorParameter for empty parts #

Total comments: 40

Patch Set 3 : Factored out a CodeGenerator interface, Plugin now has only static methods #

Total comments: 25

Patch Set 4 : javadoc, unit tests, Context#getParsedFiles, streaming to stdout #

Total comments: 21

Patch Set 5 : Few tweaks based on review #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1311 lines, -0 lines) Patch
java/src/main/java/com/google/protobuf/compiler/CodeGenerator.java View 3 4 1 chunk +129 lines, -0 lines 0 comments Download
java/src/main/java/com/google/protobuf/compiler/JavaHelpers.java View 1 2 3 4 1 chunk +475 lines, -0 lines 0 comments Download
java/src/main/java/com/google/protobuf/compiler/Plugin.java View 1 2 3 4 1 chunk +367 lines, -0 lines 0 comments Download
java/src/test/java/com/google/protobuf/compiler/PluginContextTest.java View 1 chunk +148 lines, -0 lines 0 comments Download
java/src/test/java/com/google/protobuf/compiler/PluginTest.java View 1 chunk +190 lines, -0 lines 0 comments Download
src/google/protobuf/compiler/plugin.proto View 1 2 1 chunk +2 lines, -0 lines 0 comments Download

Messages

Total messages: 16
t.broyer
4 years ago #1
t.broyer
Fixes getDefaultValue for enum fields, and parseGeneratorParameter for empty parts
3 years, 12 months ago #2
kenton
Thanks for doing this! This probably should not be part of libprotobuf.jar, since most people ...
3 years, 12 months ago #3
t.broyer
Thanks for your review. I've only responded to some comments. I'll update my code and ...
3 years, 12 months ago #4
t.broyer
If you don't mind, I'd like to polish/fill-in JavaDoc in a "last call" patchset. http://codereview.appspot.com/912042/diff/6001/7002 ...
3 years, 11 months ago #5
t.broyer
Factored out a CodeGenerator interface, Plugin now has only static methods
3 years, 11 months ago #6
t.broyer
Next patchset will add unit test too. http://codereview.appspot.com/912042/diff/22001/23001 File java/protoc-gen-plugin.bat.tmpl (right): http://codereview.appspot.com/912042/diff/22001/23001#newcode11 java/protoc-gen-plugin.bat.tmpl:11: Oops! just ...
3 years, 11 months ago #7
kenton
I've CC'd Gregory Kick, the Maven expert. Greg, this patch is contributing a library for ...
3 years, 11 months ago #8
t.broyer
The OutputDirectory->Context move looks good, except for the "ListParsedFiles" method return type (see comments in ...
3 years, 11 months ago #9
t.broyer
http://codereview.appspot.com/912042/diff/22001/23003 File java/src/main/java/com/google/protobuf/compiler/CodeGenerator.java (right): http://codereview.appspot.com/912042/diff/22001/23003#newcode9 java/src/main/java/com/google/protobuf/compiler/CodeGenerator.java:9: public interface OutputDirectory { On 2010/05/22 23:30:46, t.broyer wrote: ...
3 years, 11 months ago #10
t.broyer
javadoc, unit tests, Context#getParsedFiles, streaming to stdout
3 years, 11 months ago #11
t.broyer
The 4th patch: - adds javadoc - adds unit tests - renames OutputDirectory to Context ...
3 years, 11 months ago #12
kenton
Looking pretty good. http://codereview.appspot.com/912042/diff/40001/41001 File java/src/main/java/com/google/protobuf/compiler/CodeGenerator.java (right): http://codereview.appspot.com/912042/diff/40001/41001#newcode35 java/src/main/java/com/google/protobuf/compiler/CodeGenerator.java:35: * The generator's {@link CodeGenerator#generate(FileDescriptor, String, ...
3 years, 11 months ago #13
t.broyer
http://codereview.appspot.com/912042/diff/40001/41001 File java/src/main/java/com/google/protobuf/compiler/CodeGenerator.java (right): http://codereview.appspot.com/912042/diff/40001/41001#newcode35 java/src/main/java/com/google/protobuf/compiler/CodeGenerator.java:35: * The generator's {@link CodeGenerator#generate(FileDescriptor, String, Context)} On 2010/05/26 ...
3 years, 11 months ago #14
t.broyer
Few tweaks based on review
3 years, 11 months ago #15
Scott Blum
1 year, 8 months ago #16
Did this change ever get merged in?  It turns out this is pretty much 
exactly what I need for writing a Java-based plugin.

On Wednesday, April 14, 2010 6:15:30 AM UTC-4, Thomas Broyer wrote:
>
> Reviewers: kenton,
>
> Description:
> In C++, writing a code generator plugin is as easy as implementing
> CodeGenerator and passing an instance to
> google::protobuf::compiler::PluginMain; it shouldn't be any harder in
> Java (or Python BTW).
>
> This patch adds a JavaHelpers class which is just a port of
> google/protobuf/compiler/java/java_helpers.{h,cc} with a few additional
> helper methods; and the abstract Plugin class.
>
> To implement a protoc plugin in Java, simply write an implementation of
> Plugin, then create a main() method like:
>    public static void main(String[] args) {
>      new MyPlugin().run(args);
>    }
>
> The main difference with C++ is that the Java code needs to be launched
> from a shell/batch script (the patch includes a sample batch file for
> Windows), and expects that the name of the script be passed as the first
> command-line argument.
>
> The code currently lacks JavaDoc and unit tests but I'm providing it
> here for an early review.
>
> Please review this at http://codereview.appspot.com/912042/show
>
> Affected files:
>    java/protoc-gen-plugin.bat.tmpl
>    java/src/main/java/com/google/protobuf/compiler/JavaHelpers.java
>    java/src/main/java/com/google/protobuf/compiler/Plugin.java
>    src/google/protobuf/compiler/plugin.proto
>
>
>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1278:e6ce13d99bf5