Iterator<PsiFile> () { final Iterator<VirtualFile> iterator = myFileTree.getFileIterator(); return new Iterator<>() { @Override public boolean hasNext() { return iterator.hasNext(); } @Override public @Nullable PsiFile next() { VirtualFile vFile = iterator.next(); if (vFile == null || !vFile.isValid()) { return null; } PsiFile psiFile = PsiManager.getInstance(myProject).findFile(vFile); if (psiFile == null || !psiFile.isValid()) { return null; } return psiFile; } @Override public void remove() { throw new IllegalArgumentException(); } }; }