Skip to content

Commit 8e793ed

Browse files
committed
feat(generator): emit ResumableUploadCallSettings on stub and service settings
1 parent 068f71f commit 8e793ed

9 files changed

Lines changed: 764 additions & 28 deletions

File tree

sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/comment/SettingsCommentComposer.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ public static CommentStatement createCallSettingsGetterComment(
130130
isMethodInternal);
131131
}
132132

133+
private static final String RESUMABLE_UPLOAD_CALL_SETTINGS_DOC_NOTE =
134+
"Note that custom retry settings and headers configured via ApiCallContext"
135+
+ " apply strictly to the initial session initiation request.";
136+
137+
public static CommentStatement createResumableUploadCallSettingsGetterComment(
138+
String javaMethodName, boolean isMethodDeprecated, boolean isMethodInternal) {
139+
return createResumableUploadCallSettingsComment(
140+
CALL_SETTINGS_METHOD_DOC_PATTERN, javaMethodName, isMethodDeprecated, isMethodInternal);
141+
}
142+
133143
public static CommentStatement createBuilderClassComment(String outerClassName) {
134144
return toCommentStatement(String.format(BUILDER_CLASS_DOC_PATTERN, outerClassName));
135145
}
@@ -140,6 +150,30 @@ public static CommentStatement createCallSettingsBuilderGetterComment(
140150
return toCommentStatement(methodComment, isMethodDeprecated, isMethodInternal);
141151
}
142152

153+
public static CommentStatement createResumableUploadCallSettingsBuilderGetterComment(
154+
String javaMethodName, boolean isMethodDeprecated, boolean isMethodInternal) {
155+
return createResumableUploadCallSettingsComment(
156+
CALL_SETTINGS_BUILDER_METHOD_DOC_PATTERN,
157+
javaMethodName,
158+
isMethodDeprecated,
159+
isMethodInternal);
160+
}
161+
162+
private static CommentStatement createResumableUploadCallSettingsComment(
163+
String pattern, String javaMethodName, boolean isMethodDeprecated, boolean isMethodInternal) {
164+
JavaDocComment.Builder docBuilder =
165+
JavaDocComment.builder()
166+
.addComment(String.format(pattern, javaMethodName))
167+
.addParagraph(RESUMABLE_UPLOAD_CALL_SETTINGS_DOC_NOTE);
168+
if (isMethodDeprecated) {
169+
docBuilder.setDeprecated(CommentComposer.DEPRECATED_METHOD_STRING);
170+
}
171+
if (isMethodInternal) {
172+
docBuilder.setInternalOnly(CommentComposer.INTERNAL_ONLY_METHOD_STRING);
173+
}
174+
return CommentStatement.withComment(docBuilder.build());
175+
}
176+
143177
public static List<CommentStatement> createClassHeaderComments(
144178
String configuredClassName,
145179
String defaultHost,

sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.api.gax.rpc.ClientSettings;
2626
import com.google.api.gax.rpc.OperationCallSettings;
2727
import com.google.api.gax.rpc.PagedCallSettings;
28+
import com.google.api.gax.rpc.ResumableUploadCallSettings;
2829
import com.google.api.gax.rpc.ServerStreamingCallSettings;
2930
import com.google.api.gax.rpc.StreamingCallSettings;
3031
import com.google.api.gax.rpc.StubSettings;
@@ -153,7 +154,7 @@ private static List<CommentStatement> createClassHeaderComments(
153154
// list.
154155
List<Method> publicMethods =
155156
service.methods().stream()
156-
.filter(m -> m.isInternalApi() == false)
157+
.filter(m -> !m.isInternalApi() && !m.isResumableUpload())
157158
.collect(Collectors.toList());
158159
Optional<Method> methodOpt =
159160
publicMethods.isEmpty()
@@ -311,12 +312,18 @@ private static List<MethodDefinition> createSettingsGetterMethods(
311312
// Add method header comment statements and annotations.
312313
private static MethodDefinition methodBuilderHelper(
313314
Method protoMethod, MethodDefinition.Builder methodBuilder, String javaMethodName) {
314-
return methodBuilder
315-
.setHeaderCommentStatements(
316-
SettingsCommentComposer.createCallSettingsGetterComment(
315+
CommentStatement commentStatement =
316+
protoMethod.isResumableUpload()
317+
? SettingsCommentComposer.createResumableUploadCallSettingsGetterComment(
318+
getMethodNameFromSettingsVarName(javaMethodName),
319+
protoMethod.isDeprecated(),
320+
protoMethod.isInternalApi())
321+
: SettingsCommentComposer.createCallSettingsGetterComment(
317322
getMethodNameFromSettingsVarName(javaMethodName),
318323
protoMethod.isDeprecated(),
319-
protoMethod.isInternalApi()))
324+
protoMethod.isInternalApi());
325+
return methodBuilder
326+
.setHeaderCommentStatements(commentStatement)
320327
.setAnnotations(createMethodAnnotations(protoMethod))
321328
.build();
322329
}
@@ -794,13 +801,19 @@ private static List<MethodDefinition> createNestedBuilderSettingsGetterMethods(
794801
String javaMethodName = String.format("%sSettings", javaStyleName);
795802
MethodDefinition.Builder methodBuilder =
796803
methodMakerFn.apply(getCallSettingsBuilderType(protoMethod, typeStore), javaMethodName);
804+
CommentStatement commentStatement =
805+
protoMethod.isResumableUpload()
806+
? SettingsCommentComposer.createResumableUploadCallSettingsBuilderGetterComment(
807+
getMethodNameFromSettingsVarName(javaMethodName),
808+
protoMethod.isDeprecated(),
809+
protoMethod.isInternalApi())
810+
: SettingsCommentComposer.createCallSettingsBuilderGetterComment(
811+
getMethodNameFromSettingsVarName(javaMethodName),
812+
protoMethod.isDeprecated(),
813+
protoMethod.isInternalApi());
797814
javaMethods.add(
798815
methodBuilder
799-
.setHeaderCommentStatements(
800-
SettingsCommentComposer.createCallSettingsBuilderGetterComment(
801-
getMethodNameFromSettingsVarName(javaMethodName),
802-
protoMethod.isDeprecated(),
803-
protoMethod.isInternalApi()))
816+
.setHeaderCommentStatements(commentStatement)
804817
.setAnnotations(createMethodAnnotations(protoMethod))
805818
.build());
806819

@@ -856,6 +869,7 @@ private static TypeStore createStaticTypes() {
856869
Operation.class,
857870
OperationCallSettings.class,
858871
PagedCallSettings.class,
872+
ResumableUploadCallSettings.class,
859873
ServerStreamingCallSettings.class,
860874
StreamingCallSettings.class,
861875
StubSettings.class,
@@ -933,7 +947,13 @@ private static TypeNode getCallSettingsTypeHelper(
933947
Method protoMethod, TypeStore typeStore, boolean isBuilder) {
934948
Class<?> callSettingsClazz =
935949
isBuilder ? UnaryCallSettings.Builder.class : UnaryCallSettings.class;
936-
if (protoMethod.isPaged()) {
950+
if (protoMethod.isResumableUpload()) {
951+
return TypeNode.withReference(
952+
ConcreteReference.withClazz(
953+
isBuilder
954+
? ResumableUploadCallSettings.Builder.class
955+
: ResumableUploadCallSettings.class));
956+
} else if (protoMethod.isPaged()) {
937957
callSettingsClazz = isBuilder ? PagedCallSettings.Builder.class : PagedCallSettings.class;
938958
} else if (protoMethod.isBatching()) {
939959
callSettingsClazz =

0 commit comments

Comments
 (0)