mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] removes incorrect accessibility error (IDEA-187250)
... when IDEA thought that a class is in an inaccessible JDK module, while in fact there is an upgrade on the classpath.
This commit is contained in:
@@ -93,7 +93,8 @@ class JavaPlatformModuleSystem : JavaModuleSystemEx {
|
||||
}
|
||||
|
||||
val root = PsiJavaModuleReference.resolve(place, "java.se", false)
|
||||
if (!(root == null || JavaModuleGraphUtil.reads(root, targetModule) || inAddedModules(module, targetName))) {
|
||||
if (!(root == null || JavaModuleGraphUtil.reads(root, targetModule) || inAddedModules(module, targetName) ||
|
||||
hasUpgrade(module, targetName, packageName, place))) {
|
||||
return if (quick) ERR else ErrorWithFixes(
|
||||
JavaErrorMessages.message("module.access.not.in.graph", packageName, targetName),
|
||||
listOf(AddModulesOptionFix(module, targetName)))
|
||||
@@ -133,6 +134,23 @@ class JavaPlatformModuleSystem : JavaModuleSystemEx {
|
||||
return null
|
||||
}
|
||||
|
||||
private fun hasUpgrade(module: Module, targetName: String, packageName: String, place: PsiFileSystemItem): Boolean {
|
||||
if (PsiJavaModule.UPGRADEABLE.contains(targetName)) {
|
||||
val target = JavaPsiFacade.getInstance(module.project).findPackage(packageName)
|
||||
if (target != null) {
|
||||
val useVFile = place.virtualFile
|
||||
if (useVFile != null) {
|
||||
val index = ModuleRootManager.getInstance(module).fileIndex
|
||||
val test = index.isInTestSourceContent(useVFile)
|
||||
val dirs = target.getDirectories(module.getModuleWithDependenciesAndLibrariesScope(test))
|
||||
return dirs.asSequence().any { index.getOrderEntryForFile(it.virtualFile) !is JdkOrderEntry }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private fun inAddedExports(module: Module, targetName: String, packageName: String, useName: String): Boolean {
|
||||
val options = JavaCompilerConfigurationProxy.getAdditionalOptions(module.project, module)
|
||||
if (options.isEmpty()) return false
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.psi;
|
||||
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Represents a Java module declaration.
|
||||
*
|
||||
@@ -28,6 +18,11 @@ public interface PsiJavaModule extends NavigatablePsiElement, PsiNameIdentifierO
|
||||
String MODULE_INFO_CLS_FILE = MODULE_INFO_CLASS + ".class";
|
||||
String JAVA_BASE = "java.base";
|
||||
|
||||
/* See http://openjdk.java.net/jeps/261#Class-loaders, "Class loaders" */
|
||||
Set<String> UPGRADEABLE = Collections.unmodifiableSet(ContainerUtil.newTroveSet(
|
||||
"java.activation", "java.compiler", "java.corba", "java.transaction", "java.xml.bind", "java.xml.ws", "java.xml.ws.annotation",
|
||||
"jdk.internal.vm.compiler", "jdk.xml.bind", "jdk.xml.ws"));
|
||||
|
||||
@Override @NotNull PsiJavaModuleReferenceElement getNameIdentifier();
|
||||
@Override @NotNull String getName();
|
||||
|
||||
|
||||
Binary file not shown.
+4
-2
@@ -33,7 +33,8 @@ class ModuleCompletionTest : LightJava9ModulesCodeInsightFixtureTestCase() {
|
||||
|
||||
fun testRequiresBare() =
|
||||
variants("module M { requires <caret>",
|
||||
"transitive", "static", "M2", "java.base", "java.se", "javax.doomed", "lib.multi.release", "lib.named", "lib.auto", "lib.claimed")
|
||||
"transitive", "static", "M2", "java.base", "java.se", "java.xml.bind", "javax.doomed",
|
||||
"lib.multi.release", "lib.named", "lib.auto", "lib.claimed")
|
||||
fun testRequiresTransitive() = complete("module M { requires tr<caret> }", "module M { requires transitive <caret> }")
|
||||
fun testRequiresSimpleName() = complete("module M { requires M<caret> }", "module M { requires M2;<caret> }")
|
||||
fun testRequiresQualifiedName() = complete("module M { requires lib.m<caret> }", "module M { requires lib.multi.release;<caret> }")
|
||||
@@ -44,7 +45,8 @@ class ModuleCompletionTest : LightJava9ModulesCodeInsightFixtureTestCase() {
|
||||
fun testExportsQualifiedUnambiguous() = complete("module M { exports pkg.o<caret> }", "module M { exports pkg.other.<caret> }")
|
||||
fun testExportsTo() = complete("module M { exports pkg.other <caret> }", "module M { exports pkg.other to <caret> }")
|
||||
fun testExportsToList() =
|
||||
variants("module M { exports pkg.other to <caret> }", "M2", "java.base", "java.se", "javax.doomed", "lib.multi.release", "lib.named")
|
||||
variants("module M { exports pkg.other to <caret> }",
|
||||
"M2", "java.base", "java.se", "java.xml.bind", "javax.doomed", "lib.multi.release", "lib.named")
|
||||
fun testExportsToUnambiguous() = complete("module M { exports pkg.other to M<caret> }", "module M { exports pkg.other to M2<caret> }")
|
||||
|
||||
fun testUsesPrefixed() = complete("module M { uses p<caret> }", "module M { uses pkg.<caret> }")
|
||||
|
||||
@@ -314,6 +314,13 @@ class ModuleHighlightingTest : LightJava9ModulesCodeInsightFixtureTestCase() {
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun testUpgradeableModuleOnClasspath() {
|
||||
highlight("test.java", """
|
||||
import java.xml.bind.*;
|
||||
import java.xml.bind.C;
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun testLinearModuleGraphBug() {
|
||||
addFile("module-info.java", "module M6 { requires M7; }", M6)
|
||||
addFile("module-info.java", "module M7 { }", M7)
|
||||
|
||||
+1
@@ -73,6 +73,7 @@ object MultiModuleJava9ProjectDescriptor : DefaultLightProjectDescriptor() {
|
||||
ModuleRootModificationUtil.addModuleLibrary(main, "${libDir}/lib-auto-2.0.jar!/")
|
||||
ModuleRootModificationUtil.addModuleLibrary(main, "${libDir}/lib-multi-release.jar!/")
|
||||
ModuleRootModificationUtil.addModuleLibrary(main, "${libDir}/lib_invalid_1_2.jar!/")
|
||||
ModuleRootModificationUtil.addModuleLibrary(main, "${libDir}/lib-xml-bind.jar!/")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user