Java Code Examples for com.intellij.openapi.vfs.VirtualFile#isValid()
The following examples show how to use
com.intellij.openapi.vfs.VirtualFile#isValid() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
private boolean shouldResurrect(@Nonnull FileViewProvider viewProvider, @Nonnull VirtualFile file) { if (!file.isValid()) return false; Map<VirtualFile, FileViewProvider> tempProviders = myTempProviders.get(); if (tempProviders.containsKey(file)) { LOG.error(new StackOverflowPreventedException("isValid leads to endless recursion in " + viewProvider.getClass() + ": " + new ArrayList<>(viewProvider.getLanguages()))); } tempProviders.put(file, null); try { FileViewProvider recreated = createFileViewProvider(file, true); tempProviders.put(file, recreated); return areViewProvidersEquivalent(viewProvider, recreated) && ((AbstractFileViewProvider)viewProvider).getCachedPsiFiles().stream().noneMatch(f -> hasInvalidOriginal(f)); } finally { FileViewProvider temp = tempProviders.remove(file); if (temp != null) { DebugUtil.performPsiModification("invalidate temp view provider", () -> ((AbstractFileViewProvider)temp).markInvalidated()); } } }
Example 2
Source File: UndoRedo.java From consulo with Apache License 2.0 | 6 votes |
private Collection<VirtualFile> collectReadOnlyAffectedFiles() { Collection<VirtualFile> readOnlyFiles = new ArrayList<>(); for (UndoableAction action : myUndoableGroup.getActions()) { if (action instanceof MentionOnlyUndoableAction) continue; DocumentReference[] refs = action.getAffectedDocuments(); if (refs == null) continue; for (DocumentReference ref : refs) { VirtualFile file = ref.getFile(); if ((file != null) && file.isValid() && !file.isWritable()) { readOnlyFiles.add(file); } } } return readOnlyFiles; }
Example 3
Source File: VcsDescriptor.java From consulo with Apache License 2.0 | 6 votes |
public boolean probablyUnderVcs(final VirtualFile file) { if (file == null || (! file.isDirectory()) || (! file.isValid())) return false; if (myAdministrativePattern == null) return false; return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() { @Override public Boolean compute() { if (checkFileForBeingAdministrative(file)) return true; if (myCrawlUpToCheckUnderVcs) { VirtualFile current = file.getParent(); while (current != null) { if (checkFileForBeingAdministrative(current)) return true; current = current.getParent(); } } return false; } }); }
Example 4
Source File: DirectoryCopyPackagingElement.java From consulo with Apache License 2.0 | 5 votes |
@Override public void computeIncrementalCompilerInstructions(@Nonnull IncrementalCompilerInstructionCreator creator, @Nonnull PackagingElementResolvingContext resolvingContext, @Nonnull ArtifactIncrementalCompilerContext compilerContext, @Nonnull ArtifactType artifactType) { final VirtualFile file = findFile(); if (file != null && file.isValid() && file.isDirectory()) { creator.addDirectoryCopyInstructions(file); } }
Example 5
Source File: FactoryImpl.java From floobits-intellij with Apache License 2.0 | 5 votes |
@Override public IFile findFileByPath(String path) { String absPath = context.absPath(path); if (absPath == null) { return null; } VirtualFile fileByPath = instance.findFileByPath(absPath); if (fileByPath != null && fileByPath.isValid()) { return new FileImpl(fileByPath); } return null; }
Example 6
Source File: CompileContextImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public void recalculateOutputDirs() { final Module[] allModules = ModuleManager.getInstance(myProject).getModules(); final Set<VirtualFile> allDirs = new OrderedSet<VirtualFile>(); final Set<VirtualFile> testOutputDirs = new java.util.HashSet<VirtualFile>(); final Set<VirtualFile> productionOutputDirs = new java.util.HashSet<VirtualFile>(); for (Module module : allModules) { ModuleCompilerPathsManager moduleCompilerPathsManager = ModuleCompilerPathsManager.getInstance(module); final VirtualFile output = moduleCompilerPathsManager.getCompilerOutput(ProductionContentFolderTypeProvider.getInstance()); if (output != null && output.isValid()) { allDirs.add(output); productionOutputDirs.add(output); } final VirtualFile testsOutput = moduleCompilerPathsManager.getCompilerOutput(TestContentFolderTypeProvider.getInstance()); if (testsOutput != null && testsOutput.isValid()) { allDirs.add(testsOutput); testOutputDirs.add(testsOutput); } } myOutputDirectories = VfsUtil.toVirtualFileArray(allDirs); // need this to ensure that the sent contains only _dedicated_ test output dirs // Directories that are configured for both test and production classes must not be added in the resulting set testOutputDirs.removeAll(productionOutputDirs); myTestOutputDirectories = Collections.unmodifiableSet(testOutputDirs); }
Example 7
Source File: KnowledgeViewTreeBuilder.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
private void updateNodesContaining(@Nonnull Collection<VirtualFile> filesToRefresh, @Nonnull DefaultMutableTreeNode rootNode) { if (!(rootNode.getUserObject() instanceof ProjectViewNode)) { return; } ProjectViewNode node = (ProjectViewNode) rootNode.getUserObject(); Collection<VirtualFile> containingFiles = null; for (VirtualFile virtualFile : filesToRefresh) { if (!virtualFile.isValid()) { addSubtreeToUpdate(rootNode); // file must be deleted return; } if (node.contains(virtualFile)) { if (containingFiles == null) { containingFiles = new SmartList<VirtualFile>(); } containingFiles.add(virtualFile); } } if (containingFiles != null) { updateNode(rootNode); Enumeration children = rootNode.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); updateNodesContaining(containingFiles, child); } } }
Example 8
Source File: PathUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static String getLocalPath(@Nullable VirtualFile file) { if (file == null || !file.isValid()) { return null; } if (file.getFileSystem().getProtocol().equals(ArchiveFileSystem.ARCHIVE_SEPARATOR) && file.getParent() != null) { return null; } return getLocalPath(file.getPath()); }
Example 9
Source File: DocumentImpl.java From consulo with Apache License 2.0 | 5 votes |
private void beforeChangedUpdate(DocumentEvent event, DelayedExceptions exceptions) { Application app = ApplicationManager.getApplication(); if (app != null) { FileDocumentManager manager = FileDocumentManager.getInstance(); VirtualFile file = manager.getFile(this); if (file != null && !file.isValid()) { LOG.error("File of this document has been deleted: " + file); } } assertInsideCommand(); getLineSet(); // initialize line set to track changed lines if (!ShutDownTracker.isShutdownHookRunning()) { DocumentListener[] listeners = getListeners(); for (int i = listeners.length - 1; i >= 0; i--) { try { listeners[i].beforeDocumentChange(event); } catch (Throwable e) { exceptions.register(e); } } } myEventsHandling = true; }
Example 10
Source File: FileBasedIndexImpl.java From consulo with Apache License 2.0 | 5 votes |
static boolean belongsToScope(VirtualFile file, VirtualFile restrictedTo, GlobalSearchScope filter) { if (!(file instanceof VirtualFileWithId) || !file.isValid()) { return false; } return (restrictedTo == null || Comparing.equal(file, restrictedTo)) && (filter == null || restrictedTo != null || filter.accept(file)); }
Example 11
Source File: PsiFileUrl.java From consulo with Apache License 2.0 | 5 votes |
@Override public Object[] createPath(final Project project) { final VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url); if (file == null || !file.isValid()){ return null; } return new Object[]{PsiManager.getInstance(project).findFile(file)}; }
Example 12
Source File: TogglePopupHintsPanel.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private PsiFile getCurrentFile() { VirtualFile virtualFile = getSelectedFile(); if (virtualFile != null && virtualFile.isValid()) { return PsiManager.getInstance(getProject()).findFile(virtualFile); } return null; }
Example 13
Source File: BlazeSourceJarNavigationPolicy.java From intellij with Apache License 2.0 | 5 votes |
@Nullable private Result<PsiFile> getSourceFileResult(ClsFileImpl clsFile, VirtualFile root) { // This code is adapted from JavaPsiImplementationHelperImpl#getClsFileNavigationElement PsiClass[] classes = clsFile.getClasses(); if (classes.length == 0) { return null; } String sourceFileName = ((ClsClassImpl) classes[0]).getSourceFileName(); String packageName = clsFile.getPackageName(); String relativePath = packageName.isEmpty() ? sourceFileName : packageName.replace('.', '/') + '/' + sourceFileName; VirtualFile source = root.findFileByRelativePath(relativePath); if (source != null && source.isValid()) { // Since we have an actual source jar tracked down, use that source jar as the modification // tracker. This means the result will continue to be cached unless that source jar changes. // If we didn't find a source jar, we use a modification tracker that invalidates on every // Blaze sync, which is less efficient. PsiFile psiSource = clsFile.getManager().findFile(source); if (psiSource instanceof PsiClassOwner) { return Result.create(psiSource, source); } return Result.create(null, source); } return null; }
Example 14
Source File: BxCore.java From bxfs with MIT License | 5 votes |
public VirtualFile[] getSiteTemplatesComponents(String templateComponent) { List<VirtualFile> templates = new ArrayList<VirtualFile>(); for (String bitrixPath : BitrixPaths) { VirtualFile templatesDir = project.getBaseDir().findFileByRelativePath(bitrixPath + "/templates"); if (templatesDir != null && templatesDir.isDirectory()) { for (VirtualFile templateDir : templatesDir.getChildren()) if (templateDir != null && templateDir.isDirectory()) { VirtualFile component = templateDir.findChild(templateComponent); if (component != null && !component.isDirectory() && component.isValid()) templates.add(component); } } } return templates.toArray(new VirtualFile[templates.size()]); }
Example 15
Source File: PsiNavigateUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void navigate(@Nullable final PsiElement psiElement) { if (psiElement != null && psiElement.isValid()) { final PsiElement navigationElement = psiElement.getNavigationElement(); final int offset = navigationElement instanceof PsiFile ? -1 : navigationElement.getTextOffset(); final VirtualFile virtualFile = navigationElement.getContainingFile().getVirtualFile(); if (virtualFile != null && virtualFile.isValid()) { new OpenFileDescriptor(navigationElement.getProject(), virtualFile, offset).navigate(true); } } }
Example 16
Source File: PerFileMappingsBase.java From consulo with Apache License 2.0 | 5 votes |
private void cleanup() { for (Iterator<VirtualFile> i = myMappings.keySet().iterator(); i.hasNext();) { VirtualFile file = i.next(); if (file != null /* PROJECT, top-level */ && !file.isValid()) { i.remove(); } } }
Example 17
Source File: FileChooserDescriptor.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull protected static Image dressIcon(final VirtualFile file, final Image baseIcon) { return file.isValid() && file.is(VFileProperty.SYMLINK) ? ImageEffects.layered(baseIcon, AllIcons.Nodes.Symlink) : baseIcon; }
Example 18
Source File: FileElement.java From consulo with Apache License 2.0 | 4 votes |
public static boolean isFileHidden(@Nullable VirtualFile file) { return file != null && file.isValid() && file.isInLocalFileSystem() && (file.is(VFileProperty.HIDDEN) || SystemInfo.isUnix && file.getName().startsWith(".")); }
Example 19
Source File: FileTreeModel.java From consulo with Apache License 2.0 | 4 votes |
private static boolean isValid(VirtualFile file) { return file != null && file.isValid(); }
Example 20
Source File: PsiDocumentManagerBase.java From consulo with Apache License 2.0 | 4 votes |
@Override public PsiFile getCachedPsiFile(@Nonnull Document document) { final VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document); if (virtualFile == null || !virtualFile.isValid()) return null; return getCachedPsiFile(virtualFile); }