AA: allow directory as source roots
This commit is contained in:
committed by
Ilya Kirillov
parent
4af2fcd633
commit
87ba8525cf
+4
-4
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.analysis.project.structure.builder
|
package org.jetbrains.kotlin.analysis.project.structure.builder
|
||||||
|
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFileSystemItem
|
||||||
import org.jetbrains.kotlin.analysis.project.structure.KtSourceModule
|
import org.jetbrains.kotlin.analysis.project.structure.KtSourceModule
|
||||||
import org.jetbrains.kotlin.analysis.project.structure.impl.KtSourceModuleImpl
|
import org.jetbrains.kotlin.analysis.project.structure.impl.KtSourceModuleImpl
|
||||||
import org.jetbrains.kotlin.config.ApiVersion
|
import org.jetbrains.kotlin.config.ApiVersion
|
||||||
@@ -21,13 +21,13 @@ public class KtSourceModuleBuilder : KtModuleBuilder() {
|
|||||||
public lateinit var moduleName: String
|
public lateinit var moduleName: String
|
||||||
public var languageVersionSettings: LanguageVersionSettings =
|
public var languageVersionSettings: LanguageVersionSettings =
|
||||||
LanguageVersionSettingsImpl(LanguageVersion.LATEST_STABLE, ApiVersion.LATEST)
|
LanguageVersionSettingsImpl(LanguageVersion.LATEST_STABLE, ApiVersion.LATEST)
|
||||||
private val sourceRoots: MutableList<PsiFile> = mutableListOf()
|
private val sourceRoots: MutableList<PsiFileSystemItem> = mutableListOf()
|
||||||
|
|
||||||
public fun addSourceRoot(file: PsiFile) {
|
public fun addSourceRoot(file: PsiFileSystemItem) {
|
||||||
sourceRoots.add(file)
|
sourceRoots.add(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun addSourceRoots(files: Collection<PsiFile>) {
|
public fun addSourceRoots(files: Collection<PsiFileSystemItem>) {
|
||||||
sourceRoots.addAll(files)
|
sourceRoots.addAll(files)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
-5
@@ -9,7 +9,7 @@ import com.google.common.io.Files.getNameWithoutExtension
|
|||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.vfs.StandardFileSystems
|
import com.intellij.openapi.vfs.StandardFileSystems
|
||||||
import com.intellij.openapi.vfs.VirtualFileManager
|
import com.intellij.openapi.vfs.VirtualFileManager
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFileSystemItem
|
||||||
import com.intellij.psi.PsiManager
|
import com.intellij.psi.PsiManager
|
||||||
import com.intellij.psi.search.GlobalSearchScope
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
import com.intellij.psi.search.ProjectScope
|
import com.intellij.psi.search.ProjectScope
|
||||||
@@ -55,6 +55,7 @@ internal fun TargetPlatform.getAnalyzerServices(): PlatformDependentAnalyzerServ
|
|||||||
|
|
||||||
internal fun getSourceFilePaths(
|
internal fun getSourceFilePaths(
|
||||||
compilerConfig: CompilerConfiguration,
|
compilerConfig: CompilerConfiguration,
|
||||||
|
includeDirectoryRoot: Boolean = false,
|
||||||
): Set<String> {
|
): Set<String> {
|
||||||
return buildSet {
|
return buildSet {
|
||||||
compilerConfig.javaSourceRoots.forEach { srcRoot ->
|
compilerConfig.javaSourceRoots.forEach { srcRoot ->
|
||||||
@@ -64,6 +65,9 @@ internal fun getSourceFilePaths(
|
|||||||
Files.walk(path)
|
Files.walk(path)
|
||||||
.filter(java.nio.file.Files::isRegularFile)
|
.filter(java.nio.file.Files::isRegularFile)
|
||||||
.forEach { add(it.toString()) }
|
.forEach { add(it.toString()) }
|
||||||
|
if (includeDirectoryRoot) {
|
||||||
|
add(srcRoot)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// E.g., project/app/src/some/pkg/main.kt
|
// E.g., project/app/src/some/pkg/main.kt
|
||||||
add(srcRoot)
|
add(srcRoot)
|
||||||
@@ -72,7 +76,7 @@ internal fun getSourceFilePaths(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal inline fun <reified T : PsiFile> getPsiFilesFromPaths(
|
internal inline fun <reified T : PsiFileSystemItem> getPsiFilesFromPaths(
|
||||||
project: Project,
|
project: Project,
|
||||||
paths: Collection<String>,
|
paths: Collection<String>,
|
||||||
): List<T> {
|
): List<T> {
|
||||||
@@ -81,8 +85,12 @@ internal inline fun <reified T : PsiFile> getPsiFilesFromPaths(
|
|||||||
return buildList {
|
return buildList {
|
||||||
for (path in paths) {
|
for (path in paths) {
|
||||||
val vFile = fs.findFileByPath(path) ?: continue
|
val vFile = fs.findFileByPath(path) ?: continue
|
||||||
val psiFile = psiManager.findFile(vFile) as? T ?: continue
|
val psiFileSystemItem =
|
||||||
add(psiFile)
|
if (vFile.isDirectory)
|
||||||
|
psiManager.findDirectory(vFile) as? T
|
||||||
|
else
|
||||||
|
psiManager.findFile(vFile) as? T
|
||||||
|
psiFileSystemItem?.let { add(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,7 +158,12 @@ internal fun buildKtModuleProviderByCompilerConfiguration(
|
|||||||
this.platform = platform
|
this.platform = platform
|
||||||
this.project = project
|
this.project = project
|
||||||
this.moduleName = moduleName
|
this.moduleName = moduleName
|
||||||
addSourceRoots(getPsiFilesFromPaths(project, getSourceFilePaths(compilerConfig)))
|
addSourceRoots(
|
||||||
|
getPsiFilesFromPaths(
|
||||||
|
project,
|
||||||
|
getSourceFilePaths(compilerConfig, includeDirectoryRoot = true)
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -6,7 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.analysis.project.structure.impl
|
package org.jetbrains.kotlin.analysis.project.structure.impl
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFileSystemItem
|
||||||
import com.intellij.psi.search.GlobalSearchScope
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
import org.jetbrains.kotlin.analysis.project.structure.KtModule
|
import org.jetbrains.kotlin.analysis.project.structure.KtModule
|
||||||
import org.jetbrains.kotlin.analysis.project.structure.KtSourceModule
|
import org.jetbrains.kotlin.analysis.project.structure.KtSourceModule
|
||||||
@@ -23,7 +23,7 @@ internal class KtSourceModuleImpl(
|
|||||||
override val project: Project,
|
override val project: Project,
|
||||||
override val moduleName: String,
|
override val moduleName: String,
|
||||||
override val languageVersionSettings: LanguageVersionSettings,
|
override val languageVersionSettings: LanguageVersionSettings,
|
||||||
internal val sourceRoots: List<PsiFile>,
|
internal val sourceRoots: List<PsiFileSystemItem>,
|
||||||
) : KtSourceModule, KtModuleWithPlatform {
|
) : KtSourceModule, KtModuleWithPlatform {
|
||||||
override val analyzerServices: PlatformDependentAnalyzerServices = super.analyzerServices
|
override val analyzerServices: PlatformDependentAnalyzerServices = super.analyzerServices
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user