Search in sources :

Example 1 with NonPhysicalFileSystem

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

the class FileStatusManagerImpl method getStatus.

@Override
public FileStatus getStatus(@NotNull final VirtualFile file) {
    if (file.getFileSystem() instanceof NonPhysicalFileSystem) {
        // do not leak light files via cache
        return FileStatus.SUPPRESSED;
    }
    FileStatus status = getCachedStatus(file);
    if (status == null || status == FileStatusNull.INSTANCE) {
        status = calcStatus(file);
        cacheChangedFileStatus(file, status);
    }
    return status;
}
Also used : FileStatus(com.intellij.openapi.vcs.FileStatus) NonPhysicalFileSystem(com.intellij.openapi.vfs.NonPhysicalFileSystem)

Example 2 with NonPhysicalFileSystem

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

the class PsiManagerImpl method isInProject.

@Override
public boolean isInProject(@NotNull PsiElement element) {
    if (element instanceof PsiDirectoryContainer) {
        PsiDirectory[] dirs = ((PsiDirectoryContainer) element).getDirectories();
        for (PsiDirectory dir : dirs) {
            if (!isInProject(dir))
                return false;
        }
        return true;
    }
    PsiFile file = element.getContainingFile();
    VirtualFile virtualFile = null;
    if (file != null) {
        virtualFile = file.getViewProvider().getVirtualFile();
    } else if (element instanceof PsiFileSystemItem) {
        virtualFile = ((PsiFileSystemItem) element).getVirtualFile();
    }
    if (file != null && file.isPhysical() && virtualFile.getFileSystem() instanceof NonPhysicalFileSystem)
        return true;
    return virtualFile != null && myFileIndex.isInContent(virtualFile);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonPhysicalFileSystem(com.intellij.openapi.vfs.NonPhysicalFileSystem)

Example 3 with NonPhysicalFileSystem

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

the class JavaProjectRootsUtil method isOutsideJavaSourceRoot.

public static boolean isOutsideJavaSourceRoot(@Nullable PsiFile psiFile) {
    if (psiFile == null)
        return false;
    if (psiFile instanceof PsiCodeFragment)
        return false;
    final VirtualFile file = psiFile.getVirtualFile();
    if (file == null)
        return false;
    if (file.getFileSystem() instanceof NonPhysicalFileSystem)
        return false;
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(psiFile.getProject()).getFileIndex();
    return !projectFileIndex.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES) && !projectFileIndex.isInLibrarySource(file) && !projectFileIndex.isInLibraryClasses(file);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiCodeFragment(com.intellij.psi.PsiCodeFragment) NonPhysicalFileSystem(com.intellij.openapi.vfs.NonPhysicalFileSystem)

Example 4 with NonPhysicalFileSystem

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

the class PerFileMappingsBase method getMappingInner.

@Nullable
protected T getMappingInner(@Nullable VirtualFile file, @Nullable Map<VirtualFile, T> mappings, @Nullable Key<T> pusherKey) {
    if (file instanceof VirtualFileWindow) {
        final VirtualFileWindow window = (VirtualFileWindow) file;
        file = window.getDelegate();
    }
    VirtualFile originalFile = file instanceof LightVirtualFile ? ((LightVirtualFile) file).getOriginalFile() : null;
    if (Comparing.equal(originalFile, file))
        originalFile = null;
    if (file != null) {
        final T pushedValue = pusherKey == null ? null : file.getUserData(pusherKey);
        if (pushedValue != null)
            return pushedValue;
    }
    if (originalFile != null) {
        final T pushedValue = pusherKey == null ? null : originalFile.getUserData(pusherKey);
        if (pushedValue != null)
            return pushedValue;
    }
    if (mappings == null)
        return null;
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (mappings) {
        T t = getMappingForHierarchy(file, mappings);
        if (t != null)
            return t;
        t = getMappingForHierarchy(originalFile, mappings);
        if (t != null)
            return t;
        Project project = getProject();
        if (project == null || file == null || file.getFileSystem() instanceof NonPhysicalFileSystem || ProjectFileIndex.getInstance(project).isInContent(file)) {
            return mappings.get(null);
        }
        return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Project(com.intellij.openapi.project.Project) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) NonPhysicalFileSystem(com.intellij.openapi.vfs.NonPhysicalFileSystem) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with NonPhysicalFileSystem

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

the class PsiUtilBase method findEditor.

/**
   * Tries to find editor for the given element.
   * <p/>
   * There are at least two approaches to achieve the target. Current method is intended to encapsulate both of them:
   * <ul>
   *   <li>target editor works with a real file that remains at file system;</li>
   *   <li>target editor works with a virtual file;</li>
   * </ul>
   * <p/>
   * Please don't use this method for finding an editor for quick fix.
   * @see {@link com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement}
   *
   * @param element   target element
   * @return          editor that works with a given element if the one is found; {@code null} otherwise
   */
@Nullable
public static Editor findEditor(@NotNull PsiElement element) {
    if (!EventQueue.isDispatchThread()) {
        LOG.warn("Invoke findEditor() from EDT only. Otherwise, it causes deadlocks.");
    }
    PsiFile psiFile = element.getContainingFile();
    VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
    if (virtualFile == null) {
        return null;
    }
    Project project = psiFile.getProject();
    if (virtualFile.isInLocalFileSystem() || virtualFile.getFileSystem() instanceof NonPhysicalFileSystem) {
        // Try to find editor for the real file.
        final FileEditor[] editors = FileEditorManager.getInstance(project).getEditors(virtualFile);
        for (FileEditor editor : editors) {
            if (editor instanceof TextEditor) {
                return ((TextEditor) editor).getEditor();
            }
        }
    }
    if (SwingUtilities.isEventDispatchThread()) {
        // We assume that data context from focus-based retrieval should success if performed from EDT.
        AsyncResult<DataContext> asyncResult = DataManager.getInstance().getDataContextFromFocus();
        if (asyncResult.isDone()) {
            Editor editor = CommonDataKeys.EDITOR.getData(asyncResult.getResult());
            if (editor != null) {
                Document cachedDocument = PsiDocumentManager.getInstance(project).getCachedDocument(psiFile);
                // Ensure that target editor is found by checking its document against the one from given PSI element.
                if (cachedDocument == editor.getDocument()) {
                    return editor;
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditor(com.intellij.openapi.fileEditor.FileEditor) DataContext(com.intellij.openapi.actionSystem.DataContext) TextEditor(com.intellij.openapi.fileEditor.TextEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Document(com.intellij.openapi.editor.Document) NonPhysicalFileSystem(com.intellij.openapi.vfs.NonPhysicalFileSystem) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

NonPhysicalFileSystem (com.intellij.openapi.vfs.NonPhysicalFileSystem)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Project (com.intellij.openapi.project.Project)2 Nullable (org.jetbrains.annotations.Nullable)2 VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 FileStatus (com.intellij.openapi.vcs.FileStatus)1 PsiCodeFragment (com.intellij.psi.PsiCodeFragment)1 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1