summaryrefslogtreecommitdiff
path: root/src/main/java/org/javacs/SourceFileManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/javacs/SourceFileManager.java')
-rw-r--r--src/main/java/org/javacs/SourceFileManager.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main/java/org/javacs/SourceFileManager.java b/src/main/java/org/javacs/SourceFileManager.java
index b7e701e..dfef972 100644
--- a/src/main/java/org/javacs/SourceFileManager.java
+++ b/src/main/java/org/javacs/SourceFileManager.java
@@ -22,17 +22,30 @@ class SourceFileManager extends ForwardingJavaFileManager<StandardJavaFileManage
LOG.warning(error.getMessage(null));
}
+ private final LruCache<String, Iterable<JavaFileObject>> cacheClassPath = new LruCache<>(1000, this::listClassPath);
+
@Override
public Iterable<JavaFileObject> list(
Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException {
if (location == StandardLocation.SOURCE_PATH) {
var stream = FileStore.list(packageName).stream().map(this::asJavaFileObject);
return stream::iterator;
+ } else if (location == StandardLocation.CLASS_PATH) {
+ // Listing large class paths is expensive
+ return cacheClassPath.get(packageName);
} else {
return super.list(location, packageName, kinds, recurse);
}
}
+ private Iterable<JavaFileObject> listClassPath(String packageName) {
+ try {
+ return super.list(StandardLocation.CLASS_PATH, packageName, Set.of(JavaFileObject.Kind.values()), false);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
private JavaFileObject asJavaFileObject(Path file) {
return new SourceFileObject(file);
}