@@ -61,12 +61,13 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
61
61
private fun resolveParams (
62
62
context : Context ,
63
63
element : AstElement ,
64
+ scope : AstType ? ,
64
65
params : List <AstParam >,
65
66
): Map <String , TypeResultRef > {
66
67
return if (params.any { it.isAssisted() }) {
67
- resolveParamsNew(context, element, params)
68
+ resolveParamsNew(context, element, scope, params)
68
69
} else {
69
- resolveParamsLegacy(context, element, params)
70
+ resolveParamsLegacy(context, element, scope, params)
70
71
}
71
72
}
72
73
@@ -75,12 +76,12 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
75
76
private fun resolveParamsNew (
76
77
context : Context ,
77
78
element : AstElement ,
79
+ scope : AstType ? ,
78
80
params : List <AstParam >,
79
81
): Map <String , TypeResultRef > {
80
- if (context.scopeComponent != null ) {
81
- val scopeType = context.scopeComponent.scopeType(options)
82
+ if (scope != null ) {
82
83
throw FailedToGenerateException (
83
- " Cannot apply scope: @${scopeType !! .simpleName} to type with @Assisted parameters: [${
84
+ " Cannot apply scope: @${scope .simpleName} to type with @Assisted parameters: [${
84
85
params.filter { it.isAssisted() }.joinToString()
85
86
} ]"
86
87
)
@@ -137,6 +138,7 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
137
138
private fun resolveParamsLegacy (
138
139
context : Context ,
139
140
element : AstElement ,
141
+ scope : AstType ? ,
140
142
params : List <AstParam >,
141
143
): Map <String , TypeResultRef > {
142
144
val size = params.size
@@ -171,10 +173,9 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
171
173
""" .trimIndent(),
172
174
element
173
175
)
174
- if (context.scopeComponent != null ) {
175
- val scopeType = context.scopeComponent.scopeType(options)
176
+ if (scope != null ) {
176
177
throw FailedToGenerateException (
177
- " Cannot apply scope: @${scopeType !! .simpleName} to type with assisted parameters: [${
178
+ " Cannot apply scope: @${scope .simpleName} to type with @Assisted parameters: [${
178
179
resolvedImplicitly.joinToString()
179
180
} ]"
180
181
)
@@ -199,6 +200,7 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
199
200
context = withTypes(types),
200
201
accessor = method.accessor,
201
202
method = method.method,
203
+ scope = null ,
202
204
key = key,
203
205
)
204
206
}
@@ -255,6 +257,7 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
255
257
context = this ,
256
258
accessor = creator.accessor,
257
259
method = creator.method,
260
+ scope = creator.scope,
258
261
key = key,
259
262
)
260
263
}
@@ -270,7 +273,7 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
270
273
creator = containerKey.creator,
271
274
args = args,
272
275
mapArg = { key, arg, types ->
273
- Provides (withTypes(types), arg.accessor, arg.method, key)
276
+ Provides (withTypes(types), arg.accessor, arg.method, arg.scope, key)
274
277
}
275
278
)
276
279
}
@@ -284,7 +287,7 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
284
287
args = args,
285
288
mapArg = { key, arg, types ->
286
289
Function (withTypes(types), args = innerType.arguments.dropLast(1 )) { context ->
287
- TypeResultRef (key, Provides (context, arg.accessor, arg.method, key))
290
+ TypeResultRef (key, Provides (context, arg.accessor, arg.method, arg.scope, key))
288
291
}
289
292
}
290
293
)
@@ -299,7 +302,7 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
299
302
args = args,
300
303
mapArg = { key, arg, types ->
301
304
Lazy (key) {
302
- TypeResultRef (key, Provides (withTypes(types), arg.accessor, arg.method, key))
305
+ TypeResultRef (key, Provides (withTypes(types), arg.accessor, arg.method, arg.scope, key))
303
306
}
304
307
}
305
308
)
@@ -316,7 +319,7 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
316
319
creator = containerKey.creator,
317
320
args = args,
318
321
mapArg = { key, arg, types ->
319
- Provides (withTypes(types), arg.accessor, arg.method, key)
322
+ Provides (withTypes(types), arg.accessor, arg.method, arg.scope, key)
320
323
}
321
324
)
322
325
}
@@ -376,6 +379,7 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
376
379
Constructor (
377
380
context = this ,
378
381
constructor = injectCtor,
382
+ scope = scope,
379
383
key = key,
380
384
)
381
385
}
@@ -406,6 +410,7 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
406
410
context : Context ,
407
411
accessor : Accessor ,
408
412
method : AstMember ,
413
+ scope : AstType ? ,
409
414
key : TypeKey ,
410
415
) = withCycleDetection(key, method) {
411
416
TypeResult .Provides (
@@ -418,7 +423,7 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
418
423
},
419
424
isProperty = method is AstProperty ,
420
425
parameters = (method as ? AstFunction )?.let {
421
- resolveParams(context, method, it.parameters)
426
+ resolveParams(context, method, scope, it.parameters)
422
427
} ? : emptyMap(),
423
428
)
424
429
}
@@ -435,14 +440,19 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
435
440
result = resolve(context.withoutScoped(key.type, scopedComponent), element, key)
436
441
)
437
442
438
- private fun Constructor (context : Context , constructor : AstConstructor , key : TypeKey ) =
439
- withCycleDetection(key, constructor ) {
440
- TypeResult .Constructor (
441
- type = constructor .type,
442
- parameters = resolveParams(context, constructor , constructor .parameters),
443
- supportsNamedArguments = constructor .supportsNamedArguments
444
- )
445
- }
443
+ private fun Constructor (
444
+ context : Context ,
445
+ constructor : AstConstructor ,
446
+ scope : AstType ? ,
447
+ key : TypeKey
448
+ ) = withCycleDetection(key, constructor ) {
449
+ TypeResult .Constructor (
450
+ type = constructor .type,
451
+ scope = scope,
452
+ parameters = resolveParams(context, constructor , scope, constructor .parameters),
453
+ supportsNamedArguments = constructor .supportsNamedArguments
454
+ )
455
+ }
446
456
447
457
private fun Container (
448
458
creator : String ,
@@ -492,7 +502,12 @@ class TypeResultResolver(private val provider: AstProvider, private val options:
492
502
TypeResult .NamedFunction (
493
503
name = function.toMemberName(),
494
504
args = namedArgs.map { it.second },
495
- parameters = resolveParams(context.withArgs(namedArgs), function, function.parameters),
505
+ parameters = resolveParams(
506
+ context = context.withArgs(namedArgs),
507
+ element = function,
508
+ scope = null ,
509
+ params = function.parameters
510
+ ),
496
511
)
497
512
}
498
513
0 commit comments