@@ -246,43 +246,35 @@ private StarlarkProvider(
246
246
@ Override
247
247
public StarlarkCallable .ArgumentProcessor requestArgumentProcessor (StarlarkThread thread )
248
248
throws EvalException {
249
- StarlarkCallable . ArgumentProcessor initArgumentProcessor = null ;
249
+ StarlarkInfoFactory factory = newStarlarkInfoFactory ( thread ) ;
250
250
if (init != null ) {
251
- initArgumentProcessor = Starlark .requestArgumentProcessor (thread , init );
251
+ StarlarkCallable .ArgumentProcessor initArgumentProcessor =
252
+ Starlark .requestArgumentProcessor (thread , init );
253
+ return new ArgumentProcessorWithInit (this , factory , initArgumentProcessor , thread );
254
+ } else {
255
+ return new RawArgumentProcessor (this , factory , thread );
252
256
}
253
- return newArgumentProcessor (this , thread , initArgumentProcessor );
254
- }
255
-
256
- private StarlarkCallable .ArgumentProcessor requestRawArgumentProcessor (
257
- StarlarkCallable owner , StarlarkThread thread ) {
258
- return newArgumentProcessor (owner , thread , null );
259
257
}
260
258
261
- private StarlarkCallable .ArgumentProcessor newArgumentProcessor (
262
- StarlarkCallable owner ,
263
- StarlarkThread thread ,
264
- StarlarkCallable .ArgumentProcessor initArgumentProcessor ) {
265
- StarlarkInfoFactory factory =
266
- schema != null
267
- ? StarlarkInfoWithSchema .newStarlarkInfoFactory (this , thread )
268
- : StarlarkInfoNoSchema .newStarlarkInfoFactory (this , thread );
269
- if (initArgumentProcessor != null ) {
270
- return new ArgumentProcessorWithInit (
271
- (StarlarkProvider ) owner , factory , initArgumentProcessor , thread );
272
- } else {
273
- return new RawArgumentProcessor (owner , factory , thread );
274
- }
259
+ private StarlarkInfoFactory newStarlarkInfoFactory (StarlarkThread thread ) {
260
+ return schema != null
261
+ ? StarlarkInfoWithSchema .newStarlarkInfoFactory (this , thread )
262
+ : StarlarkInfoNoSchema .newStarlarkInfoFactory (this , thread );
275
263
}
276
264
277
- static final class ArgumentProcessorWithInit extends RawArgumentProcessor {
265
+ static final class ArgumentProcessorWithInit extends StarlarkCallable .ArgumentProcessor {
266
+ private final StarlarkProvider owner ;
267
+ private final StarlarkProvider .StarlarkInfoFactory factory ;
278
268
private final StarlarkCallable .ArgumentProcessor initArgumentProcessor ;
279
269
280
270
ArgumentProcessorWithInit (
281
271
StarlarkProvider owner ,
282
272
StarlarkProvider .StarlarkInfoFactory factory ,
283
273
StarlarkCallable .ArgumentProcessor initArgumentProcessor ,
284
274
StarlarkThread thread ) {
285
- super (owner , factory , thread );
275
+ super (thread );
276
+ this .owner = owner ;
277
+ this .factory = factory ;
286
278
this .initArgumentProcessor = initArgumentProcessor ;
287
279
}
288
280
@@ -296,20 +288,28 @@ public void addNamedArg(String name, Object value) throws EvalException {
296
288
initArgumentProcessor .addNamedArg (name , value );
297
289
}
298
290
291
+ @ Override
292
+ public StarlarkCallable getCallable () {
293
+ return owner ;
294
+ }
295
+
299
296
@ Override
300
297
public Object call (StarlarkThread thread ) throws EvalException , InterruptedException {
301
298
Object initResult =
302
- Starlark .callViaArgumentProcessor (
303
- thread , ((StarlarkProvider ) owner ).init , initArgumentProcessor );
299
+ Starlark .callViaArgumentProcessor (thread , owner .init , initArgumentProcessor );
304
300
Dict <String , Object > kwargs =
305
301
Dict .cast (initResult , String .class , Object .class , "return value of provider init()" );
306
302
return factory .createFromMap (kwargs , thread );
307
303
}
308
304
}
309
305
306
+ /**
307
+ * A {@link RawArgumentProcessor} is used for calling two different types of StarlarkCallable:
308
+ * StarlarkProvider in case it doesn't have an init function, and RawConstructor.
309
+ */
310
310
static class RawArgumentProcessor extends StarlarkCallable .ArgumentProcessor {
311
- protected final StarlarkCallable owner ;
312
- protected final StarlarkProvider .StarlarkInfoFactory factory ;
311
+ private final StarlarkCallable owner ; // either StarlarkProvider or RawConstructor
312
+ private final StarlarkProvider .StarlarkInfoFactory factory ;
313
313
314
314
RawArgumentProcessor (
315
315
StarlarkCallable owner ,
@@ -367,7 +367,7 @@ private RawConstructor(StarlarkProvider provider) {
367
367
368
368
@ Override
369
369
public StarlarkCallable .ArgumentProcessor requestArgumentProcessor (StarlarkThread thread ) {
370
- return provider .requestRawArgumentProcessor ( this , thread );
370
+ return new RawArgumentProcessor ( this , provider .newStarlarkInfoFactory ( thread ) , thread );
371
371
}
372
372
373
373
@ Override
@@ -633,10 +633,9 @@ public boolean equals(Object obj) {
633
633
return true ;
634
634
}
635
635
636
- if (!(obj instanceof Key )) {
636
+ if (!(obj instanceof Key other )) {
637
637
return false ;
638
638
}
639
- Key other = (Key ) obj ;
640
639
return Objects .equals (this .key , other .key )
641
640
&& Objects .equals (this .exportedName , other .exportedName );
642
641
}
0 commit comments