Skip to content

Commit

Permalink
Add generated notice for clients
Browse files Browse the repository at this point in the history
  • Loading branch information
Duzhinsky committed Sep 5, 2023
1 parent f98512f commit 1ca13af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

public class BaseGrpcClient {

public static final String modificationNotice = """
The client was generated by protogen. If you want to add some logic, mark the service using
`option (protogen.abstract) = true;` and make your own class.
""";

public static final TypeName clazz = ClassName.get("org.sudu.api", "BaseGrpcClient");

private static final ClassName managedChannelClass = ClassName.get("io.grpc", "ManagedChannel");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.sudu.protogen.generator.client;

import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeSpec;
import com.squareup.javapoet.*;
import org.sudu.protogen.descriptors.Method;
import org.sudu.protogen.descriptors.Service;
import org.sudu.protogen.generator.GenerationContext;

import javax.annotation.processing.Generated;
import javax.lang.model.element.Modifier;
import java.util.stream.Stream;

Expand All @@ -34,6 +32,7 @@ public TypeSpec generate() {
.addModifiers(Modifier.PUBLIC)
.superclass(BaseGrpcClient.clazz)
.addField(stubField)
.addAnnotation(AnnotationSpec.builder(ClassName.get(Generated.class)).addMember("value", CodeBlock.of("\"protogen\"")).build())
.addMethods(BaseGrpcClient.generateConstructors(constructorsBody))
.addMethods(service.getMethods().stream()
.filter(Method::doGenerate)
Expand All @@ -42,6 +41,8 @@ public TypeSpec generate() {
);
if (service.isAbstract()) {
builder.addModifiers(Modifier.ABSTRACT);
} else {
builder.addJavadoc(CodeBlock.of(BaseGrpcClient.modificationNotice));
}
return builder.build();
}
Expand Down

0 comments on commit 1ca13af

Please sign in to comment.