Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRPC code generator needs to handle reserved words in method names #2195

Closed
carl-mastrangelo opened this issue Aug 24, 2016 · 3 comments · Fixed by #4309
Closed

gRPC code generator needs to handle reserved words in method names #2195

carl-mastrangelo opened this issue Aug 24, 2016 · 3 comments · Fixed by #4309
Assignees
Labels
Milestone

Comments

@carl-mastrangelo
Copy link
Contributor

carl-mastrangelo commented Aug 24, 2016

When defining an RPC like:

service Foo {
  rpc Import(ImportRequest) returns (ImportResponse) {};
}

The method Import gets translated to a java keyword. When should adjust it by adding an underscore (prepended?) to allow it to compile.

@ejona86
Copy link
Member

ejona86 commented Aug 24, 2016

We should probably mimic protobuf (e.g., prepend if it prepends)

@ejona86 ejona86 added the bug label Aug 25, 2016
@ejona86 ejona86 added this to the 1.1 milestone Aug 25, 2016
@ejona86 ejona86 modified the milestones: 1.2, 1.1 Jan 17, 2017
@carl-mastrangelo carl-mastrangelo modified the milestones: Next, 1.2 Mar 16, 2017
@zpencer
Copy link
Contributor

zpencer commented Apr 5, 2018

Fields always have a "_" appended, which avoids the problem:

message False {
  Native import = 1;
  string mYsTr = 2;
}
private volatile java.lang.Object mYsTr_;
private io.grpc.channelz.v1.Native import_ = null;

I notice protobuf doesn't do anything special with java reserved keywords for message types, for example this generates invalid Java:

message native { // if this is capitalized it works
}
public  final class native extends
    com.google.protobuf.GeneratedMessageV3 implements
    // @@protoc_insertion_point(message_implements:grpc.channelz.native)
    nativeOrBuilder {

@ejona86
Copy link
Member

ejona86 commented Apr 5, 2018

And methods for fields have get or set prefix, so they're also fine. Messages virtually always start with an upper-case character and keywords are all lowercase. And enums are ALL_UPPER_CASE.

@ejona86 ejona86 modified the milestones: Next, 1.12 Apr 9, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Sep 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants