[Analysis API Standalone] refactoring, use Path instead of String for path representation

^KT-60884
This commit is contained in:
Ilya Kirillov
2023-08-29 20:50:10 +02:00
committed by Space Team
parent eb2c4e4015
commit e6bd34b671
@@ -63,7 +63,7 @@ internal fun TargetPlatform.getAnalyzerServices(): PlatformDependentAnalyzerServ
internal fun getSourceFilePaths( internal fun getSourceFilePaths(
compilerConfig: CompilerConfiguration, compilerConfig: CompilerConfiguration,
includeDirectoryRoot: Boolean = false, includeDirectoryRoot: Boolean = false,
): Set<String> { ): Set<Path> {
return buildSet { return buildSet {
compilerConfig.javaSourceRoots.forEach { srcRoot -> compilerConfig.javaSourceRoots.forEach { srcRoot ->
val path = Paths.get(srcRoot) val path = Paths.get(srcRoot)
@@ -71,11 +71,11 @@ internal fun getSourceFilePaths(
// E.g., project/app/src // E.g., project/app/src
collectSourceFilePaths(path, this) collectSourceFilePaths(path, this)
if (includeDirectoryRoot) { if (includeDirectoryRoot) {
add(srcRoot) add(path)
} }
} else { } else {
// E.g., project/app/src/some/pkg/main.kt // E.g., project/app/src/some/pkg/main.kt
add(srcRoot) add(path)
} }
} }
} }
@@ -91,7 +91,7 @@ internal fun getSourceFilePaths(
*/ */
private fun collectSourceFilePaths( private fun collectSourceFilePaths(
root: Path, root: Path,
result: MutableSet<String> result: MutableSet<Path>
) { ) {
// NB: [Files#walk] throws an exception if there is an issue during IO. // NB: [Files#walk] throws an exception if there is an issue during IO.
// With [Files#walkFileTree] with a custom visitor, we can take control of exception handling. // With [Files#walkFileTree] with a custom visitor, we can take control of exception handling.
@@ -113,7 +113,7 @@ private fun collectSourceFilePaths(
ext == KotlinParserDefinition.STD_SCRIPT_SUFFIX || ext == KotlinParserDefinition.STD_SCRIPT_SUFFIX ||
ext == JavaFileType.DEFAULT_EXTENSION ext == JavaFileType.DEFAULT_EXTENSION
) { ) {
result.add(file.toString()) result.add(file)
} }
return FileVisitResult.CONTINUE return FileVisitResult.CONTINUE
} }
@@ -131,13 +131,13 @@ private fun collectSourceFilePaths(
internal inline fun <reified T : PsiFileSystemItem> getPsiFilesFromPaths( internal inline fun <reified T : PsiFileSystemItem> getPsiFilesFromPaths(
project: Project, project: Project,
paths: Collection<String>, paths: Collection<Path>,
): List<T> { ): List<T> {
val fs = StandardFileSystems.local() val fs = StandardFileSystems.local()
val psiManager = PsiManager.getInstance(project) val psiManager = PsiManager.getInstance(project)
return buildList { return buildList {
for (path in paths) { for (path in paths) {
val vFile = fs.findFileByPath(path) ?: continue val vFile = fs.findFileByPath(path.toString()) ?: continue
val psiFileSystemItem = val psiFileSystemItem =
if (vFile.isDirectory) if (vFile.isDirectory)
psiManager.findDirectory(vFile) as? T psiManager.findDirectory(vFile) as? T