mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] allows one module-info file in either source or test root - highlighting (IDEA-171221)
This commit is contained in:
+1
-1
@@ -135,7 +135,7 @@ public class ModuleHighlightUtil {
|
||||
Module module = findModule(file);
|
||||
if (module != null) {
|
||||
Project project = file.getProject();
|
||||
Collection<VirtualFile> others = FilenameIndex.getVirtualFilesByName(project, MODULE_INFO_FILE, module.getModuleScope(false));
|
||||
Collection<VirtualFile> others = FilenameIndex.getVirtualFilesByName(project, MODULE_INFO_FILE, module.getModuleScope());
|
||||
if (others.size() > 1) {
|
||||
String message = JavaErrorMessages.message("module.file.duplicate");
|
||||
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range(element)).descriptionAndTooltip(message).create();
|
||||
|
||||
@@ -55,6 +55,11 @@ class ModuleHighlightingTest : LightJava9ModulesCodeInsightFixtureTestCase() {
|
||||
highlight("""<error descr="'module-info.java' already exists in the module">module M</error> { }""")
|
||||
}
|
||||
|
||||
fun testFileDuplicateInTestRoot() {
|
||||
addTestFile("module-info.java", """module M.test { }""")
|
||||
highlight("""<error descr="'module-info.java' already exists in the module">module M</error> { }""")
|
||||
}
|
||||
|
||||
fun testWrongFileLocation() {
|
||||
highlight("pkg/module-info.java", """<warning descr="Module declaration should be located in a module's source root">module M</warning> { }""")
|
||||
}
|
||||
|
||||
+3
@@ -31,4 +31,7 @@ abstract class LightJava9ModulesCodeInsightFixtureTestCase : LightCodeInsightFix
|
||||
|
||||
protected fun addFile(path: String, text: String, module: ModuleDescriptor = MAIN): VirtualFile =
|
||||
VfsTestUtil.createFile(module.root(), path, text)
|
||||
|
||||
protected fun addTestFile(path: String, text: String): VirtualFile =
|
||||
VfsTestUtil.createFile(MAIN.testRoot()!!, path, text)
|
||||
}
|
||||
+11
@@ -28,6 +28,8 @@ import com.intellij.openapi.vfs.ex.temp.TempFileSystem
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.testFramework.IdeaTestUtil
|
||||
import com.intellij.testFramework.LightPlatformTestCase
|
||||
import jdk.nashorn.internal.objects.NativeArray.forEach
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType
|
||||
|
||||
/**
|
||||
* Dependencies: 'main' -> 'm2', 'main' -> 'm4', 'main' -> 'm5', 'main' -> 'm6' => 'm7'
|
||||
@@ -44,6 +46,9 @@ object MultiModuleJava9ProjectDescriptor : DefaultLightProjectDescriptor() {
|
||||
|
||||
fun root(): VirtualFile =
|
||||
if (this == MAIN) LightPlatformTestCase.getSourceRoot() else TempFileSystem.getInstance().findFileByPath("/$rootName")!!
|
||||
|
||||
fun testRoot(): VirtualFile? =
|
||||
if (this == MAIN) TempFileSystem.getInstance().findFileByPath("/test_src")!! else null
|
||||
}
|
||||
|
||||
override fun getSdk(): Sdk = IdeaTestUtil.getMockJdk9()
|
||||
@@ -89,12 +94,18 @@ object MultiModuleJava9ProjectDescriptor : DefaultLightProjectDescriptor() {
|
||||
|
||||
override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension::class.java).languageLevel = LanguageLevel.JDK_1_9
|
||||
if (module.name == TEST_MODULE_NAME) {
|
||||
val testRoot = createSourceRoot(module, "test_src")
|
||||
registerSourceRoot(module.project, testRoot)
|
||||
model.addContentEntry(testRoot).addSourceFolder(testRoot, JavaSourceRootType.TEST_SOURCE)
|
||||
}
|
||||
}
|
||||
|
||||
fun cleanupSourceRoots() = runWriteAction {
|
||||
ModuleDescriptor.values().asSequence()
|
||||
.filter { it != ModuleDescriptor.MAIN }
|
||||
.flatMap { it.root().children.asSequence() }
|
||||
.plus(ModuleDescriptor.MAIN.testRoot()!!.children.asSequence())
|
||||
.forEach { it.delete(this) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user