4141import com .google .api .generator .gapic .model .GapicClass ;
4242import com .google .api .generator .gapic .model .GapicClass .Kind ;
4343import com .google .api .generator .gapic .model .GapicContext ;
44- import com .google .api .generator .gapic .model .Method ;
4544import com .google .api .generator .gapic .model .Service ;
4645import java .util .ArrayList ;
4746import java .util .Arrays ;
@@ -63,19 +62,13 @@ protected TransportContext getTransportContext() {
6362
6463 @ Override
6564 public GapicClass generate (GapicContext context , Service service ) {
66- TypeStore typeStore = createTypes ();
65+ TypeStore typeStore = createTypes (service );
66+
6767 String className =
6868 getTransportContext ().classNames ().getTransportServiceCallableFactoryClassName (service );
6969 GapicClass .Kind kind = Kind .STUB ;
7070 String pakkage = String .format ("%s.stub" , service .pakkage ());
7171
72- String operationService = "" ;
73- for (Method method : service .methods ()) {
74- if (method .operationService () != null ) {
75- operationService = method .operationService ();
76- }
77- }
78-
7972 StubCommentComposer commentComposer =
8073 new StubCommentComposer (getTransportContext ().transportName ());
8174 ClassDefinition classDef =
@@ -85,9 +78,9 @@ public GapicClass generate(GapicContext context, Service service) {
8578 commentComposer .createTransportServiceCallableFactoryClassHeaderComments (
8679 service .name (), service .isDeprecated ()))
8780 .setAnnotations (createClassAnnotations (service , typeStore ))
88- .setImplementsTypes (createClassImplements (typeStore ))
81+ .setImplementsTypes (createClassImplements (typeStore , service ))
8982 .setName (className )
90- .setMethods (createClassMethods (typeStore , operationService ))
83+ .setMethods (createClassMethods (service , typeStore ))
9184 .setScope (ScopeNode .PUBLIC )
9285 .build ();
9386 return GapicClass .create (kind , classDef );
@@ -118,22 +111,23 @@ protected List<AnnotationNode> createClassAnnotations(Service service, TypeStore
118111 * @return {@code TypeNode} containing the interface to be implemented by the generated callable
119112 * factory class.
120113 */
121- protected abstract List <TypeNode > createClassImplements (TypeStore typeStore );
114+ protected abstract List <TypeNode > createClassImplements (TypeStore typeStore , Service service );
122115
123- protected List <MethodDefinition > createClassMethods (TypeStore typeStore , String operationService ) {
116+ protected List <MethodDefinition > createClassMethods (Service service , TypeStore typeStore ) {
124117 return Arrays .asList (
125- createUnaryCallableMethod (typeStore ),
126- createPagedCallableMethod (typeStore ),
127- createBatchingCallableMethod (typeStore ),
128- createOperationCallableMethod (typeStore , operationService ));
118+ createUnaryCallableMethod (service , typeStore ),
119+ createPagedCallableMethod (service , typeStore ),
120+ createBatchingCallableMethod (service , typeStore ),
121+ createOperationCallableMethod (service , typeStore ));
129122 }
130123
131- protected MethodDefinition createUnaryCallableMethod (TypeStore typeStore ) {
124+ protected MethodDefinition createUnaryCallableMethod (Service service , TypeStore typeStore ) {
132125 String methodVariantName = "Unary" ;
133126 String requestTemplateName = "RequestT" ;
134127 String responseTemplateName = "ResponseT" ;
135128 List <String > methodTemplateNames = Arrays .asList (requestTemplateName , responseTemplateName );
136129 return createGenericCallableMethod (
130+ service ,
137131 typeStore ,
138132 /*methodTemplateNames=*/ methodTemplateNames ,
139133 /*returnCallableKindName=*/ methodVariantName ,
@@ -148,14 +142,15 @@ protected MethodDefinition createUnaryCallableMethod(TypeStore typeStore) {
148142 .collect (Collectors .toList ()));
149143 }
150144
151- protected MethodDefinition createPagedCallableMethod (TypeStore typeStore ) {
145+ protected MethodDefinition createPagedCallableMethod (Service service , TypeStore typeStore ) {
152146 String methodVariantName = "Paged" ;
153147 String requestTemplateName = "RequestT" ;
154148 String pagedResponseTemplateName = "PagedListResponseT" ;
155149 String responseTemplateName = "ResponseT" ;
156150 List <String > methodTemplateNames =
157151 Arrays .asList (requestTemplateName , responseTemplateName , pagedResponseTemplateName );
158152 return createGenericCallableMethod (
153+ service ,
159154 typeStore ,
160155 /*methodTemplateNames=*/ methodTemplateNames ,
161156 /*returnCallableKindName=*/ "Unary" ,
@@ -170,12 +165,13 @@ protected MethodDefinition createPagedCallableMethod(TypeStore typeStore) {
170165 .collect (Collectors .toList ()));
171166 }
172167
173- protected MethodDefinition createBatchingCallableMethod (TypeStore typeStore ) {
168+ protected MethodDefinition createBatchingCallableMethod (Service service , TypeStore typeStore ) {
174169 String methodVariantName = "Batching" ;
175170 String requestTemplateName = "RequestT" ;
176171 String responseTemplateName = "ResponseT" ;
177172 List <String > methodTemplateNames = Arrays .asList (requestTemplateName , responseTemplateName );
178173 return createGenericCallableMethod (
174+ service ,
179175 typeStore ,
180176 /*methodTemplateNames=*/ methodTemplateNames ,
181177 /*returnCallableKindName=*/ "Unary" ,
@@ -190,9 +186,11 @@ protected MethodDefinition createBatchingCallableMethod(TypeStore typeStore) {
190186 .collect (Collectors .toList ()));
191187 }
192188
193- protected abstract MethodDefinition createOperationCallableMethod (TypeStore typeStore , String operationService );
189+ protected abstract MethodDefinition createOperationCallableMethod (
190+ Service service , TypeStore typeStore );
194191
195192 protected MethodDefinition createGenericCallableMethod (
193+ Service service ,
196194 TypeStore typeStore ,
197195 List <String > methodTemplateNames ,
198196 String returnCallableKindName ,
@@ -202,6 +200,7 @@ protected MethodDefinition createGenericCallableMethod(
202200 String callSettingsVariantName ,
203201 List <Object > callSettingsTemplateObjects ) {
204202 return createGenericCallableMethod (
203+ service ,
205204 typeStore ,
206205 methodTemplateNames ,
207206 returnCallableKindName ,
@@ -214,6 +213,7 @@ protected MethodDefinition createGenericCallableMethod(
214213 }
215214
216215 protected MethodDefinition createGenericCallableMethod (
216+ Service service ,
217217 TypeStore typeStore ,
218218 List <String > methodTemplateNames ,
219219 String returnCallableKindName ,
@@ -265,7 +265,7 @@ protected MethodDefinition createGenericCallableMethod(
265265 .setVariable (
266266 Variable .builder ()
267267 .setName ("operationsStub" )
268- .setType (getTransportContext (). operationsStubType ( ))
268+ .setType (getOperationsStubType ( service ))
269269 .build ())
270270 .setIsDecl (true )
271271 .build ());
@@ -296,7 +296,16 @@ protected MethodDefinition createGenericCallableMethod(
296296 .build ();
297297 }
298298
299- private static TypeStore createTypes () {
299+ protected TypeNode getOperationsStubType (Service service ) {
300+ TypeNode opeationsStubType = service .operationServiceStubType ();
301+ if (opeationsStubType == null ) {
302+ opeationsStubType = getTransportContext ().operationsStubType ();
303+ }
304+ return opeationsStubType ;
305+ }
306+
307+
308+ private TypeStore createTypes (Service service ) {
300309 List <Class > concreteClazzes =
301310 Arrays .asList (
302311 // Gax-java classes.
0 commit comments