Take longer read action in forEachKotlinOverride()

EA-114124 - assert: CompositeElement.getChildrenAsPsiElements
This commit is contained in:
Dmitry Jemerov
2017-12-28 12:11:17 +01:00
parent 768fce4722
commit 254f766aaf
@@ -1,17 +1,6 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* * that can be found in the license/LICENSE.txt file.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.jetbrains.kotlin.idea.search.declarationsSearch package org.jetbrains.kotlin.idea.search.declarationsSearch
@@ -43,7 +32,6 @@ import org.jetbrains.kotlin.idea.core.getDeepestSuperDeclarations
import org.jetbrains.kotlin.idea.core.isOverridable import org.jetbrains.kotlin.idea.core.isOverridable
import org.jetbrains.kotlin.idea.search.allScope import org.jetbrains.kotlin.idea.search.allScope
import org.jetbrains.kotlin.idea.search.excludeKotlinSources import org.jetbrains.kotlin.idea.search.excludeKotlinSources
import org.jetbrains.kotlin.idea.search.restrictToKotlinSources
import org.jetbrains.kotlin.idea.util.application.runReadAction import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
@@ -140,19 +128,22 @@ private fun forEachKotlinOverride(
val baseDescriptors = runReadAction { members.mapNotNull { it.unsafeResolveToDescriptor() as? CallableMemberDescriptor }.filter { it.isOverridable } } val baseDescriptors = runReadAction { members.mapNotNull { it.unsafeResolveToDescriptor() as? CallableMemberDescriptor }.filter { it.isOverridable } }
if (baseDescriptors.isEmpty()) return true if (baseDescriptors.isEmpty()) return true
HierarchySearchRequest(ktClass, scope, true).searchInheritors().forEach { HierarchySearchRequest(ktClass, scope, true).searchInheritors().forEach(Processor {
val inheritor = it.unwrapped as? KtClassOrObject ?: return@forEach val inheritor = it.unwrapped as? KtClassOrObject ?: return@Processor true
val inheritorDescriptor = runReadAction { inheritor.unsafeResolveToDescriptor() as ClassDescriptor } runReadAction {
val substitutor = getTypeSubstitutor(baseClassDescriptor.defaultType, inheritorDescriptor.defaultType) ?: return@forEach val inheritorDescriptor = inheritor.unsafeResolveToDescriptor() as ClassDescriptor
baseDescriptors.forEach { val substitutor = getTypeSubstitutor(baseClassDescriptor.defaultType, inheritorDescriptor.defaultType) ?: return@runReadAction true
val superMember = it.source.getPsi()!! baseDescriptors.forEach {
val overridingDescriptor = inheritorDescriptor.findCallableMemberBySignature(it.substitute(substitutor) as CallableMemberDescriptor) val superMember = it.source.getPsi()!!
val overridingMember = overridingDescriptor?.source?.getPsi() val overridingDescriptor = inheritorDescriptor.findCallableMemberBySignature(it.substitute(substitutor) as CallableMemberDescriptor)
if (overridingMember != null) { val overridingMember = overridingDescriptor?.source?.getPsi()
if (!processor(superMember, overridingMember)) return false if (overridingMember != null) {
if (!processor(superMember, overridingMember)) return@runReadAction false
}
} }
true
} }
} })
return true return true
} }