Skip to content

Commit

Permalink
Incorrect default test root on antlr project #1017
Browse files Browse the repository at this point in the history
  • Loading branch information
Vassiliy-Kudryashov committed Oct 26, 2022
1 parent 195999f commit f8db8ce
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.components.service
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleUtil
import com.intellij.openapi.options.ShowSettingsUtil
import com.intellij.openapi.projectRoots.JavaSdkVersion
import com.intellij.openapi.roots.ContentEntry
import com.intellij.openapi.roots.DependencyScope
import com.intellij.openapi.roots.ExternalLibraryDescriptor
import com.intellij.openapi.roots.JavaProjectModelModificationService
Expand Down Expand Up @@ -423,11 +423,13 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
return null
}

private fun VirtualFile.toRealFile():VirtualFile = if (this is FakeVirtualFile) this.parent else this

override fun doValidate(): ValidationInfo? {
val testRoot = getTestRoot()
?: return ValidationInfo("Test source root is not configured", testSourceFolderField.childComponent)

if (!model.project.isBuildWithGradle && findReadOnlyContentEntry(testRoot) == null) {
if (!model.project.isBuildWithGradle && ModuleUtil.findModuleForFile(testRoot.toRealFile(), model.project) == null) {
return ValidationInfo("Test source root is located out of content entry", testSourceFolderField.childComponent)
}

Expand Down Expand Up @@ -606,16 +608,6 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
"Generation error"
)

private fun findReadOnlyContentEntry(testSourceRoot: VirtualFile?): ContentEntry? {
if (testSourceRoot == null) return null
if (testSourceRoot is FakeVirtualFile) {
return findReadOnlyContentEntry(testSourceRoot.parent)
}
return ModuleRootManager.getInstance(model.testModule).contentEntries
.filterNot { it.file == null }
.firstOrNull { VfsUtil.isAncestor(it.file!!, testSourceRoot, false) }
}

private fun getOrCreateTestRoot(testSourceRoot: VirtualFile): Boolean {
val modifiableModel = ModuleRootManager.getInstance(model.testModule).modifiableModel
try {
Expand Down

0 comments on commit f8db8ce

Please sign in to comment.