@@ -18,15 +18,22 @@ import org.jetbrains.kotlinx.jupyter.config.getLogger
18
18
import org.jetbrains.kotlinx.jupyter.exceptions.ReplException
19
19
import org.jetbrains.kotlinx.jupyter.util.AcceptanceRule
20
20
import org.jetbrains.kotlinx.jupyter.util.accepts
21
+ import org.jetbrains.kotlinx.jupyter.util.unionAcceptance
21
22
22
23
class LibrariesScanner (val notebook : Notebook ) {
23
24
private val processedFQNs = mutableSetOf<TypeName >()
24
25
private val discardedFQNs = mutableSetOf<TypeName >()
25
26
26
- private fun <T , I : LibrariesInstantiable <T >> Iterable<I>.filterNamesToLoad (host : KotlinKernelHost ): List <I > {
27
+ private fun <I : LibrariesInstantiable <* >> Iterable<I>.filterNamesToLoad (
28
+ host : KotlinKernelHost ,
29
+ integrationTypeNameRules : Iterable <AcceptanceRule <TypeName >>,
30
+ ): List <I > {
27
31
return filter {
28
32
val typeName = it.fqn
29
- val acceptance = host.acceptsIntegrationTypeName(typeName)
33
+ val acceptance = unionAcceptance(
34
+ host.acceptsIntegrationTypeName(typeName),
35
+ integrationTypeNameRules.accepts(typeName)
36
+ )
30
37
log.debug(" Acceptance result for $typeName : $acceptance " )
31
38
when (acceptance) {
32
39
true -> processedFQNs.add(typeName)
@@ -57,20 +64,15 @@ class LibrariesScanner(val notebook: Notebook) {
57
64
val producers = mutableListOf<LibrariesProducerDeclaration >()
58
65
59
66
for (result in results) {
60
- for (definition in result.definitions) {
61
- if (integrationTypeNameRules.accepts(definition.fqn) != false )
62
- definitions + = definition
63
- }
64
-
65
- for (producer in result.producers) {
66
- if (integrationTypeNameRules.accepts(producer.fqn) != false )
67
- producers + = producer
68
- }
67
+ definitions.addAll(result.definitions)
68
+ producers.addAll(result.producers)
69
69
}
70
70
71
+ fun <I : LibrariesInstantiable <* >> Iterable<I>.filterNames () = filterNamesToLoad(host, integrationTypeNameRules)
72
+
71
73
return LibrariesScanResult (
72
- definitions.filterNamesToLoad(host ),
73
- producers.filterNamesToLoad(host ),
74
+ definitions.filterNames( ),
75
+ producers.filterNames( ),
74
76
)
75
77
}
76
78
0 commit comments