Search in sources :

Example 1 with NewVirtualFile

use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.

the class UnixPythonSdkFlavor method collectUnixPythons.

public static void collectUnixPythons(String path, Set<String> candidates) {
    VirtualFile rootDir = LocalFileSystem.getInstance().findFileByPath(path);
    if (rootDir != null) {
        if (rootDir instanceof NewVirtualFile) {
            ((NewVirtualFile) rootDir).markDirty();
        }
        rootDir.refresh(true, false);
        VirtualFile[] suspects = rootDir.getChildren();
        for (VirtualFile child : suspects) {
            if (!child.isDirectory()) {
                final String childName = child.getName().toLowerCase();
                for (String name : NAMES) {
                    if (childName.startsWith(name) || PYTHON_RE.matcher(childName).matches()) {
                        String childPath = child.getPath();
                        if (FileSystemUtil.isSymLink(childPath)) {
                            childPath = FileSystemUtil.resolveSymLink(childPath);
                        }
                        if (childPath != null && !childName.endsWith("-config") && !childName.startsWith("pythonw") && !childName.endsWith("m") && !candidates.contains(childPath)) {
                            candidates.add(childPath);
                        }
                        break;
                    }
                }
            }
        }
    }
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile)

Example 2 with NewVirtualFile

use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.

the class StudyProjectGenerator method openFirstTask.

public static void openFirstTask(@NotNull final Course course, @NotNull final Project project) {
    LocalFileSystem.getInstance().refresh(false);
    final Lesson firstLesson = StudyUtils.getFirst(course.getLessons());
    if (firstLesson == null)
        return;
    final Task firstTask = StudyUtils.getFirst(firstLesson.getTaskList());
    if (firstTask == null)
        return;
    final VirtualFile taskDir = firstTask.getTaskDir(project);
    if (taskDir == null)
        return;
    final Map<String, TaskFile> taskFiles = firstTask.getTaskFiles();
    VirtualFile activeVirtualFile = null;
    for (Map.Entry<String, TaskFile> entry : taskFiles.entrySet()) {
        final String relativePath = entry.getKey();
        final TaskFile taskFile = entry.getValue();
        taskDir.refresh(false, true);
        final VirtualFile virtualFile = taskDir.findFileByRelativePath(relativePath);
        if (virtualFile != null) {
            if (!taskFile.getActivePlaceholders().isEmpty()) {
                activeVirtualFile = virtualFile;
            }
        }
    }
    if (activeVirtualFile != null) {
        final PsiFile file = PsiManager.getInstance(project).findFile(activeVirtualFile);
        ProjectView.getInstance(project).select(file, activeVirtualFile, false);
        final FileEditor[] editors = FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
        if (editors.length == 0) {
            return;
        }
        final FileEditor studyEditor = editors[0];
        if (studyEditor instanceof StudyEditor) {
            StudyUtils.selectFirstAnswerPlaceholder((StudyEditor) studyEditor, project);
        }
        FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
    } else {
        String first = StudyUtils.getFirst(taskFiles.keySet());
        if (first != null) {
            NewVirtualFile firstFile = ((VirtualDirectoryImpl) taskDir).refreshAndFindChild(first);
            if (firstFile != null) {
                FileEditorManager.getInstance(project).openFile(firstFile, true);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Task(com.jetbrains.edu.learning.courseFormat.Task) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) VirtualDirectoryImpl(com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl) PsiFile(com.intellij.psi.PsiFile) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor)

Example 3 with NewVirtualFile

use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.

the class DumpVfsInfoForExcludedFilesAction method dumpChildrenInDbRecursively.

private static void dumpChildrenInDbRecursively(VirtualFile dir, int depth) {
    if (!(dir instanceof NewVirtualFile)) {
        System.out.println(dir.getPresentableUrl() + ": not in db (" + dir.getClass().getName() + ")");
        return;
    }
    List<VirtualFile> dirs = new ArrayList<>();
    int inDb = 0, contentInDb = 0, nullChildren = 0;
    PersistentFS persistentFS = PersistentFS.getInstance();
    if (persistentFS.wereChildrenAccessed(dir)) {
        for (String name : persistentFS.listPersisted(dir)) {
            inDb++;
            NewVirtualFile child = ((NewVirtualFile) dir).refreshAndFindChild(name);
            if (child == null) {
                nullChildren++;
                continue;
            }
            if (child.isDirectory()) {
                dirs.add(child);
            } else if (FSRecords.getContentId(child.getId()) != 0) {
                contentInDb++;
            }
        }
    }
    System.out.print(dir.getPresentableUrl() + ": " + inDb + " children in db");
    if (contentInDb > 0) {
        System.out.print(", content of " + contentInDb + " files in db");
    }
    if (nullChildren > 0) {
        System.out.print(", " + nullChildren + " invalid files in db");
    }
    System.out.println();
    if (depth > 10) {
        System.out.println("too deep, skipping children");
    } else {
        for (VirtualFile childDir : dirs) {
            dumpChildrenInDbRecursively(childDir, depth + 1);
        }
    }
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) PersistentFS(com.intellij.openapi.vfs.newvfs.persistent.PersistentFS)

Example 4 with NewVirtualFile

use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.

the class LoadAllVfsStoredContentsAction method iterateCached.

private void iterateCached(VirtualFile root) {
    processFile((NewVirtualFile) root);
    Collection<VirtualFile> children = ((NewVirtualFile) root).getCachedChildren();
    for (VirtualFile child : children) {
        iterateCached(child);
    }
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile)

Example 5 with NewVirtualFile

use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.

the class PsiFileGistImpl method shouldUseMemoryStorage.

private static boolean shouldUseMemoryStorage(PsiFile file) {
    if (!(file.getVirtualFile() instanceof NewVirtualFile))
        return true;
    PsiDocumentManager pdm = PsiDocumentManager.getInstance(file.getProject());
    Document document = pdm.getCachedDocument(file);
    return document != null && (pdm.isUncommited(document) || FileDocumentManager.getInstance().isDocumentUnsaved(document));
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) Document(com.intellij.openapi.editor.Document) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Aggregations

NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 File (java.io.File)4 VirtualDirectoryImpl (com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 JobLauncher (com.intellij.concurrency.JobLauncher)1 JobSchedulerImpl (com.intellij.concurrency.JobSchedulerImpl)1 Language (com.intellij.lang.Language)1 ParserDefinition (com.intellij.lang.ParserDefinition)1 Application (com.intellij.openapi.application.Application)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Document (com.intellij.openapi.editor.Document)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 FileType (com.intellij.openapi.fileTypes.FileType)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 Project (com.intellij.openapi.project.Project)1 Disposer (com.intellij.openapi.util.Disposer)1 Ref (com.intellij.openapi.util.Ref)1