Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions codegen/src/main/scala/akka/grpc/gen/javadsl/Method.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ final case class Method(
comment: Option[String] = None) {
import Method._

require(
!ReservedWords.contains(name),
s"The method name `$name` is a reserved word in Java, please change it in your proto")

def deserializer = Serializer(inputType)
def serializer = Serializer(outputType)

Expand Down Expand Up @@ -92,4 +96,57 @@ object Method {
(if (packageName.isEmpty) "" else packageName + ".") + name
}

// https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html
private val ReservedWords = Set(
"abstract",
"continue",
"for",
"new",
"switch",
"assert",
"default",
"goto",
"package",
"synchronized",
"boolean",
"do",
"if",
"private",
"this",
"break",
"double",
"implements",
"protected",
"throw",
"byte",
"else",
"import",
"public",
"throws",
"case",
"enum",
"instanceof",
"return",
"transient",
"catch",
"extends",
"int",
"short",
"try",
"char",
"final",
"interface",
"static",
"void",
"class",
"finally",
"long",
"strictfp",
"volatile",
"const",
"float",
"native",
"super",
"while")

}
4 changes: 2 additions & 2 deletions codegen/src/main/scala/akka/grpc/gen/scaladsl/Method.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ case class Method(
}

val nameSafe: String =
if (reservedWords.contains(name)) s"""`$name`"""
if (ReservedWords.contains(name)) s"""`$name`"""
else name

}
Expand All @@ -77,7 +77,7 @@ object Method {
}

// https://github.com/scalapb/ScalaPB/blob/master/compiler-plugin/src/main/scala/scalapb/compiler/DescriptorImplicits.scala#L1038
private val reservedWords = Set(
private val ReservedWords = Set(
"abstract",
"case",
"catch",
Expand Down
10 changes: 10 additions & 0 deletions sbt-plugin/src/sbt-test/gen-java/04-crash-on-keywords/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resolvers += Resolver.sonatypeRepo("staging")
resolvers += Resolver.bintrayRepo("akka", "snapshots")

enablePlugins(AkkaGrpcPlugin)

javacOptions += "-Xdoclint:all"

akkaGrpcGeneratedLanguages := Seq(AkkaGrpc.Java)

Compile / PB.protocOptions += "--include_std_types"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % sys.props("project.version"))

addSbtPlugin("com.lightbend.sbt" % "sbt-javaagent" % "0.1.5")
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
syntax = "proto3";

import "google/protobuf/timestamp.proto";

option java_multiple_files = true;
option java_package = "example.myapp.helloworld.grpc";
option java_outer_classname = "HelloWorldProto";

package helloworld;

// The greeting service definition.
service GreeterService {
// Sends a greeting
rpc While (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
string name = 1;
google.protobuf.Timestamp timestamp = 2;
}

// The response message containing the greetings
message HelloReply {
string message = 1;
google.protobuf.Timestamp timestamp = 2;
}
1 change: 1 addition & 0 deletions sbt-plugin/src/sbt-test/gen-java/04-crash-on-keywords/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-> protocGenerate