diff --git a/java/java-impl/src/META-INF/JavaPlugin.xml b/java/java-impl/src/META-INF/JavaPlugin.xml
index 8fdc59383617..3f762b52895b 100644
--- a/java/java-impl/src/META-INF/JavaPlugin.xml
+++ b/java/java-impl/src/META-INF/JavaPlugin.xml
@@ -757,8 +757,6 @@
order="first" id="VmOptionsCompletionContributor"/>
-
diff --git a/java/java-impl/src/com/intellij/execution/vmModules/VmModulesService.kt b/java/java-impl/src/com/intellij/execution/vmModules/VmModulesService.kt
deleted file mode 100644
index 71ba84023ede..000000000000
--- a/java/java-impl/src/com/intellij/execution/vmModules/VmModulesService.kt
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
-package com.intellij.execution.vmModules
-
-import com.intellij.openapi.components.service
-import java.util.concurrent.CompletableFuture
-
-interface VmModulesService {
- companion object {
- @JvmStatic
- fun getInstance(): VmModulesService = service()
- }
-
- fun getOrComputeModulesForJdk(javaHome: String): CompletableFuture>
-}
\ No newline at end of file
diff --git a/java/java-impl/src/com/intellij/execution/vmModules/VmModulesServiceImpl.kt b/java/java-impl/src/com/intellij/execution/vmModules/VmModulesServiceImpl.kt
deleted file mode 100644
index 4a0a90685f1c..000000000000
--- a/java/java-impl/src/com/intellij/execution/vmModules/VmModulesServiceImpl.kt
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
-package com.intellij.execution.vmModules
-
-import com.intellij.execution.configurations.GeneralCommandLine
-import com.intellij.execution.process.CapturingProcessRunner
-import com.intellij.execution.process.OSProcessHandler
-import com.intellij.execution.process.ProcessNotCreatedException
-import com.intellij.openapi.util.SystemInfo
-import com.intellij.openapi.util.io.FileUtil
-import com.intellij.util.containers.CollectionFactory
-import java.io.File
-import java.nio.file.Path
-import java.util.concurrent.CompletableFuture
-import java.util.concurrent.ConcurrentMap
-
-class VmModulesServiceImpl : VmModulesService {
- companion object {
- private val ourData: ConcurrentMap>> = CollectionFactory.createConcurrentSoftValueMap()
- }
-
- override fun getOrComputeModulesForJdk(javaHome: String): CompletableFuture> {
- val future = ourData.computeIfAbsent(javaHome) { CompletableFuture.supplyAsync { computeModules(it) } }
- if (future.isDone) {
- // sometimes the timeout may appear and in order not to block the possibility to get the completion afterwards, it is better to retry
- if (future.get() == null) {
- ourData.remove(javaHome)
- }
- }
- return future
- }
-
- // when null is returned, it was a timeout
- private fun computeModules(javaHome: String): List? {
- val vmPath = getVmPath(javaHome)
- val generalCommandLine = GeneralCommandLine(vmPath).apply {
- addParameters("--list-modules")
- }
- try {
- val handler = OSProcessHandler(generalCommandLine)
- val runner = CapturingProcessRunner(handler)
- val output = runner.runProcess(1_000)
- if (output.isTimeout) {
- return null
- } else {
- return parse(output.stdout) + parse(output.stderr)
- }
- }
- catch (e: ProcessNotCreatedException) {
- return null
- }
- }
-
- private fun parse(out: String): List = out.lineSequence().map { line -> line.substringBefore('@') }.toList()
-
- private fun getVmPath(javaHome: String): String {
- val vmExeName = if (SystemInfo.isWindows) "java.exe" else "java" // do not use JavaW.exe because of issues with encoding
- return Path.of(getConvertedPath(javaHome), "bin", vmExeName).toString()
- }
-
- private fun getConvertedPath(javaHome: String): String {
- // it is copied from com.intellij.openapi.projectRoots.impl.JavaSdkImpl.getConvertedHomePath
- var systemDependentName = FileUtil.toSystemDependentName(javaHome)
- if (javaHome.endsWith(File.separatorChar)) {
- systemDependentName += File.separatorChar
- }
- return systemDependentName
- }
-}
\ No newline at end of file
diff --git a/java/java-impl/src/com/intellij/psi/impl/JavaPlatformModuleSystem.kt b/java/java-impl/src/com/intellij/psi/impl/JavaPlatformModuleSystem.kt
index da9f0331f432..7d35ffb32a1d 100644
--- a/java/java-impl/src/com/intellij/psi/impl/JavaPlatformModuleSystem.kt
+++ b/java/java-impl/src/com/intellij/psi/impl/JavaPlatformModuleSystem.kt
@@ -9,7 +9,6 @@ import com.intellij.codeInsight.daemon.impl.analysis.JavaModuleGraphUtil
import com.intellij.codeInsight.daemon.impl.quickfix.AddExportsDirectiveFix
import com.intellij.codeInsight.daemon.impl.quickfix.AddRequiresDirectiveFix
import com.intellij.codeInspection.util.IntentionName
-import com.intellij.execution.vmModules.VmModulesService
import com.intellij.java.JavaBundle
import com.intellij.modcommand.ActionContext
import com.intellij.modcommand.ModCommand
@@ -17,13 +16,10 @@ import com.intellij.modcommand.ModCommandAction
import com.intellij.modcommand.Presentation
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleUtilCore
-import com.intellij.openapi.progress.runBlockingCancellable
-import com.intellij.openapi.projectRoots.JavaSdk
import com.intellij.openapi.roots.JdkOrderEntry
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.openapi.roots.ProjectRootManager
-import com.intellij.platform.ide.progress.withBackgroundProgress
import com.intellij.pom.java.JavaFeature
import com.intellij.psi.*
import com.intellij.psi.JavaModuleSystem.*
@@ -32,7 +28,6 @@ import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.util.PsiUtil
import com.intellij.util.indexing.DumbModeAccessType
import org.jetbrains.annotations.NonNls
-import java.util.concurrent.TimeUnit
import java.util.regex.Pattern
private const val MAIN = "main"
@@ -55,8 +50,8 @@ internal class JavaPlatformModuleSystem : JavaModuleSystemEx {
return getProblem(targetPackageName, targetFile, place, false) { use, _, target, _, _ -> JavaModuleGraphUtil.reads(use, target) }
}
- private fun isExported(useModule: PsiJavaModule, packageName: String, targetModule: PsiJavaModule, useModuleName: String, module: Module?): Boolean {
- if (!targetModule.isPhysical || JavaModuleGraphUtil.exports(targetModule, packageName, useModule)) return true
+ private fun isExported(useModule: PsiJavaModule, packageName: String, targetModule: PsiJavaModule, useModuleName: String, module: Module?) : Boolean {
+ if(!targetModule.isPhysical || JavaModuleGraphUtil.exports(targetModule, packageName, useModule)) return true
if (module == null) return false
return inAddedExports(module, targetModule.name, packageName, useModuleName)
}
@@ -123,12 +118,16 @@ internal class JavaPlatformModuleSystem : JavaModuleSystemEx {
if (targetName.startsWith("java.") &&
targetName != PsiJavaModule.JAVA_BASE &&
!inAddedModules(module, targetName) &&
- !hasUpgrade(module, targetName, packageName, place) &&
- !accessibleFromLoadedModules(module, targetName, place, isAccessible, packageName, targetModule, useName)) {
- return if (quick) ERR
- else ErrorWithFixes(
- JavaErrorBundle.message("module.access.not.in.graph", packageName, targetName),
- listOf(AddModulesOptionFix(module, targetName).asIntention()))
+ !hasUpgrade(module, targetName, packageName, place)) {
+ val root = DumbModeAccessType.RELIABLE_DATA_ONLY.ignoreDumbMode {
+ JavaPsiFacade.getInstance(place.project).findModule("java.se", module.moduleWithLibrariesScope)
+ }
+ if (root != null && !isAccessible(root, packageName, targetModule, useName, module)) {
+ return if (quick) ERR
+ else ErrorWithFixes(
+ JavaErrorBundle.message("module.access.not.in.graph", packageName, targetName),
+ listOf(AddModulesOptionFix(module, targetName).asIntention()))
+ }
}
}
@@ -176,43 +175,6 @@ internal class JavaPlatformModuleSystem : JavaModuleSystemEx {
return null
}
- private fun accessibleFromLoadedModules(module: Module,
- targetName: String,
- place: PsiFileSystemItem,
- isAccessible: (useModule: PsiJavaModule, packageName: String, targetModule: PsiJavaModule, useModuleName: String, module: Module?) -> Boolean,
- packageName: String,
- targetModule: PsiJavaModule,
- useName: String): Boolean {
- val modules = getLoadedModules(module)
- if (!modules.isEmpty()) {
- return modules.contains(targetName)
- }
- else {
- val root = DumbModeAccessType.RELIABLE_DATA_ONLY.ignoreDumbMode {
- JavaPsiFacade.getInstance(place.project).findModule("java.se", module.moduleWithLibrariesScope)
- }
- return root == null || isAccessible(root, packageName, targetModule, useName, module)
- }
- }
-
- private fun getLoadedModules(module: Module): List {
- val sdk = ModuleRootManager.getInstance(module).sdk ?: return listOf()
- if (sdk.sdkType is JavaSdk) {
- val sdkHome = sdk.homePath ?: return listOf()
- try {
- val modules = VmModulesService.getInstance().getOrComputeModulesForJdk(sdkHome)
- return runBlockingCancellable {
- withBackgroundProgress(module.project, JavaBundle.message("load.modules.from.jdk")) {
- modules.get(1, TimeUnit.SECONDS) ?: listOf()
- }
- }
- }
- catch (ignore: Exception) {
- }
- }
- return listOf()
- }
-
private fun inSameMultiReleaseModule(place: PsiElement, target: PsiElement): Boolean {
val placeModule = ModuleUtilCore.findModuleForPsiElement(place) ?: return false
val targetModule = ModuleUtilCore.findModuleForPsiElement(target) ?: return false
diff --git a/java/openapi/resources/messages/JavaBundle.properties b/java/openapi/resources/messages/JavaBundle.properties
index c917b9242723..b1f1c5247429 100644
--- a/java/openapi/resources/messages/JavaBundle.properties
+++ b/java/openapi/resources/messages/JavaBundle.properties
@@ -1803,7 +1803,6 @@ intention.family.name.move.class.to.test.root=Move class to test root
intention.name.move.class.to.test.root=Move ''{0}'' to test root
megabytes.unit=megabytes
java.platform.module.system.name=Java Platform Module System
-load.modules.from.jdk=Loading modules...
dialog.title.move.directory=Move Directory
progress.title.checking.if.class.exists=Check target class ''{0}'' exists
quickfix.find.cause.description=Attempts to highlight code elements that resulted in this warning and explain how exactly they contribute.