Optimize getSingleAbstractMethodOrNull
Searching for the single abstract method leads to computing whole member scopes of given intrefaces, especially when they contain a lot of methods (i.e. they're definitely not SAMs) On the other side this method is very hot because it's called for each Java interface used as a type for some value parameter (for building SAM adapters) The idea is to apply some heuristics to understand using only JavaMethod and supertypes that this interface is definitely not a SAM
This commit is contained in:
+2
-1
@@ -52,6 +52,7 @@ import org.jetbrains.kotlin.idea.util.FuzzyType
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocName
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||
import org.jetbrains.kotlin.load.java.sam.SingleAbstractMethodUtils
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
@@ -508,7 +509,7 @@ class ExpressionsOfTypeProcessor(
|
||||
testLog?.add("Resolved java class to descriptor: ${psiClass.qualifiedName}")
|
||||
|
||||
val resolutionFacade = KotlinCacheService.getInstance(project).getResolutionFacadeByFile(psiClass.containingFile, JvmPlatform)
|
||||
val classDescriptor = psiClass.resolveToDescriptor(resolutionFacade)
|
||||
val classDescriptor = psiClass.resolveToDescriptor(resolutionFacade) as? JavaClassDescriptor
|
||||
if (classDescriptor != null && SingleAbstractMethodUtils.getSingleAbstractMethodOrNull(classDescriptor) != null) {
|
||||
addSamInterfaceToProcess(psiClass)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user