Java Code Examples for com.intellij.openapi.vfs.VirtualFile#isInLocalFileSystem()
The following examples show how to use
com.intellij.openapi.vfs.VirtualFile#isInLocalFileSystem() .
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: LineEndingsManager.java From editorconfig-jetbrains with MIT License | 6 votes |
private void applySettings(VirtualFile file) { if (file == null || !file.isInLocalFileSystem()) return; final String filePath = file.getCanonicalPath(); final List<EditorConfig.OutPair> outPairs = SettingsProviderComponent.getInstance().getOutPairs(filePath); final String lineEndings = Utils.configValueForKey(outPairs, lineEndingsKey); if (!lineEndings.isEmpty()) { try { LineSeparator separator = LineSeparator.valueOf(lineEndings.toUpperCase(Locale.US)); String oldSeparator = file.getDetectedLineSeparator(); String newSeparator = separator.getSeparatorString(); if (!StringUtil.equals(oldSeparator, newSeparator)) { file.setDetectedLineSeparator(newSeparator); if (!statusBarUpdated) { statusBarUpdated = true; updateStatusBar(); } LOG.debug(Utils.appliedConfigMessage(lineEndings, lineEndingsKey, filePath)); } } catch (IllegalArgumentException e) { LOG.warn(Utils.invalidConfigMessage(lineEndings, lineEndingsKey, filePath)); } } }
Example 2
Source File: EncodingManager.java From editorconfig-jetbrains with MIT License | 6 votes |
private void applySettings(VirtualFile file) { if (file == null || !file.isInLocalFileSystem()) return; // Prevent "setEncoding" calling "saveAll" from causing an endless loop isApplyingSettings = true; final String filePath = file.getCanonicalPath(); final List<OutPair> outPairs = SettingsProviderComponent.getInstance().getOutPairs(filePath); final EncodingProjectManager encodingProjectManager = EncodingProjectManager.getInstance(project); final String charset = Utils.configValueForKey(outPairs, charsetKey); if (!charset.isEmpty()) { if (encodingMap.containsKey(charset)) { encodingProjectManager.setEncoding(file, encodingMap.get(charset)); LOG.debug(Utils.appliedConfigMessage(charset, charsetKey, filePath)); } else { LOG.warn(Utils.invalidConfigMessage(charset, charsetKey, filePath)); } } isApplyingSettings = false; }
Example 3
Source File: Util.java From DarkyenusTimeTracker with The Unlicense | 5 votes |
@Nullable public static Path convertToIOFile(@Nullable VirtualFile file) { if (file == null || !file.isInLocalFileSystem()) { return null; } // Based on LocalFileSystemBase.java String path = file.getPath(); if (StringUtil.endsWithChar(path, ':') && path.length() == 2 && SystemInfo.isWindows) { path += "/"; } return Paths.get(path); }
Example 4
Source File: DocumentImpl.java From consulo with Apache License 2.0 | 5 votes |
private void assertWriteAccess() { if (myAssertThreading) { final Application application = ApplicationManager.getApplication(); if (application != null) { application.assertWriteAccessAllowed(); VirtualFile file = FileDocumentManager.getInstance().getFile(this); if (file != null && file.isInLocalFileSystem()) { ((TransactionGuardEx)TransactionGuard.getInstance()).assertWriteActionAllowed(); } } } }
Example 5
Source File: ESLintExternalAnnotator.java From eslint-plugin with MIT License | 5 votes |
@Nullable private static ExternalLintAnnotationInput collectInformation(@NotNull PsiFile psiFile, @Nullable Editor editor) { if (psiFile.getContext() != null) { return null; } VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile == null || !virtualFile.isInLocalFileSystem()) { return null; } if (psiFile.getViewProvider() instanceof MultiplePsiFilesPerDocumentFileViewProvider) { return null; } Project project = psiFile.getProject(); ESLintProjectComponent component = project.getComponent(ESLintProjectComponent.class); if (!component.isSettingsValid() || !component.isEnabled() || !isJavaScriptFile(psiFile, component.ext)) { return null; } Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile); if (document == null) { return null; } String fileContent = document.getText(); if (StringUtil.isEmptyOrSpaces(fileContent)) { return null; } EditorColorsScheme colorsScheme = editor == null ? null : editor.getColorsScheme(); // tabSize = getTabSize(editor); // tabSize = 4; return new ExternalLintAnnotationInput(project, psiFile, fileContent, colorsScheme); }
Example 6
Source File: RTExternalAnnotator.java From react-templates-plugin with MIT License | 5 votes |
@Nullable private static ExternalLintAnnotationInput collectInformation(@NotNull PsiFile psiFile, @Nullable Editor editor) { if (psiFile.getContext() != null || !RTFileUtil.isRTFile(psiFile)) { return null; } VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile == null || !virtualFile.isInLocalFileSystem()) { return null; } if (psiFile.getViewProvider() instanceof MultiplePsiFilesPerDocumentFileViewProvider) { return null; } Project project = psiFile.getProject(); RTProjectComponent component = project.getComponent(RTProjectComponent.class); if (component == null || !component.isValidAndEnabled()) { return null; } Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile); if (document == null) { return null; } String fileContent = document.getText(); if (StringUtil.isEmptyOrSpaces(fileContent)) { return null; } EditorColorsScheme colorsScheme = editor == null ? null : editor.getColorsScheme(); // tabSize = getTabSize(editor); // tabSize = 4; return new ExternalLintAnnotationInput(project, psiFile, fileContent, colorsScheme); }
Example 7
Source File: GraphQLConfigMigrationHelper.java From js-graphql-intellij-plugin with MIT License | 5 votes |
public static void checkGraphQLConfigJsonMigrations(Project project) { final Task.Backgroundable task = new Task.Backgroundable(project, "Verifying GraphQL Configuration", false) { @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setIndeterminate(true); final GlobalSearchScope scope = GlobalSearchScope.projectScope(project); final Collection<VirtualFile> legacyConfigFiles = ApplicationManager.getApplication().runReadAction( (Computable<Collection<VirtualFile>>) () -> FilenameIndex.getVirtualFilesByName(project, "graphql.config.json", scope) ); for (VirtualFile virtualFile : legacyConfigFiles) { if (!virtualFile.isDirectory() && virtualFile.isInLocalFileSystem()) { boolean migrate = true; for (String fileName : GraphQLConfigManager.GRAPHQLCONFIG_FILE_NAMES) { if (virtualFile.getParent().findChild(fileName) != null) { migrate = false; break; } } if (migrate) { createMigrationNotification(project, virtualFile); } } } } }; ProgressManager.getInstance().run(task); }
Example 8
Source File: RTExternalAnnotator.java From react-templates-plugin with MIT License | 5 votes |
@Nullable private static ExternalLintAnnotationInput collectInformation(@NotNull PsiFile psiFile, @Nullable Editor editor) { if (psiFile.getContext() != null || !RTFileUtil.isRTFile(psiFile)) { return null; } VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile == null || !virtualFile.isInLocalFileSystem()) { return null; } if (psiFile.getViewProvider() instanceof MultiplePsiFilesPerDocumentFileViewProvider) { return null; } Project project = psiFile.getProject(); RTProjectComponent component = project.getComponent(RTProjectComponent.class); if (component == null || !component.isValidAndEnabled()) { return null; } Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile); if (document == null) { return null; } String fileContent = document.getText(); if (StringUtil.isEmptyOrSpaces(fileContent)) { return null; } EditorColorsScheme colorsScheme = editor == null ? null : editor.getColorsScheme(); // tabSize = getTabSize(editor); // tabSize = 4; return new ExternalLintAnnotationInput(project, psiFile, fileContent, colorsScheme); }
Example 9
Source File: CompilerContentIterator.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean processFile(VirtualFile fileOrDir) { if (fileOrDir.isDirectory()) return true; if (!fileOrDir.isInLocalFileSystem()) return true; if (myInSourceOnly && !myFileIndex.isInSourceContent(fileOrDir)) return true; if (myFileType == null || myFileType == fileOrDir.getFileType()) { myFiles.add(fileOrDir); } return true; }
Example 10
Source File: CompileAction.java From consulo with Apache License 2.0 | 5 votes |
private static VirtualFile[] getCompilableFiles(Project project, VirtualFile[] files) { if (files == null || files.length == 0) { return VirtualFile.EMPTY_ARRAY; } final PsiManager psiManager = PsiManager.getInstance(project); final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); final CompilerManager compilerManager = CompilerManager.getInstance(project); final List<VirtualFile> filesToCompile = new ArrayList<VirtualFile>(); for (final VirtualFile file : files) { if (!fileIndex.isInSourceContent(file)) { continue; } if (!file.isInLocalFileSystem()) { continue; } if (file.isDirectory()) { final PsiDirectory directory = psiManager.findDirectory(file); if (directory == null || PsiPackageManager.getInstance(project).findAnyPackage(directory) == null) { continue; } } else { FileType fileType = file.getFileType(); if (!(compilerManager.isCompilableFileType(fileType) || isCompilableResourceFile(project, file))) { continue; } } filesToCompile.add(file); } return VfsUtil.toVirtualFileArray(filesToCompile); }
Example 11
Source File: LibraryPackagingElement.java From consulo with Apache License 2.0 | 5 votes |
public static PackagingElementOutputKind getKindForLibrary(final Library library) { boolean containsDirectories = false; boolean containsJars = false; for (VirtualFile file : library.getFiles(BinariesOrderRootType.getInstance())) { if (file.isInLocalFileSystem()) { containsDirectories = true; } else { containsJars = true; } } return new PackagingElementOutputKind(containsDirectories, containsJars); }
Example 12
Source File: FlutterPubspecNotificationProvider.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Nullable @Override public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor, @NotNull Project project) { if (!file.isInLocalFileSystem()) { return null; } // If the user has opted out of using pub in a project with both bazel rules and pub rules, // then we will default to bazel instead of pub. if (WorkspaceCache.getInstance(project).isBazel()) { return null; } // We only show this notification inside pubspec files. if (!PubRoot.isPubspec(file)) { return null; } // Check that this pubspec file declares flutter if (!FlutterUtils.declaresFlutter(file)) { return null; } if (FlutterSdk.getFlutterSdk(project) == null) { return null; } return new FlutterPubspecActionsPanel(project, file); }
Example 13
Source File: NativeEditorNotificationProvider.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Nullable @Override public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) { if (!file.isInLocalFileSystem() || !showNotification) { return null; } return createPanelForFile(file, findRootDir(file, myProject.getBaseDir())); }
Example 14
Source File: FlutterDependencyInspection.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Nullable @Override public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) { if (!isOnTheFly) return null; if (!(psiFile instanceof DartFile)) return null; if (DartPlugin.isPubActionInProgress()) return null; final VirtualFile file = FlutterUtils.getRealVirtualFile(psiFile); if (file == null || !file.isInLocalFileSystem()) return null; final Project project = psiFile.getProject(); // If the project should use bazel instead of pub, don't surface this warning. if (WorkspaceCache.getInstance(project).isBazel()) return null; if (!ProjectRootManager.getInstance(project).getFileIndex().isInContent(file)) return null; final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project); final Module module = ModuleUtilCore.findModuleForFile(file, project); if (!FlutterModuleUtils.isFlutterModule(module)) return null; final PubRoot root = PubRootCache.getInstance(project).getRoot(psiFile); if (root == null || myIgnoredPubspecPaths.contains(root.getPubspec().getPath())) return null; // TODO(pq): consider validating package name here (`get` will fail if it's invalid). if (root.getPackagesFile() == null) { return createProblemDescriptors(manager, psiFile, root, FlutterBundle.message("pub.get.not.run")); } if (!root.hasUpToDatePackages()) { return createProblemDescriptors(manager, psiFile, root, FlutterBundle.message("pubspec.edited")); } return null; }
Example 15
Source File: ArchivesBuilder.java From consulo with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private <T> void buildArchive(final ArchivePackageInfo archive) throws IOException { if (archive.getPackedFiles().isEmpty() && archive.getPackedArchives().isEmpty()) { myContext.addMessage(CompilerMessageCategory.WARNING, "Archive '" + archive.getPresentableDestination() + "' has no files so it won't be created", null, -1, -1); return; } myContext.getProgressIndicator().setText(CompilerBundle.message("packaging.compiler.message.building.0", archive.getPresentableDestination())); File tempFile = File.createTempFile("artifactCompiler", "tmp"); myBuiltArchives.put(archive, tempFile); FileUtil.createParentDirs(tempFile); ArchivePackageWriter<T> packageWriter = (ArchivePackageWriter<T>)archive.getPackageWriter(); T archiveFile; if (packageWriter instanceof ArchivePackageWriterEx) { archiveFile = ((ArchivePackageWriterEx<T>)packageWriter).createArchiveObject(tempFile, archive); } else { archiveFile = packageWriter.createArchiveObject(tempFile); } try { final THashSet<String> writtenPaths = new THashSet<>(); for (Pair<String, VirtualFile> pair : archive.getPackedFiles()) { final VirtualFile sourceFile = pair.getSecond(); if (sourceFile.isInLocalFileSystem()) { File file = VfsUtil.virtualToIoFile(sourceFile); addFileToArchive(archiveFile, packageWriter, file, pair.getFirst(), writtenPaths); } else { extractFileAndAddToArchive(archiveFile, packageWriter, sourceFile, pair.getFirst(), writtenPaths); } } for (Pair<String, ArchivePackageInfo> nestedArchive : archive.getPackedArchives()) { File nestedArchiveFile = myBuiltArchives.get(nestedArchive.getSecond()); if (nestedArchiveFile != null) { addFileToArchive(archiveFile, packageWriter, nestedArchiveFile, nestedArchive.getFirst(), writtenPaths); } else { LOGGER.debug("nested archive file " + nestedArchive.getFirst() + " for " + archive.getPresentableDestination() + " not found"); } } } catch (Exception e) { e.printStackTrace(); } finally { packageWriter.close(archiveFile); } }
Example 16
Source File: CamelRouteSearchScope.java From camel-idea-plugin with Apache License 2.0 | 4 votes |
@Override public boolean contains(@NotNull VirtualFile virtualFile) { return virtualFile.isInLocalFileSystem() && isAllowedFileExtension(virtualFile.getExtension()) && isAllowedFile(virtualFile.getPresentableName()); }
Example 17
Source File: VcsFileStatusProvider.java From consulo with Apache License 2.0 | 4 votes |
private boolean isHandledByVcs(@Nonnull VirtualFile file) { return file.isInLocalFileSystem() && myVcsManager.getVcsFor(file) != null; }
Example 18
Source File: IntelliUtils.java From floobits-intellij with Apache License 2.0 | 4 votes |
public static Boolean isSharable(VirtualFile virtualFile) { return (virtualFile != null && virtualFile.isValid() && virtualFile.isInLocalFileSystem() && !virtualFile.is(VFileProperty.SPECIAL) && !virtualFile.is(VFileProperty.SYMLINK)); }
Example 19
Source File: LocalFileExternalizer.java From consulo with Apache License 2.0 | 4 votes |
@Nullable public static LocalFileExternalizer tryCreate(VirtualFile file) { if (file == null || !file.isValid()) return null; if (!file.isInLocalFileSystem()) return null; return new LocalFileExternalizer(new File(file.getPath().replace('/', File.separatorChar))); }
Example 20
Source File: FlutterIconProvider.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Nullable public Icon getIcon(@NotNull final PsiElement element, @Iconable.IconFlags final int flags) { final Project project = element.getProject(); if (!FlutterModuleUtils.declaresFlutter(project)) return null; // Directories. if (element instanceof PsiDirectory) { final VirtualFile dir = ((PsiDirectory)element).getVirtualFile(); if (!dir.isInLocalFileSystem()) return null; final PubRootCache pubRootCache = PubRootCache.getInstance(project); // Show an icon for flutter modules. final PubRoot pubRoot = pubRootCache.getRoot(dir); if (pubRoot != null && dir.equals(pubRoot.getRoot()) && pubRoot.declaresFlutter()) { return FlutterIcons.Flutter; } final PubRoot root = pubRootCache.getRoot(dir.getParent()); if (root == null) return null; // TODO(devoncarew): should we just make the folder a source kind? if (dir.equals(root.getLib())) return AllIcons.Modules.SourceRoot; if (Objects.equals(dir, root.getAndroidDir())) return AllIcons.Nodes.KeymapTools; if (Objects.equals(dir, root.getiOsDir())) return AllIcons.Nodes.KeymapTools; if (dir.isDirectory() && dir.getName().equals(".idea")) return AllIcons.Modules.GeneratedFolder; } // Files. if (element instanceof DartFile) { final DartFile dartFile = (DartFile)element; final VirtualFile file = dartFile.getVirtualFile(); if (file == null || !file.isInLocalFileSystem()) return null; // Use a simple naming convention heuristic to identify test files. // TODO(pq): consider pushing up to the Dart Plugin. if (FlutterUtils.isInTestDir(dartFile) && file.getName().endsWith("_test.dart")) { return TEST_FILE; } } return null; }