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;
}
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);
}
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);
}
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;
}
}
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;
}
Aggregations