Search in sources :

Example 1 with FileTypeManager

use of com.intellij.openapi.fileTypes.FileTypeManager in project intellij-community by JetBrains.

the class PythonLanguageLevelPusher method markRecursively.

private void markRecursively(final Project project, @NotNull final VirtualFile file, final LanguageLevel languageLevel, final boolean suppressSizeLimit) {
    final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
    VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {

        @Override
        public boolean visitFile(@NotNull VirtualFile file) {
            if (fileTypeManager.isFileIgnored(file)) {
                return false;
            }
            if (file.isDirectory()) {
                PushedFilePropertiesUpdater.getInstance(project).findAndUpdateValue(file, PythonLanguageLevelPusher.this, languageLevel);
            }
            if (suppressSizeLimit) {
                SingleRootFileViewProvider.doNotCheckFileSizeLimit(file);
            }
            return true;
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor)

Example 2 with FileTypeManager

use of com.intellij.openapi.fileTypes.FileTypeManager in project intellij-community by JetBrains.

the class ModuleChunkSourcePath method addExcludePatterns.

private static void addExcludePatterns(Module module, final VirtualFile root, VirtualFile dir, final CompositeGenerator generator, final boolean parentIncluded) {
    final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
    final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() {

        @Override
        public boolean visitFile(@NotNull VirtualFile dir) {
            if (!dir.isDirectory() || fileTypeManager.isFileIgnored(dir)) {
                // ignored files are handled by global 'ignored' pattern set
                return false;
            }
            final boolean isIncluded = moduleRootManager.getFileIndex().isInContent(dir);
            if (isIncluded != parentIncluded) {
                final String relativePath = VfsUtilCore.getRelativePath(dir, root, '/');
                if (isIncluded) {
                    generator.add(new Include(relativePath + "/**"));
                } else {
                    if (!isExcludedByDefault(dir.getName())) {
                        generator.add(new Exclude(relativePath + "/**"));
                    }
                }
            }
            return true;
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor)

Example 3 with FileTypeManager

use of com.intellij.openapi.fileTypes.FileTypeManager in project intellij-community by JetBrains.

the class LocalFilePath method getFileType.

@Override
@NotNull
public FileType getFileType() {
    VirtualFile file = getVirtualFile();
    FileTypeManager manager = FileTypeManager.getInstance();
    return file != null ? manager.getFileTypeByFile(file) : manager.getFileTypeByFileName(getName());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with FileTypeManager

use of com.intellij.openapi.fileTypes.FileTypeManager in project intellij-community by JetBrains.

the class JavaVfsSourceRootDetectionUtil method suggestRoots.

/**
   * Scan directory and detect java source roots within it. The source root is detected as the following:
   * <ol>
   * <li>It contains at least one Java file.</li>
   * <li>Java file is located in the sub-folder that matches package statement in the file.</li>
   * </ol>
   *
   * @param dir a directory to scan
   * @param progressIndicator
   * @return a list of found source roots within directory. If no source roots are found, a empty list is returned.
   */
@NotNull
public static List<VirtualFile> suggestRoots(@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()) {
                    if (typeManager.isFileIgnored(file) || StringUtil.startsWithIgnoreCase(file.getName(), "testData")) {
                        return SKIP_CHILDREN;
                    }
                } else {
                    FileType type = typeManager.getFileTypeByFileName(file.getName());
                    if (StdFileTypes.JAVA == type) {
                        VirtualFile root = suggestRootForJavaFile(file);
                        if (root != null) {
                            foundDirectories.add(root);
                            return skipTo(root);
                        }
                    }
                }
                return CONTINUE;
            }
        });
    } catch (ProcessCanceledException ignore) {
    }
    return foundDirectories;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileType(com.intellij.openapi.fileTypes.FileType) ArrayList(java.util.ArrayList) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) NotNull(org.jetbrains.annotations.NotNull) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with FileTypeManager

use of com.intellij.openapi.fileTypes.FileTypeManager in project intellij-community by JetBrains.

the class PsiVFSListener method createFileCopyWithNewName.

@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);
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 VirtualFileVisitor (com.intellij.openapi.vfs.VirtualFileVisitor)5 NotNull (org.jetbrains.annotations.NotNull)5 FileType (com.intellij.openapi.fileTypes.FileType)4 Result (com.intellij.openapi.application.Result)3 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 IOException (java.io.IOException)3 Nullable (org.jetbrains.annotations.Nullable)3 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 Project (com.intellij.openapi.project.Project)2 VfsUtilCore (com.intellij.openapi.vfs.VfsUtilCore)2 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 MockDisposable (com.facebook.buck.intellij.ideabuck.test.util.MockDisposable)1 HashMultiset (com.google.common.collect.HashMultiset)1 Multiset (com.google.common.collect.Multiset)1 FindBundle (com.intellij.find.FindBundle)1 FindModel (com.intellij.find.FindModel)1