Skip to content

Commit 885a677

Browse files
committed
Walk the file tree lazily while looking for resolvers
1 parent ba9a74c commit 885a677

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

shared/src/main/kotlin/org/javacs/kt/classpath/DefaultClassPathResolver.kt

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,12 @@ private fun workspaceResolvers(workspaceRoot: Path): Sequence<ClassPathResolver>
1919
}
2020

2121
/** Searches the folder for all build-files. */
22-
private fun folderResolvers(root: Path, ignored: List<PathMatcher>): Collection<ClassPathResolver> {
23-
val resolvers = mutableListOf<ClassPathResolver>()
24-
25-
for (file in Files.walk(root)) {
26-
// Only test whether non-ignored file is a build-file
27-
if (ignored.none { it.matches(root.relativize(file)) }) {
28-
val resolver = asClassPathProvider(file)
29-
if (resolver != null) {
30-
resolvers.add(resolver)
31-
}
32-
}
33-
}
34-
35-
return resolvers
36-
}
22+
private fun folderResolvers(root: Path, ignored: List<PathMatcher>): Collection<ClassPathResolver> =
23+
root.toFile()
24+
.walk()
25+
.onEnter { file -> ignored.none { it.matches(root.relativize(file.toPath())) } }
26+
.mapNotNull { asClassPathProvider(it.toPath()) }
27+
.toList()
3728

3829
/** Tries to read glob patterns from a gitignore. */
3930
private fun ignoredPathPatterns(path: Path): List<PathMatcher> =

0 commit comments

Comments
 (0)