From 0a70a957e946c61f1091aa27dd4655bc499bbd9b Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Mon, 24 Sep 2018 15:04:27 +0300 Subject: [PATCH] Minor. Reformat LazyJavaPackageScope.kt --- .../lazy/descriptors/LazyJavaPackageScope.kt | 92 ++++++++++--------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaPackageScope.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaPackageScope.kt index 90a19ab497c..c65b57b4612 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaPackageScope.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaPackageScope.kt @@ -37,9 +37,9 @@ import org.jetbrains.kotlin.utils.alwaysTrue import java.util.* class LazyJavaPackageScope( - c: LazyJavaResolverContext, - private val jPackage: JavaPackage, - override val ownerDescriptor: LazyJavaPackageFragment + c: LazyJavaResolverContext, + private val jPackage: JavaPackage, + override val ownerDescriptor: LazyJavaPackageFragment ) : LazyJavaStaticScope(c) { // Null means that it's impossible to determine list of class names in package, i.e. in IDE where special finders exist // But for compiler though we can determine full list of class names by getting all class-file names in classpath and sources @@ -47,48 +47,49 @@ class LazyJavaPackageScope( c.components.finder.knownClassNamesInPackage(ownerDescriptor.fqName) } - private val classes = c.storageManager.createMemoizedFunctionWithNullableValues classByRequest@{ request -> - val requestClassId = ClassId(ownerDescriptor.fqName, request.name) + private val classes = + c.storageManager.createMemoizedFunctionWithNullableValues classByRequest@{ request -> + val requestClassId = ClassId(ownerDescriptor.fqName, request.name) - val kotlinBinaryClass = - // These branches should be semantically equal, but the first one could be faster + val kotlinBinaryClass = + // These branches should be semantically equal, but the first one could be faster if (request.javaClass != null) c.components.kotlinClassFinder.findKotlinClass(request.javaClass) else c.components.kotlinClassFinder.findKotlinClass(requestClassId) - val classId = kotlinBinaryClass?.classId - // Nested/local classes can be found when running in CLI in case when request.name looks like 'Outer$Inner' - // It happens because KotlinClassFinder searches through a file-based index that does not differ classes containing $-sign and nested ones - if (classId != null && (classId.isNestedClass || classId.isLocal)) return@classByRequest null + val classId = kotlinBinaryClass?.classId + // Nested/local classes can be found when running in CLI in case when request.name looks like 'Outer$Inner' + // It happens because KotlinClassFinder searches through a file-based index that does not differ classes containing $-sign and nested ones + if (classId != null && (classId.isNestedClass || classId.isLocal)) return@classByRequest null - val kotlinResult = resolveKotlinBinaryClass(kotlinBinaryClass) + val kotlinResult = resolveKotlinBinaryClass(kotlinBinaryClass) - when (kotlinResult) { - is KotlinClassLookupResult.Found -> kotlinResult.descriptor - is KotlinClassLookupResult.SyntheticClass -> null - is KotlinClassLookupResult.NotFound -> { - val javaClass = request.javaClass ?: c.components.finder.findClass(requestClassId) + when (kotlinResult) { + is KotlinClassLookupResult.Found -> kotlinResult.descriptor + is KotlinClassLookupResult.SyntheticClass -> null + is KotlinClassLookupResult.NotFound -> { + val javaClass = request.javaClass ?: c.components.finder.findClass(requestClassId) - if (javaClass?.lightClassOriginKind == LightClassOriginKind.BINARY) { - throw IllegalStateException( + if (javaClass?.lightClassOriginKind == LightClassOriginKind.BINARY) { + throw IllegalStateException( "Couldn't find kotlin binary class for light class created by kotlin binary file\n" + - "JavaClass: $javaClass\n" + - "ClassId: $requestClassId\n" + - "findKotlinClass(JavaClass) = ${c.components.kotlinClassFinder.findKotlinClass(javaClass)}\n" + - "findKotlinClass(ClassId) = ${c.components.kotlinClassFinder.findKotlinClass(requestClassId)}\n" - ) - } + "JavaClass: $javaClass\n" + + "ClassId: $requestClassId\n" + + "findKotlinClass(JavaClass) = ${c.components.kotlinClassFinder.findKotlinClass(javaClass)}\n" + + "findKotlinClass(ClassId) = ${c.components.kotlinClassFinder.findKotlinClass(requestClassId)}\n" + ) + } - val actualFqName = javaClass?.fqName - if (actualFqName == null || actualFqName.isRoot || actualFqName.parent() != ownerDescriptor.fqName) - null - else - LazyJavaClassDescriptor(c, ownerDescriptor, javaClass) + val actualFqName = javaClass?.fqName + if (actualFqName == null || actualFqName.isRoot || actualFqName.parent() != ownerDescriptor.fqName) + null + else + LazyJavaClassDescriptor(c, ownerDescriptor, javaClass) .also(c.components.javaClassesTracker::reportClass) + } } } - } private sealed class KotlinClassLookupResult { class Found(val descriptor: ClassDescriptor) : KotlinClassLookupResult() @@ -97,19 +98,19 @@ class LazyJavaPackageScope( } private fun resolveKotlinBinaryClass(kotlinClass: KotlinJvmBinaryClass?): KotlinClassLookupResult = - when { - kotlinClass == null -> { - KotlinClassLookupResult.NotFound - } - kotlinClass.classHeader.kind == KotlinClassHeader.Kind.CLASS -> { - val descriptor = c.components.deserializedDescriptorResolver.resolveClass(kotlinClass) - if (descriptor != null) KotlinClassLookupResult.Found(descriptor) else KotlinClassLookupResult.NotFound - } - else -> { - // This is a package or interface DefaultImpls or something like that - KotlinClassLookupResult.SyntheticClass - } + when { + kotlinClass == null -> { + KotlinClassLookupResult.NotFound } + kotlinClass.classHeader.kind == KotlinClassHeader.Kind.CLASS -> { + val descriptor = c.components.deserializedDescriptorResolver.resolveClass(kotlinClass) + if (descriptor != null) KotlinClassLookupResult.Found(descriptor) else KotlinClassLookupResult.NotFound + } + else -> { + // This is a package or interface DefaultImpls or something like that + KotlinClassLookupResult.SyntheticClass + } + } // javaClass here is only for sake of optimizations private class FindClassRequest(val name: Name, val javaClass: JavaClass?) { @@ -159,7 +160,10 @@ class LazyJavaPackageScope( override fun computePropertyNames(kindFilter: DescriptorKindFilter, nameFilter: ((Name) -> Boolean)?) = emptySet() // we don't use implementation from super which caches all descriptors and does not use filters - override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection { + override fun getContributedDescriptors( + kindFilter: DescriptorKindFilter, + nameFilter: (Name) -> Boolean + ): Collection { return computeDescriptors(kindFilter, nameFilter, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS) } }