Skip to content

Instantly share code, notes, and snippets.

@bartekpacia
Created September 26, 2025 17:43
Show Gist options
  • Select an option

  • Save bartekpacia/d0d3cb9391251d96ea4dbf2570c3a73a to your computer and use it in GitHub Desktop.

Select an option

Save bartekpacia/d0d3cb9391251d96ea4dbf2570c3a73a to your computer and use it in GitHub Desktop.
adsad
@bartekpacia
Copy link
Author

Find modules in a project:

ModuleManager.getInstance(getProject()).getModules()

@bartekpacia
Copy link
Author

Find current JDK used, by the PSI element:

ModuleRootManager.getInstance(ModuleUtilCore.findModuleForPsiElement(typeCast)).getSdk()

@bartekpacia
Copy link
Author

FileBasedIndex index = FileBasedIndex.getInstance();
Collection<VirtualFile> allFiles = new HashSet<>();

index.processAllKeys(FileTypeIndex.NAME, fileType -> {
  Collection<VirtualFile> files = FileTypeIndex.getFiles(fileType, element.getResolveScope());
  for (var file : files) {
    if (file.getPath().contains("openjdk.jdk")) continue;
    if (file.getPath().contains(".gradle/caches")) continue;
    allFiles.add(file);
  }
  return true;
}, element.getProject());

return allFiles;

@bartekpacia
Copy link
Author

bartekpacia commented Sep 26, 2025

List all files in GlobalSearchScope of some library:

FileTypeIndex.getFiles(JavaClassFileType.INSTANCE, LibraryScopeCache.getInstance(element.getProject()).myLibrariesOnlyScope).stream()
  .map(vf -> vf.getPath())
  .filter(name -> name.contains("demo_cucumber"))
  .toList()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment