Skip to content

Commit a1fbbac

Browse files
style: spotless reformat, no functional change
1 parent d91dfbe commit a1fbbac

2 files changed

Lines changed: 76 additions & 66 deletions

File tree

‎lsp/kotlin/src/main/java/com/itsaky/androidide/lsp/kotlin/compiler/WorkspaceExts.kt‎

Lines changed: 71 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -19,76 +19,82 @@ private val logger = LoggerFactory.getLogger("WorkspaceExts")
1919

2020
internal fun Workspace.collectKtModules(
2121
project: Project,
22-
appEnv: CoreApplicationEnvironment
23-
): List<KtModule> = buildList {
24-
fun addModule(module: KtModule) = add(module)
25-
26-
val moduleProjects = subProjects
27-
.asSequence()
28-
.filterIsInstance<ModuleProject>()
29-
.filter { it.path != rootProject.path }
30-
31-
val jarToModMap = mutableMapOf<Path, KtLibraryModule>()
32-
33-
// One module per jar: every module shares android.jar, and each KtLibraryModule
34-
// materializes the jar's full file list for its search scope (ADFA-6381).
35-
fun addLibrary(path: Path): KtLibraryModule =
36-
jarToModMap.getOrPut(path) {
37-
buildKtLibraryModule(project, appEnv) {
38-
id = path.pathString
39-
addContentRoot(path)
22+
appEnv: CoreApplicationEnvironment,
23+
): List<KtModule> =
24+
buildList {
25+
fun addModule(module: KtModule) = add(module)
26+
27+
val moduleProjects =
28+
subProjects
29+
.asSequence()
30+
.filterIsInstance<ModuleProject>()
31+
.filter { it.path != rootProject.path }
32+
33+
val jarToModMap = mutableMapOf<Path, KtLibraryModule>()
34+
35+
// One module per jar: every module shares android.jar, and each KtLibraryModule
36+
// materializes the jar's full file list for its search scope (ADFA-6381).
37+
fun addLibrary(path: Path): KtLibraryModule =
38+
jarToModMap.getOrPut(path) {
39+
buildKtLibraryModule(project, appEnv) {
40+
id = path.pathString
41+
addContentRoot(path)
42+
}
4043
}
41-
}
4244

43-
// A List, not a Sequence: a Sequence would re-run addLibrary for every source module below.
44-
val bootClassPaths = moduleProjects
45-
.filterIsInstance<AndroidModule>()
46-
.flatMap { it.bootClassPaths.asSequence() }
47-
.filter { it.exists() }
48-
.map { it.toPath() }
49-
.distinct()
50-
.map(::addLibrary)
51-
.toList()
52-
53-
val libraryDependencies = moduleProjects
54-
.flatMap { it.getCompileClasspaths() }
55-
.filter { it.exists() }
56-
.map { it.toPath() }
57-
.associateWith(::addLibrary)
58-
59-
val subprojectsAsModules = mutableMapOf<ModuleProject, KtSourceModule>()
60-
val sourceRootToModuleMap = mutableMapOf<Path, KtSourceModule>()
61-
62-
fun getOrCreateModule(moduleProject: ModuleProject): KtSourceModule {
63-
subprojectsAsModules[moduleProject]?.let { return it }
64-
65-
val module = buildKtSourceModule(project) {
66-
this.module = moduleProject
67-
68-
bootClassPaths.forEach { addDependency(it) }
69-
70-
moduleProject.getCompileClasspaths(excludeSourceGeneratedClassPath = true)
71-
.forEach { classpath ->
72-
val libDep = libraryDependencies[classpath.toPath()]
73-
if (libDep == null) {
74-
logger.error(
75-
"Skipping non-existent classpath classpath: {}",
76-
classpath
77-
)
78-
return@forEach
45+
// A List, not a Sequence: a Sequence would re-run addLibrary for every source module below.
46+
val bootClassPaths =
47+
moduleProjects
48+
.filterIsInstance<AndroidModule>()
49+
.flatMap { it.bootClassPaths.asSequence() }
50+
.filter { it.exists() }
51+
.map { it.toPath() }
52+
.distinct()
53+
.map(::addLibrary)
54+
.toList()
55+
56+
val libraryDependencies =
57+
moduleProjects
58+
.flatMap { it.getCompileClasspaths() }
59+
.filter { it.exists() }
60+
.map { it.toPath() }
61+
.associateWith(::addLibrary)
62+
63+
val subprojectsAsModules = mutableMapOf<ModuleProject, KtSourceModule>()
64+
val sourceRootToModuleMap = mutableMapOf<Path, KtSourceModule>()
65+
66+
fun getOrCreateModule(moduleProject: ModuleProject): KtSourceModule {
67+
subprojectsAsModules[moduleProject]?.let { return it }
68+
69+
val module =
70+
buildKtSourceModule(project) {
71+
this.module = moduleProject
72+
73+
bootClassPaths.forEach { addDependency(it) }
74+
75+
moduleProject
76+
.getCompileClasspaths(excludeSourceGeneratedClassPath = true)
77+
.forEach { classpath ->
78+
val libDep = libraryDependencies[classpath.toPath()]
79+
if (libDep == null) {
80+
logger.error(
81+
"Skipping non-existent classpath classpath: {}",
82+
classpath,
83+
)
84+
return@forEach
85+
}
86+
addDependency(libDep)
87+
}
88+
89+
moduleProject.getCompileModuleProjects().forEach { dep ->
90+
addDependency(getOrCreateModule(dep))
7991
}
80-
addDependency(libDep)
8192
}
8293

83-
moduleProject.getCompileModuleProjects().forEach { dep ->
84-
addDependency(getOrCreateModule(dep))
85-
}
94+
subprojectsAsModules[moduleProject] = module
95+
module.contentRoots.forEach { root -> sourceRootToModuleMap[root] = module }
96+
return module
8697
}
8798

88-
subprojectsAsModules[moduleProject] = module
89-
module.contentRoots.forEach { root -> sourceRootToModuleMap[root] = module }
90-
return module
99+
moduleProjects.forEach { addModule(getOrCreateModule(it)) }
91100
}
92-
93-
moduleProjects.forEach { addModule(getOrCreateModule(it)) }
94-
}

‎lsp/kotlin/src/test/java/com/itsaky/androidide/lsp/kotlin/compiler/CollectKtModulesTest.kt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import kotlin.io.path.pathString
1515
class CollectKtModulesTest : KtLspTest() {
1616
@Test
1717
fun `modules sharing android jar share one library module`() {
18-
val androidJar = lspTestRule.tempDir.root.toPath().resolve("android.jar").createFile()
18+
val androidJar =
19+
lspTestRule.tempDir.root
20+
.toPath()
21+
.resolve("android.jar")
22+
.createFile()
1923
val modulePaths = listOf(":a", ":b", ":c")
2024
val workspace =
2125
Workspace(

0 commit comments

Comments
 (0)