Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPDATE_KOTLIN_VERSION: 2.1.0-dev-7621 #2141

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ import com.intellij.openapi.vfs.StandardFileSystems
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.psi.PsiJavaFile
import com.intellij.psi.PsiManager
import com.intellij.psi.impl.file.impl.JavaFileManager
import org.jetbrains.kotlin.analyzer.AnalysisResult
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCliJavaFileManagerImpl
import org.jetbrains.kotlin.config.JvmAnalysisFlags
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.container.ComponentProvider
Expand Down Expand Up @@ -157,6 +159,8 @@ abstract class AbstractKotlinSymbolProcessingExtension(
val psiManager = PsiManager.getInstance(project)
if (initialized) {
psiManager.dropPsiCaches()
psiManager.dropResolveCaches()
invalidateKotlinCliJavaFileManagerCache(project)
} else {
// In case of broken builds.
if (javaShadowBase.exists()) {
Expand Down Expand Up @@ -509,3 +513,13 @@ fun findTargetInfos(languageVersionSettings: LanguageVersionSettings, module: Mo
else -> UnknownPlatformInfoImpl(platform.toString())
}
} ?: emptyList()

// FIXME: remove as soon as possible.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the plan (on what condition) to remove this wordkaround

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix just landed in the Kotlin compiler and should be available in the next bootstrap release and Kotlin 2.1.0-RC.

private fun invalidateKotlinCliJavaFileManagerCache(project: Project): Boolean {
val javaFileManager = (JavaFileManager.getInstance(project) as? KotlinCliJavaFileManagerImpl) ?: return false
val privateCacheField = KotlinCliJavaFileManagerImpl::class.java.getDeclaredField("topLevelClassesCache")
if (!privateCacheField.trySetAccessible())
return false
(privateCacheField.get(javaFileManager) as? MutableMap<*, *>)?.clear() ?: return false
return true
}
Loading