3 comments
Comment actions Permalink

Hello Oleg,

How to get in the language plugin all PsiFiles or certain file by name
from the project?


Please see http://confluence.jetbrains.net/display/IDEADEV/IntelliJIDEAArchitectural+Overview
for more information. Note that in most cases you don't ever need to get
all PsiFiles (that would be unusably slow in a real-life-sized project in
any language).

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

The only solution I found is the next:

public static List<PsiFile> allProjectFiles(@NotNull Project project) {
final PsiManager psiManager = PsiManager.getInstance(project);
final PsiDirectory prjDirectory = psiManager.findDirectory(project.getBaseDir());
return prjDirectory != null ? getFilesRecursively(prjDirectory) : Collections.emptyList();
}

private static List<PsiFile> getFilesRecursively(@NotNull PsiDirectory psiDirectory) {
List<PsiFile> psiFileList = new ArrayList<>(Arrays.asList(psiDirectory.getFiles()));
for (PsiDirectory subDir : psiDirectory.getSubdirectories()) {
psiFileList.addAll(getFilesRecursively(subDir));
}
return psiFileList;
}

Unfortunately, deprecated Project#getBaseDir() method is used here...

Will appreciate for any better solution. (Dmitry Jemerov ?)

0
Comment actions Permalink

As I wrote above, this code will be unusably slow in any real-life project. A better solution is to find an approach to solving your issue that does not require getting all PSI files in a project.

1

Please sign in to leave a comment.