Log fallbacks to plain text search when searching expressions of type
This will help diagnose performance problems in IDEA inspections.
This commit is contained in:
+16
-4
@@ -20,6 +20,7 @@ import com.intellij.ide.highlighter.JavaFileType
|
|||||||
import com.intellij.ide.highlighter.XmlFileType
|
import com.intellij.ide.highlighter.XmlFileType
|
||||||
import com.intellij.lang.java.JavaLanguage
|
import com.intellij.lang.java.JavaLanguage
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
import com.intellij.psi.search.FileTypeIndex
|
import com.intellij.psi.search.FileTypeIndex
|
||||||
@@ -81,6 +82,8 @@ class ExpressionsOfTypeProcessor(
|
|||||||
@TestOnly
|
@TestOnly
|
||||||
var testLog: MutableList<String>? = null
|
var testLog: MutableList<String>? = null
|
||||||
|
|
||||||
|
val LOG = Logger.getInstance(ExpressionsOfTypeProcessor::class.java)
|
||||||
|
|
||||||
fun logPresentation(element: PsiElement): String? {
|
fun logPresentation(element: PsiElement): String? {
|
||||||
return runReadAction {
|
return runReadAction {
|
||||||
if (element !is KtDeclaration && element !is PsiMember) return@runReadAction element.text
|
if (element !is KtDeclaration && element !is PsiMember) return@runReadAction element.text
|
||||||
@@ -184,15 +187,15 @@ class ExpressionsOfTypeProcessor(
|
|||||||
searchReferences(classToSearch, scope) { reference ->
|
searchReferences(classToSearch, scope) { reference ->
|
||||||
if (processClassUsage(reference)) return@searchReferences true
|
if (processClassUsage(reference)) return@searchReferences true
|
||||||
|
|
||||||
|
val diagnosticsMessage = getFallbackDiagnosticsMessage(reference)
|
||||||
|
|
||||||
if (mode != Mode.ALWAYS_SMART) {
|
if (mode != Mode.ALWAYS_SMART) {
|
||||||
|
LOG.info(diagnosticsMessage)
|
||||||
downShiftToPlainSearch()
|
downShiftToPlainSearch()
|
||||||
return@searchReferences false
|
return@searchReferences false
|
||||||
}
|
}
|
||||||
|
|
||||||
val element = reference.element
|
error(diagnosticsMessage)
|
||||||
val document = PsiDocumentManager.getInstance(project).getDocument(element.containingFile)
|
|
||||||
val lineAndCol = DiagnosticUtils.offsetToLineAndColumn(document, element.startOffset)
|
|
||||||
error("Unsupported reference: '${element.text}' in ${element.containingFile.name} line ${lineAndCol.line} column ${lineAndCol.column}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we must use plain search inside our class (and inheritors) because implicit 'this' can happen anywhere
|
// we must use plain search inside our class (and inheritors) because implicit 'this' can happen anywhere
|
||||||
@@ -202,6 +205,13 @@ class ExpressionsOfTypeProcessor(
|
|||||||
addTask(ProcessClassUsagesTask(classToSearch))
|
addTask(ProcessClassUsagesTask(classToSearch))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getFallbackDiagnosticsMessage(reference: PsiReference): String {
|
||||||
|
val element = reference.element
|
||||||
|
val document = PsiDocumentManager.getInstance(project).getDocument(element.containingFile)
|
||||||
|
val lineAndCol = DiagnosticUtils.offsetToLineAndColumn(document, element.startOffset)
|
||||||
|
return "ExpressionsOfTypeProcessor: Unsupported reference: '${element.text}' in ${element.containingFile.name} line ${lineAndCol.line} column ${lineAndCol.column}"
|
||||||
|
}
|
||||||
|
|
||||||
private enum class ReferenceProcessor(val handler: (ExpressionsOfTypeProcessor, PsiReference) -> Boolean) {
|
private enum class ReferenceProcessor(val handler: (ExpressionsOfTypeProcessor, PsiReference) -> Boolean) {
|
||||||
CallableOfOurType(ExpressionsOfTypeProcessor::processReferenceToCallableOfOurType),
|
CallableOfOurType(ExpressionsOfTypeProcessor::processReferenceToCallableOfOurType),
|
||||||
|
|
||||||
@@ -220,6 +230,7 @@ class ExpressionsOfTypeProcessor(
|
|||||||
searchReferences(searchParameters) { reference ->
|
searchReferences(searchParameters) { reference ->
|
||||||
val processed = processor.handler(this@ExpressionsOfTypeProcessor, reference)
|
val processed = processor.handler(this@ExpressionsOfTypeProcessor, reference)
|
||||||
if (!processed) { // we don't know how to handle this reference and down-shift to plain search
|
if (!processed) { // we don't know how to handle this reference and down-shift to plain search
|
||||||
|
LOG.info(getFallbackDiagnosticsMessage(reference))
|
||||||
downShiftToPlainSearch()
|
downShiftToPlainSearch()
|
||||||
}
|
}
|
||||||
processed
|
processed
|
||||||
@@ -269,6 +280,7 @@ class ExpressionsOfTypeProcessor(
|
|||||||
testLog?.add("Searched references to ${logPresentation(psiClass)} in non-Kotlin files")
|
testLog?.add("Searched references to ${logPresentation(psiClass)} in non-Kotlin files")
|
||||||
searchReferences(psiClass, scope) { reference ->
|
searchReferences(psiClass, scope) { reference ->
|
||||||
if (reference.element.language != JavaFileType.INSTANCE) { // reference in some JVM language can be method parameter (but we don't know)
|
if (reference.element.language != JavaFileType.INSTANCE) { // reference in some JVM language can be method parameter (but we don't know)
|
||||||
|
LOG.info(getFallbackDiagnosticsMessage(reference))
|
||||||
downShiftToPlainSearch()
|
downShiftToPlainSearch()
|
||||||
return@searchReferences false
|
return@searchReferences false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user