Java Code Examples for com.intellij.openapi.fileTypes.FileTypeManager#getInstance()
The following examples show how to use
com.intellij.openapi.fileTypes.FileTypeManager#getInstance() .
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: OCamlSourcesOrderRootTypeUIFactory.java From reasonml-idea-plugin with MIT License | 6 votes |
@NotNull List<VirtualFile> suggestOCamlRoots(@NotNull VirtualFile dir, @NotNull final ProgressIndicator progressIndicator) { if (!dir.isDirectory()) { return ContainerUtil.emptyList(); } final FileTypeManager typeManager = FileTypeManager.getInstance(); final ArrayList<VirtualFile> foundDirectories = new ArrayList<>(); try { VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() { @NotNull @Override public Result visitFileEx(@NotNull VirtualFile file) { progressIndicator.checkCanceled(); if (!file.isDirectory()) { FileType type = typeManager.getFileTypeByFileName(file.getName()); if (type.getDefaultExtension().equals("ml")) { VirtualFile root = file.getParent(); if (root != null) { foundDirectories.add(root); return skipTo(root); } } } return CONTINUE; } }); } catch (ProcessCanceledException ignore) { } return foundDirectories; }
Example 2
Source File: CodeInsightTestFixtureImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public PsiFile configureByText(final FileType fileType, @NonNls final String text) { assertInitialized(); final String extension = fileType.getDefaultExtension(); final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); if (fileTypeManager.getFileTypeByExtension(extension) != fileType) { new WriteCommandAction(getProject()) { @Override protected void run(Result result) throws Exception { fileTypeManager.associateExtension(fileType, extension); } }.execute(); } final String fileName = "aaa." + extension; return configureByText(fileName, text); }
Example 3
Source File: PolygeneApplicationComponent.java From attic-polygene-java with Apache License 2.0 | 5 votes |
public final FileTemplateGroupDescriptor getFileTemplatesDescriptor() { FileTemplateGroupDescriptor group = new FileTemplateGroupDescriptor( message( "polygene.file.template.group.title" ), null ); FileTypeManager fileTypeManager = FileTypeManager.getInstance(); for( @NonNls String template : FILE_TEMPLATES ) { Icon icon = fileTypeManager.getFileTypeByFileName( template ).getIcon(); group.addTemplate( new FileTemplateDescriptor( template, icon ) ); } return group; }
Example 4
Source File: TypeAssociationFix.java From intellij-pants-plugin with Apache License 2.0 | 5 votes |
@Override public void invoke(@NotNull final Project project, Editor editor, PsiFile psiFile) throws IncorrectOperationException { FileTypeManager manager = FileTypeManager.getInstance(); FileType type = manager.getFileTypeByFileName(psiFile.getName()); // Remove the BUILD file matcher from the wrong type then add it to PythonFileType for (FileNameMatcher matcher : manager.getAssociations(type)) { if (matcher.acceptsCharSequence(psiFile.getName())) { manager.removeAssociation(type, matcher); } } }
Example 5
Source File: IgnoreManager.java From idea-gitignore with MIT License | 5 votes |
/** * Associates given file with proper {@link IgnoreFileType}. * * @param fileName to associate * @param fileType file type to bind with pattern */ public static void associateFileType(@NotNull final String fileName, @NotNull final IgnoreFileType fileType) { final Application application = ApplicationManager.getApplication(); if (application.isDispatchThread()) { final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); application.invokeLater(() -> application.runWriteAction(() -> { fileTypeManager.associate(fileType, new ExactFileNameMatcher(fileName)); FILE_TYPES_ASSOCIATION_QUEUE.remove(fileName); }), ModalityState.NON_MODAL); } else if (!FILE_TYPES_ASSOCIATION_QUEUE.containsKey(fileName)) { FILE_TYPES_ASSOCIATION_QUEUE.put(fileName, fileType); } }
Example 6
Source File: VfsUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void processFileRecursivelyWithoutIgnored(@Nonnull final VirtualFile root, @Nonnull final Processor<VirtualFile> processor) { final FileTypeManager ftm = FileTypeManager.getInstance(); processFilesRecursively(root, processor, new Convertor<VirtualFile, Boolean>() { public Boolean convert(final VirtualFile vf) { return !ftm.isFileIgnored(vf); } }); }
Example 7
Source File: TranslatingCompilerFilesMonitorImpl.java From consulo with Apache License 2.0 | 5 votes |
public boolean isIgnoredOrUnderIgnoredDirectory(ProjectManager projectManager, VirtualFile file) { FileTypeManager fileTypeManager = FileTypeManager.getInstance(); if (fileTypeManager.isFileIgnored(file)) { return true; } //optimization: if file is in content of some project it's definitely not ignored boolean isInContent = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() { @Override public Boolean compute() { for (Project project : projectManager.getOpenProjects()) { if (project.isInitialized() && ProjectRootManager.getInstance(project).getFileIndex().isInContent(file)) { return true; } } return false; } }); if (isInContent) { return false; } VirtualFile current = file.getParent(); while (current != null) { if (fileTypeManager.isFileIgnored(current)) { return true; } current = current.getParent(); } return false; }
Example 8
Source File: CommonRefactoringUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void collectReadOnlyFiles(@Nonnull VirtualFile vFile, @Nonnull final Collection<VirtualFile> list) { final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); VfsUtilCore.visitChildrenRecursively(vFile, new VirtualFileVisitor(VirtualFileVisitor.NO_FOLLOW_SYMLINKS) { @Override public boolean visitFile(@Nonnull VirtualFile file) { final boolean ignored = fileTypeManager.isFileIgnored(file); if (!file.isWritable() && !ignored) { list.add(file); } return !ignored; } }); }
Example 9
Source File: VcsUtil.java From consulo with Apache License 2.0 | 5 votes |
/** * Collects all files which are located in the passed directory. * * @throws IllegalArgumentException if <code>dir</code> isn't a directory. */ public static void collectFiles(final VirtualFile dir, final List<VirtualFile> files, final boolean recursive, final boolean addDirectories) { if (!dir.isDirectory()) { throw new IllegalArgumentException(VcsBundle.message("exception.text.file.should.be.directory", dir.getPresentableUrl())); } final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() { @Override public boolean visitFile(@Nonnull VirtualFile file) { if (file.isDirectory()) { if (addDirectories) { files.add(file); } if (!recursive && !Comparing.equal(file, dir)) { return false; } } else if (fileTypeManager == null || file.getFileType() != UnknownFileType.INSTANCE) { files.add(file); } return true; } }); }
Example 10
Source File: LocalFilePath.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public FileType getFileType() { VirtualFile file = getVirtualFile(); FileTypeManager manager = FileTypeManager.getInstance(); return file != null ? manager.getFileTypeByFile(file) : manager.getFileTypeByFileName(getName()); }
Example 11
Source File: DirtBuilder.java From consulo with Apache License 2.0 | 5 votes |
public DirtBuilder(final VcsGuess guess) { myGuess = guess; myDirs = MultiMap.createSet(); myFiles = MultiMap.createSet(); myEverythingDirty = false; myFileTypeManager = FileTypeManager.getInstance(); }
Example 12
Source File: PsiVFSListener.java From consulo with Apache License 2.0 | 5 votes |
@Inject public PsiVFSListener(@Nonnull Project project, Provider<ProjectFileIndex> fileIndex) { installGlobalListener(); myProject = project; myFileTypeManager = FileTypeManager.getInstance(); myFileIndex = fileIndex; myManager = (PsiManagerImpl)PsiManager.getInstance(project); myFileManager = (FileManagerImpl)myManager.getFileManager(); if (project.isDefault()) { return; } // events must handled only after pre-startup (https://upsource.jetbrains.com/intellij/review/IDEA-CR-47395) StartupManager.getInstance(project).registerPreStartupActivity(() -> { MessageBusConnection connection = project.getMessageBus().connect(); connection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyModuleRootListener()); connection.subscribe(FileTypeManager.TOPIC, new FileTypeListener() { @Override public void fileTypesChanged(@Nonnull FileTypeEvent e) { myFileManager.processFileTypesChanged(e.getRemovedFileType() != null); } }); connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new MyFileDocumentManagerAdapter()); }); }
Example 13
Source File: PsiVFSListener.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private PsiFile createFileCopyWithNewName(VirtualFile vFile, String name) { // TODO[ik] remove this. Event handling and generation must be in view providers mechanism since we // need to track changes in _all_ psi views (e.g. namespace changes in XML) final FileTypeManager instance = FileTypeManager.getInstance(); if (instance.isFileIgnored(name)) return null; final FileType fileTypeByFileName = instance.getFileTypeByFileName(name); final Document document = FileDocumentManager.getInstance().getDocument(vFile); return PsiFileFactory.getInstance(myManager.getProject()) .createFileFromText(name, fileTypeByFileName, document != null ? document.getCharsSequence() : "", vFile.getModificationStamp(), true, false); }
Example 14
Source File: IgnoredFileFilter.java From consulo with Apache License 2.0 | 4 votes |
@Override public boolean accept(File file) { final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); final String name = file.getName(); return !fileTypeManager.isFileIgnored(name); }
Example 15
Source File: FileBasedIndexScanRunnableCollectorImpl.java From consulo with Apache License 2.0 | 4 votes |
@Inject public FileBasedIndexScanRunnableCollectorImpl(@Nonnull Project project) { this.myProject = project; this.myProjectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex(); this.myFileTypeManager = FileTypeManager.getInstance(); }