mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
[kotlin] KTIJ-34592 - fixed KotlinModuleSizeCollector running even for Java-only projects
^KTIJ-34592 fixed GitOrigin-RevId: 954f96ec6bfd344bdffde58273851d7f49b33147
This commit is contained in:
committed by
intellij-monorepo-bot
parent
844d3c2c32
commit
82f7ade5ea
@@ -14,6 +14,8 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.modules
|
||||
import com.intellij.openapi.roots.ModuleRootManager
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.search.FileTypeIndex
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
@@ -174,11 +176,24 @@ internal class KotlinModuleSizeCollector : ProjectUsagesCollector() {
|
||||
return projectStatistics.generateEvents()
|
||||
}
|
||||
|
||||
private fun Project.hasKotlinFiles(): Boolean {
|
||||
return FileTypeIndex.containsFileOfType(KotlinFileType.INSTANCE, GlobalSearchScope.projectScope(this))
|
||||
}
|
||||
|
||||
override suspend fun collect(project: Project): Set<MetricEvent> {
|
||||
if (!KotlinModuleSizeCollectorTracker.getInstance(project).shouldCollectData()) return emptySet()
|
||||
|
||||
val startTime = System.currentTimeMillis()
|
||||
val result = project.gatherProjectStatistics()
|
||||
val hasKotlinFiles = readAction {
|
||||
project.hasKotlinFiles()
|
||||
}
|
||||
// If there are no Kotlin files, then we do not want to collect any statistics for the project.
|
||||
// We still want to mark it as having finished collecting statistics, so that we do not check for Kotlin files too often.
|
||||
val result = if (hasKotlinFiles) {
|
||||
project.gatherProjectStatistics()
|
||||
} else {
|
||||
emptySet()
|
||||
}
|
||||
KotlinModuleSizeCollectorTracker.getInstance(project).onCollectionFinished()
|
||||
logger.debug("Collecting stats for project took ${System.currentTimeMillis() - startTime} ms")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user