mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 11:53:49 +07:00
Revert " [java, highlighting] add standard "jigsaw" modules from the user's JDK for non-modular projects IDEA-259485"
This reverts commit 8e172c5f75f1d0840fbd48206c4e4708f47084fc. GitOrigin-RevId: 01871c48dca312f03d9b97a22ecf3602b7714613
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bb4ff68d32
commit
59caea7b12
@@ -757,8 +757,6 @@
|
||||
order="first" id="VmOptionsCompletionContributor"/>
|
||||
<applicationService serviceInterface="com.intellij.execution.vmOptions.VMOptionsService"
|
||||
serviceImplementation="com.intellij.execution.vmOptions.VMOptionsServiceImpl"/>
|
||||
<applicationService serviceInterface="com.intellij.execution.vmModules.VmModulesService"
|
||||
serviceImplementation="com.intellij.execution.vmModules.VmModulesServiceImpl"/>
|
||||
|
||||
<runDashboardCustomizer implementation="com.intellij.execution.CommonJavaRunDashboardCustomizer" id="commonJavaCustomizer"/>
|
||||
|
||||
|
||||
@@ -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<List<String>>
|
||||
}
|
||||
@@ -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<String, CompletableFuture<List<String>>> = CollectionFactory.createConcurrentSoftValueMap()
|
||||
}
|
||||
|
||||
override fun getOrComputeModulesForJdk(javaHome: String): CompletableFuture<List<String>> {
|
||||
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<String>? {
|
||||
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<String> = 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
|
||||
}
|
||||
}
|
||||
@@ -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<PsiJavaModule, Throwable> {
|
||||
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<PsiJavaModule, Throwable> {
|
||||
JavaPsiFacade.getInstance(place.project).findModule("java.se", module.moduleWithLibrariesScope)
|
||||
}
|
||||
return root == null || isAccessible(root, packageName, targetModule, useName, module)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getLoadedModules(module: Module): List<String> {
|
||||
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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user