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

Include source comments in generated output #86

Merged
merged 1 commit into from
Nov 15, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ object GrpcCoroutinesGenerator : Generator {

private fun ProtoService.buildOuterObject(): TypeSpec =
TypeSpec.objectBuilder(outerObjectName)
.addKdoc(attachedComments)
.addAnnotation(protoFile.getGeneratedAnnotationSpec())
.addFunction(
FunSpec.builder("newStub")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ object GrpcStubExtsGenerator : Generator {

private fun ProtoMethod.buildStubClientStreamingMethod(): FunSpec =
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.receiver(protoService.asyncStubClassName)
.returns(
CommonClassNames.ClientChannels.clientStreamingCallChannel.parameterizedBy(
Expand All @@ -122,6 +123,7 @@ object GrpcStubExtsGenerator : Generator {

private fun ProtoMethod.buildStubCoroutineBidiStreamingMethod(): FunSpec =
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.receiver(protoService.asyncStubClassName)
.returns(
CommonClassNames.ClientChannels.clientBidiCallChannel.parameterizedBy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class GrpcServiceBaseImplBuilder(val context: GeneratorContext){
val delegateValName = "delegate"

TypeSpec.classBuilder(baseImplName)
.addKdoc(attachedComments)
.addModifiers(KModifier.ABSTRACT)
.addSuperinterface(CommonClassNames.bindableService)
.addSuperinterface(CommonClassNames.serviceScope)
Expand Down Expand Up @@ -115,6 +116,7 @@ class GrpcServiceBaseImplBuilder(val context: GeneratorContext){

private fun buildUnaryBaseImpl(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addModifiers(KModifier.SUSPEND, KModifier.OPEN)
.addParameter("request", requestClassName)
.returns(responseClassName)
Expand All @@ -132,6 +134,7 @@ class GrpcServiceBaseImplBuilder(val context: GeneratorContext){

private fun buildServerStreamingBaseImpl(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addModifiers(KModifier.SUSPEND, KModifier.OPEN)
.addParameter("request", requestClassName)
.addParameter(
Expand All @@ -157,6 +160,7 @@ class GrpcServiceBaseImplBuilder(val context: GeneratorContext){

private fun buildClientStreamingBaseImpl(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addModifiers(KModifier.SUSPEND, KModifier.OPEN)
.addParameter(
name = "requestChannel",
Expand All @@ -177,6 +181,7 @@ class GrpcServiceBaseImplBuilder(val context: GeneratorContext){

private fun buildBidiStreamingBaseImpl(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addModifiers(KModifier.SUSPEND, KModifier.OPEN)
.addParameter(
name = "requestChannel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ package com.github.marcoferrer.krotoplus.generators.builders
import com.github.marcoferrer.krotoplus.generators.GeneratorContext
import com.github.marcoferrer.krotoplus.proto.ProtoMethod
import com.github.marcoferrer.krotoplus.proto.ProtoService
import com.github.marcoferrer.krotoplus.proto.getFieldClassName
import com.github.marcoferrer.krotoplus.utils.CommonClassNames
import com.github.marcoferrer.krotoplus.utils.addForEach
import com.github.marcoferrer.krotoplus.utils.builderLambdaTypeName
import com.github.marcoferrer.krotoplus.utils.requestParamSpec
import com.github.marcoferrer.krotoplus.utils.requestValueBuilderCodeBlock
import com.github.marcoferrer.krotoplus.utils.requestValueMethodSigCodeBlock
import com.github.marcoferrer.krotoplus.utils.toUpperCamelCase
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.ParameterSpec
Expand All @@ -39,13 +36,13 @@ import io.grpc.MethodDescriptor

class GrpcStubBuilder(val context: GeneratorContext){


fun buildStub(protoService: ProtoService): TypeSpec = with(protoService) {

val paramNameChannel = "channel"
val paramNameCallOptions = "callOptions"

TypeSpec.classBuilder(stubName)
.addKdoc(attachedComments)
.superclass(CommonClassNames.grpcAbstractStub.parameterizedBy(stubClassName))
.addSuperclassConstructorParameter(paramNameChannel)
.addSuperclassConstructorParameter(paramNameCallOptions)
Expand Down Expand Up @@ -77,7 +74,7 @@ class GrpcStubBuilder(val context: GeneratorContext){
.build()
}

fun TypeSpec.Builder.addRpcMethods(service: ProtoService): TypeSpec.Builder = apply {
private fun TypeSpec.Builder.addRpcMethods(service: ProtoService): TypeSpec.Builder = apply {

for(method in service.methodDefinitions) when(method.type){
MethodDescriptor.MethodType.UNARY -> {
Expand All @@ -102,11 +99,10 @@ class GrpcStubBuilder(val context: GeneratorContext){
}
}

// Default method

private fun buildUnaryMethod(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addModifiers(KModifier.SUSPEND)
.addKdoc(attachedComments)
.returns(responseClassName)
.addParameter(requestClassName.requestParamSpec)
.addStatement(
Expand All @@ -120,6 +116,7 @@ class GrpcStubBuilder(val context: GeneratorContext){

private fun buildServerStreamingMethod(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.returns(CommonClassNames.receiveChannel.parameterizedBy(responseClassName))
.addParameter(requestClassName.requestParamSpec)
.addStatement(
Expand All @@ -133,6 +130,7 @@ class GrpcStubBuilder(val context: GeneratorContext){

private fun buildClientStreamingMethod(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.returns(
CommonClassNames.ClientChannels.clientStreamingCallChannel.parameterizedBy(
requestClassName,
Expand All @@ -150,6 +148,7 @@ class GrpcStubBuilder(val context: GeneratorContext){

private fun buildBidiStreamingMethod(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.returns(
CommonClassNames.ClientChannels.clientBidiCallChannel.parameterizedBy(
requestClassName,
Expand All @@ -169,6 +168,7 @@ class GrpcStubBuilder(val context: GeneratorContext){

private fun buildUnaryLambdaOverload(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addModifiers(KModifier.SUSPEND, KModifier.INLINE)
.returns(responseClassName)
.addParameter("block", requestClassName.builderLambdaTypeName)
Expand All @@ -179,6 +179,7 @@ class GrpcStubBuilder(val context: GeneratorContext){

private fun buildServerStreamingLambdaOverload(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addModifiers(KModifier.INLINE)
.returns(CommonClassNames.receiveChannel.parameterizedBy(responseClassName))
.addParameter("block", requestClassName.builderLambdaTypeName)
Expand All @@ -192,6 +193,7 @@ class GrpcStubBuilder(val context: GeneratorContext){
private fun buildUnaryMethodSigOverload(protoMethod: ProtoMethod): FunSpec? = with(protoMethod){
if(methodSignatureFields.isEmpty())
null else FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addModifiers(KModifier.SUSPEND)
.returns(responseClassName)
.addMethodSignatureParameter(methodSignatureFields,context.schema)
Expand All @@ -203,6 +205,7 @@ class GrpcStubBuilder(val context: GeneratorContext){
private fun buildServerStreamingMethodSigOverload(protoMethod: ProtoMethod): FunSpec? = with(protoMethod){
if(methodSignatureFields.isEmpty())
null else FunSpec.builder(functionName)
.addKdoc(attachedComments)
.returns(CommonClassNames.receiveChannel.parameterizedBy(responseClassName))
.addMethodSignatureParameter(methodSignatureFields,context.schema)
.addCode(requestClassName.requestValueMethodSigCodeBlock(methodSignatureFields))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class ServerStreamingStubExtsBuilder(val context: GeneratorContext){

private fun buildCoroutineExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.returns(CommonClassNames.receiveChannel.parameterizedBy(responseClassName))
.receiver(protoService.asyncStubClassName)
.addParameter(requestClassName.requestParamSpec)
Expand All @@ -85,6 +86,7 @@ class ServerStreamingStubExtsBuilder(val context: GeneratorContext){

private fun buildAsyncMethodSigExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.receiver(protoService.asyncStubClassName)
.returns(UNIT)
.addMethodSignatureParameter(methodSignatureFields, context.schema)
Expand All @@ -96,6 +98,7 @@ class ServerStreamingStubExtsBuilder(val context: GeneratorContext){

private fun buildCoroutineMethodSigExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.receiver(protoService.asyncStubClassName)
.addMethodSignatureParameter(methodSignatureFields, context.schema)
.returns(CommonClassNames.receiveChannel.parameterizedBy(responseClassName))
Expand All @@ -106,6 +109,7 @@ class ServerStreamingStubExtsBuilder(val context: GeneratorContext){

private fun buildBlockingMethodSigExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.receiver(protoService.blockingStubClassName)
.addMethodSignatureParameter(methodSignatureFields, context.schema)
.returns(Iterator::class.asClassName().parameterizedBy(responseClassName))
Expand All @@ -118,6 +122,7 @@ class ServerStreamingStubExtsBuilder(val context: GeneratorContext){

private fun buildAsyncLambdaBuilderExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addModifiers(KModifier.INLINE)
.receiver(protoService.asyncStubClassName)
.addResponseObserverParameter(responseClassName)
Expand All @@ -130,6 +135,7 @@ class ServerStreamingStubExtsBuilder(val context: GeneratorContext){

private fun buildCoroutineLambdaBuilderExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.receiver(protoService.asyncStubClassName)
.returns(CommonClassNames.receiveChannel.parameterizedBy(responseClassName))
.addModifiers(KModifier.INLINE)
Expand All @@ -141,6 +147,7 @@ class ServerStreamingStubExtsBuilder(val context: GeneratorContext){

private fun buildBlockingLambdaBuilderExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addModifiers(KModifier.INLINE)
.receiver(protoService.blockingStubClassName)
.addParameter("block", requestClassName.builderLambdaTypeName)
Expand All @@ -154,6 +161,7 @@ class ServerStreamingStubExtsBuilder(val context: GeneratorContext){

private fun buildAsyncDefaultArgExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.receiver(protoService.asyncStubClassName)
.addResponseObserverParameter(responseClassName)
.returns(UNIT)
Expand All @@ -163,6 +171,7 @@ class ServerStreamingStubExtsBuilder(val context: GeneratorContext){

private fun buildBlockingDefaultArgExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.receiver(protoService.blockingStubClassName)
.returns(Iterator::class.asClassName().parameterizedBy(responseClassName))
.addStatement("return %N(%T.getDefaultInstance())", functionName, requestClassName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class UnaryStubExtsBuilder(val context: GeneratorContext){

private fun buildCoroutineExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addModifiers(KModifier.SUSPEND)
.receiver(protoService.asyncStubClassName)
.addParameter(requestClassName.requestParamSpec)
Expand All @@ -88,6 +89,7 @@ class UnaryStubExtsBuilder(val context: GeneratorContext){

private fun buildAsyncMethodSigExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.receiver(protoService.asyncStubClassName)
.addMethodSignatureParameter(methodSignatureFields, context.schema)
.addResponseObserverParameter(responseClassName)
Expand All @@ -99,6 +101,7 @@ class UnaryStubExtsBuilder(val context: GeneratorContext){

private fun buildCoroutineMethodSigExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addModifiers(KModifier.SUSPEND)
.receiver(protoService.asyncStubClassName)
.returns(responseClassName)
Expand All @@ -110,6 +113,7 @@ class UnaryStubExtsBuilder(val context: GeneratorContext){

private fun buildFutureMethodSigExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.receiver(protoService.futureStubClassName)
.addMethodSignatureParameter(methodSignatureFields, context.schema)
.returns(CommonClassNames.listenableFuture.parameterizedBy(responseClassName))
Expand All @@ -120,6 +124,7 @@ class UnaryStubExtsBuilder(val context: GeneratorContext){

private fun buildBlockingMethodSigExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.receiver(protoService.blockingStubClassName)
.returns(responseClassName)
.addMethodSignatureParameter(methodSignatureFields, context.schema)
Expand All @@ -132,6 +137,7 @@ class UnaryStubExtsBuilder(val context: GeneratorContext){

private fun buildAsyncLambdaBuilderExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.receiver(protoService.asyncStubClassName)
.addModifiers(KModifier.INLINE)
.addResponseObserverParameter(responseClassName)
Expand All @@ -144,6 +150,7 @@ class UnaryStubExtsBuilder(val context: GeneratorContext){

private fun buildCoroutineLambdaBuilderExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.receiver(protoService.asyncStubClassName)
.addModifiers(KModifier.INLINE, KModifier.SUSPEND)
.addParameter("block", requestClassName.builderLambdaTypeName)
Expand All @@ -155,6 +162,7 @@ class UnaryStubExtsBuilder(val context: GeneratorContext){

private fun buildFutureLambdaBuilderExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addModifiers(KModifier.INLINE)
.receiver(protoService.futureStubClassName)
.addParameter("block", requestClassName.builderLambdaTypeName)
Expand All @@ -166,6 +174,7 @@ class UnaryStubExtsBuilder(val context: GeneratorContext){

private fun buildBlockingLambdaBuilderExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addModifiers(KModifier.INLINE)
.addCode(requestClassName.requestValueBuilderCodeBlock)
.addParameter("block", requestClassName.builderLambdaTypeName)
Expand All @@ -179,6 +188,7 @@ class UnaryStubExtsBuilder(val context: GeneratorContext){

private fun buildAsyncDefaultArgExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.receiver(protoService.asyncStubClassName)
.addResponseObserverParameter(responseClassName)
.addStatement("%N(%T.getDefaultInstance(),responseObserver)", functionName, requestClassName)
Expand All @@ -188,6 +198,7 @@ class UnaryStubExtsBuilder(val context: GeneratorContext){

private fun buildFutureDefaultArgExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addStatement("return %N(%T.getDefaultInstance())", functionName, requestClassName)
.receiver(protoService.futureStubClassName)
.returns(CommonClassNames.listenableFuture.parameterizedBy(responseClassName))
Expand All @@ -196,6 +207,7 @@ class UnaryStubExtsBuilder(val context: GeneratorContext){

private fun buildBlockingDefaultArgExt(protoMethod: ProtoMethod): FunSpec = with(protoMethod){
FunSpec.builder(functionName)
.addKdoc(attachedComments)
.addStatement("return %N(%T.getDefaultInstance())", functionName, requestClassName)
.receiver(protoService.blockingStubClassName)
.returns(responseClassName)
Expand Down
Loading