@@ -18,28 +18,25 @@ package org.jetbrains.kotlin.load.kotlin.reflect
18
18
19
19
import org.jetbrains.kotlin.descriptors.PackagePartProvider
20
20
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
21
- import java.io.InputStream
22
21
import java.util.concurrent.ConcurrentHashMap
23
22
24
- class RuntimePackagePartProvider (val classLoader : ClassLoader ) : PackagePartProvider {
25
-
26
- val module2Mapping = ConcurrentHashMap <String , Lazy <ModuleMapping >>()
23
+ class RuntimePackagePartProvider (private val classLoader : ClassLoader ) : PackagePartProvider {
24
+ private val module2Mapping = ConcurrentHashMap <String , ModuleMapping >()
27
25
28
26
fun registerModule (moduleName : String ) {
29
- module2Mapping.putIfAbsent(moduleName, lazy {
30
- val resourceAsStream: InputStream = classLoader.getResourceAsStream(" META-INF/$moduleName .${ModuleMapping .MAPPING_FILE_EXT } " ) ? : return @lazy ModuleMapping .create()
31
-
32
- try {
33
- return @lazy ModuleMapping .create(resourceAsStream.readBytes())
27
+ val mapping = try {
28
+ classLoader.getResourceAsStream(" META-INF/$moduleName .${ModuleMapping .MAPPING_FILE_EXT } " )?.let { stream ->
29
+ ModuleMapping .create(stream.readBytes())
34
30
}
35
- catch (e: Exception ) {
36
- return @lazy ModuleMapping .create()
37
- }
38
- })
31
+ }
32
+ catch (e: Exception ) {
33
+ // TODO: do not swallow this exception?
34
+ null
35
+ }
36
+ module2Mapping.putIfAbsent(moduleName, mapping ? : ModuleMapping .EMPTY )
39
37
}
40
38
41
-
42
39
override fun findPackageParts (packageFqName : String ): List <String > {
43
- return module2Mapping.values.map { it.value. findPackageParts(packageFqName) }.filterNotNull() .flatMap { it.parts }.distinct()
40
+ return module2Mapping.values.mapNotNull { it.findPackageParts(packageFqName) }.flatMap { it.parts }.distinct()
44
41
}
45
- }
42
+ }
0 commit comments