Re: [protobuf] add "implements Interface" to generated Java code

2,107 views
Skip to first unread message

Jason Hsueh

unread,
Aug 22, 2012, 2:55:49 PM8/22/12
to Kiamur, prot...@googlegroups.com
I'm assuming you're aware of the previous discussions about adding interfaces to generated protobuf code...so if you still really want to do this:

You would need to change the parser to accept this: http://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/compiler/parser.cc
That means including it in the descriptor.proto definitions, which captures all definitions specified in a .proto file, and then plumbing it all the way through the Descriptor classes.

An alternative would be to add an insertion point in the Java code generator. This file defines generated message classes: http://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/compiler/java/java_message.cc
You can search for @@protoc_insertion_point to see how other insertion points are defined. This would then allow you to write a proto compiler plugin that reads a custom MessageOption with the interfaces you want to implement, and insert those interfaces. There are other insertion points available for you to actually add the methods to implement those interfaces.


On Fri, Aug 17, 2012 at 5:39 AM, Kiamur <maikritt...@gmail.com> wrote:
Hi,

I was searching the protoc source code to add the feature of generating java code with an "implements" statement. Unfortunately, I don't know exactly, where I have to add my addition.

It should work like the "package" definition in the *.proto file.

Can anybody point me to the appropriate source code locations or (even better) can provide me with source file that contain this addition? i can compile to protoc.exe myself. I'm just not abel to implement this feature myself.

Any help is much appreciated.

Maik

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/protobuf/-/TXIlp_1ThYIJ.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.

Kiamur

unread,
Aug 23, 2012, 7:37:38 AM8/23/12
to prot...@googlegroups.com, Kiamur
Hi Jason,

thanks for the hints. I will look into them.

I have not been aware of that topic being actually discussed here but I just took a look into it and I see that there are some concerns about this "feature" that I still have to understand thoroughly.

I understand that it is necessary to provide an additional file (the interface to implement) to successfully compile the protocol generated sources. Therefore I thought of that additional interface definition as optional.

I still think that it can be beneficial for my purposes and therefore I will try to write my own protoc in order to get the interface in there. Thanks again for the point into the right direction.

Maik
Reply all
Reply to author
Forward
0 new messages