Enable debug log for PerModulePackageService only in J2K
This commit is contained in:
+19
-11
@@ -18,6 +18,7 @@ import com.intellij.openapi.project.rootManager
|
|||||||
import com.intellij.openapi.roots.ModuleRootEvent
|
import com.intellij.openapi.roots.ModuleRootEvent
|
||||||
import com.intellij.openapi.roots.ModuleRootListener
|
import com.intellij.openapi.roots.ModuleRootListener
|
||||||
import com.intellij.openapi.util.Disposer
|
import com.intellij.openapi.util.Disposer
|
||||||
|
import com.intellij.openapi.util.Key
|
||||||
import com.intellij.openapi.vfs.VfsUtilCore
|
import com.intellij.openapi.vfs.VfsUtilCore
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import com.intellij.openapi.vfs.VirtualFileManager
|
import com.intellij.openapi.vfs.VirtualFileManager
|
||||||
@@ -40,10 +41,12 @@ import org.jetbrains.kotlin.idea.util.sourceRoot
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi.KtPackageDirective
|
import org.jetbrains.kotlin.psi.KtPackageDirective
|
||||||
|
import org.jetbrains.kotlin.psi.NotNullableUserDataProperty
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import java.util.concurrent.ConcurrentMap
|
import java.util.concurrent.ConcurrentMap
|
||||||
|
import org.jetbrains.kotlin.idea.caches.PerModulePackageCacheService.Companion.DEBUG_LOG_ENABLE_PerModulePackageCache
|
||||||
|
|
||||||
class KotlinPackageContentModificationListener(private val project: Project) {
|
class KotlinPackageContentModificationListener(private val project: Project) {
|
||||||
init {
|
init {
|
||||||
@@ -85,7 +88,7 @@ class KotlinPackageContentModificationListener(private val project: Project) {
|
|||||||
class KotlinPackageStatementPsiTreeChangePreprocessor(private val project: Project) : PsiTreeChangePreprocessor {
|
class KotlinPackageStatementPsiTreeChangePreprocessor(private val project: Project) : PsiTreeChangePreprocessor {
|
||||||
override fun treeChanged(event: PsiTreeChangeEventImpl) {
|
override fun treeChanged(event: PsiTreeChangeEventImpl) {
|
||||||
val eFile = event.file ?: event.child as? PsiFile
|
val eFile = event.file ?: event.child as? PsiFile
|
||||||
if (eFile == null) LOG.debugInTests("Got PsiEvent: $event without file", true)
|
if (eFile == null) LOG.debugIfEnabled(project, "Got PsiEvent: $event without file", true)
|
||||||
val file = eFile as? KtFile ?: return
|
val file = eFile as? KtFile ?: return
|
||||||
|
|
||||||
when (event.code) {
|
when (event.code) {
|
||||||
@@ -94,7 +97,7 @@ class KotlinPackageStatementPsiTreeChangePreprocessor(private val project: Proje
|
|||||||
PsiTreeChangeEventImpl.PsiEventType.CHILD_REPLACED,
|
PsiTreeChangeEventImpl.PsiEventType.CHILD_REPLACED,
|
||||||
PsiTreeChangeEventImpl.PsiEventType.CHILD_REMOVED -> {
|
PsiTreeChangeEventImpl.PsiEventType.CHILD_REMOVED -> {
|
||||||
val child = event.child ?: run {
|
val child = event.child ?: run {
|
||||||
LOG.debugInTests("Got PsiEvent: $event without child", true)
|
LOG.debugIfEnabled(project, "Got PsiEvent: $event without child", true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (child.getParentOfType<KtPackageDirective>(false) != null)
|
if (child.getParentOfType<KtPackageDirective>(false) != null)
|
||||||
@@ -102,7 +105,7 @@ class KotlinPackageStatementPsiTreeChangePreprocessor(private val project: Proje
|
|||||||
}
|
}
|
||||||
PsiTreeChangeEventImpl.PsiEventType.CHILDREN_CHANGED -> {
|
PsiTreeChangeEventImpl.PsiEventType.CHILDREN_CHANGED -> {
|
||||||
val parent = event.parent ?: run {
|
val parent = event.parent ?: run {
|
||||||
LOG.debugInTests("Got PsiEvent: $event without parent", true)
|
LOG.debugIfEnabled(project, "Got PsiEvent: $event without parent", true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (parent.getChildrenOfType<KtPackageDirective>().any())
|
if (parent.getChildrenOfType<KtPackageDirective>().any())
|
||||||
@@ -243,7 +246,7 @@ class PerModulePackageCacheService(private val project: Project) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun invalidateCacheForModuleSourceInfo(moduleSourceInfo: ModuleSourceInfo) {
|
private fun invalidateCacheForModuleSourceInfo(moduleSourceInfo: ModuleSourceInfo) {
|
||||||
LOG.debugInTests("Invalidated cache for $moduleSourceInfo", false)
|
LOG.debugIfEnabled(project, "Invalidated cache for $moduleSourceInfo", false)
|
||||||
val perSourceInfoData = cache[moduleSourceInfo.module] ?: return
|
val perSourceInfoData = cache[moduleSourceInfo.module] ?: return
|
||||||
val dataForSourceInfo = perSourceInfoData[moduleSourceInfo] ?: return
|
val dataForSourceInfo = perSourceInfoData[moduleSourceInfo] ?: return
|
||||||
dataForSourceInfo.clear()
|
dataForSourceInfo.clear()
|
||||||
@@ -263,14 +266,14 @@ class PerModulePackageCacheService(private val project: Project) {
|
|||||||
if (sourceRootUrls.any { url ->
|
if (sourceRootUrls.any { url ->
|
||||||
vfile.containedInOrContains(url)
|
vfile.containedInOrContains(url)
|
||||||
}) {
|
}) {
|
||||||
LOG.debugInTests("Invalidated cache for $module")
|
LOG.debugIfEnabled(project, "Invalidated cache for $module")
|
||||||
data.clear()
|
data.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val infoByVirtualFile = getModuleInfoByVirtualFile(project, vfile)
|
val infoByVirtualFile = getModuleInfoByVirtualFile(project, vfile)
|
||||||
if (infoByVirtualFile == null || infoByVirtualFile !is ModuleSourceInfo) {
|
if (infoByVirtualFile == null || infoByVirtualFile !is ModuleSourceInfo) {
|
||||||
LOG.debugInTests("Skip $vfile as it has mismatched ModuleInfo=$infoByVirtualFile")
|
LOG.debugIfEnabled(project, "Skip $vfile as it has mismatched ModuleInfo=$infoByVirtualFile")
|
||||||
}
|
}
|
||||||
(infoByVirtualFile as? ModuleSourceInfo)?.let {
|
(infoByVirtualFile as? ModuleSourceInfo)?.let {
|
||||||
invalidateCacheForModuleSourceInfo(it)
|
invalidateCacheForModuleSourceInfo(it)
|
||||||
@@ -282,13 +285,13 @@ class PerModulePackageCacheService(private val project: Project) {
|
|||||||
|
|
||||||
pendingKtFileChanges.processPending { file ->
|
pendingKtFileChanges.processPending { file ->
|
||||||
if (file.virtualFile != null && file.virtualFile !in projectScope) {
|
if (file.virtualFile != null && file.virtualFile !in projectScope) {
|
||||||
LOG.debugInTests("Skip $file without vFile, or not in scope: ${file.virtualFile?.let { it !in projectScope }}")
|
LOG.debugIfEnabled(project, "Skip $file without vFile, or not in scope: ${file.virtualFile?.let { it !in projectScope }}")
|
||||||
return@processPending
|
return@processPending
|
||||||
}
|
}
|
||||||
val nullableModuleInfo = file.getNullableModuleInfo()
|
val nullableModuleInfo = file.getNullableModuleInfo()
|
||||||
(nullableModuleInfo as? ModuleSourceInfo)?.let { invalidateCacheForModuleSourceInfo(it) }
|
(nullableModuleInfo as? ModuleSourceInfo)?.let { invalidateCacheForModuleSourceInfo(it) }
|
||||||
if (nullableModuleInfo == null || nullableModuleInfo !is ModuleSourceInfo) {
|
if (nullableModuleInfo == null || nullableModuleInfo !is ModuleSourceInfo) {
|
||||||
LOG.debugInTests("Skip $file as it has mismatched ModuleInfo=$nullableModuleInfo")
|
LOG.debugIfEnabled(project, "Skip $file as it has mismatched ModuleInfo=$nullableModuleInfo")
|
||||||
}
|
}
|
||||||
implicitPackagePrefixCache.update(file)
|
implicitPackagePrefixCache.update(file)
|
||||||
}
|
}
|
||||||
@@ -329,7 +332,7 @@ class PerModulePackageCacheService(private val project: Project) {
|
|||||||
|
|
||||||
return cacheForCurrentModuleInfo.getOrPut(packageFqName) {
|
return cacheForCurrentModuleInfo.getOrPut(packageFqName) {
|
||||||
val packageExists = PackageIndexUtil.packageExists(packageFqName, moduleInfo.contentScope(), project)
|
val packageExists = PackageIndexUtil.packageExists(packageFqName, moduleInfo.contentScope(), project)
|
||||||
LOG.debugInTests("Computed cache value for $packageFqName in $moduleInfo is $packageExists")
|
LOG.debugIfEnabled(project, "Computed cache value for $packageFqName in $moduleInfo is $packageExists")
|
||||||
packageExists
|
packageExists
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -345,12 +348,17 @@ class PerModulePackageCacheService(private val project: Project) {
|
|||||||
|
|
||||||
fun getInstance(project: Project): PerModulePackageCacheService =
|
fun getInstance(project: Project): PerModulePackageCacheService =
|
||||||
ServiceManager.getService(project, PerModulePackageCacheService::class.java)
|
ServiceManager.getService(project, PerModulePackageCacheService::class.java)
|
||||||
|
|
||||||
|
var Project.DEBUG_LOG_ENABLE_PerModulePackageCache: Boolean
|
||||||
|
by NotNullableUserDataProperty<Project, Boolean>(Key.create("debug.PerModulePackageCache"), false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun Logger.debugInTests(message: String, withCurrentTrace: Boolean = false) {
|
|
||||||
if (ApplicationManager.getApplication().isUnitTestMode) {
|
|
||||||
|
private fun Logger.debugIfEnabled(project: Project, message: String, withCurrentTrace: Boolean = false) {
|
||||||
|
if (ApplicationManager.getApplication().isUnitTestMode && project.DEBUG_LOG_ENABLE_PerModulePackageCache) {
|
||||||
if (withCurrentTrace) {
|
if (withCurrentTrace) {
|
||||||
val e = Exception().apply { fillInStackTrace() }
|
val e = Exception().apply { fillInStackTrace() }
|
||||||
this.debug(message, e)
|
this.debug(message, e)
|
||||||
|
|||||||
@@ -26,12 +26,15 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
|||||||
import org.jetbrains.kotlin.idea.test.invalidateLibraryCache
|
import org.jetbrains.kotlin.idea.test.invalidateLibraryCache
|
||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
|
import org.jetbrains.kotlin.idea.caches.PerModulePackageCacheService.Companion.DEBUG_LOG_ENABLE_PerModulePackageCache
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
abstract class AbstractJavaToKotlinConverterTest : LightCodeInsightFixtureTestCase() {
|
abstract class AbstractJavaToKotlinConverterTest : LightCodeInsightFixtureTestCase() {
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
|
|
||||||
|
project.DEBUG_LOG_ENABLE_PerModulePackageCache = true
|
||||||
|
|
||||||
val testName = getTestName(false)
|
val testName = getTestName(false)
|
||||||
if (testName.contains("Java8") || testName.contains("java8")) {
|
if (testName.contains("Java8") || testName.contains("java8")) {
|
||||||
LanguageLevelProjectExtension.getInstance(project).languageLevel = LanguageLevel.JDK_1_8
|
LanguageLevelProjectExtension.getInstance(project).languageLevel = LanguageLevel.JDK_1_8
|
||||||
@@ -47,6 +50,8 @@ abstract class AbstractJavaToKotlinConverterTest : LightCodeInsightFixtureTestCa
|
|||||||
|
|
||||||
override fun tearDown() {
|
override fun tearDown() {
|
||||||
VfsRootAccess.disallowRootAccess(KotlinTestUtils.getHomeDirectory())
|
VfsRootAccess.disallowRootAccess(KotlinTestUtils.getHomeDirectory())
|
||||||
|
|
||||||
|
project.DEBUG_LOG_ENABLE_PerModulePackageCache = false
|
||||||
super.tearDown()
|
super.tearDown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user