Search in sources :

Example 1 with FileTypeRegistry

use of com.intellij.openapi.fileTypes.FileTypeRegistry in project intellij-elixir by KronicDeth.

the class ParsingTestCase method registerProjectFileIndex.

private void registerProjectFileIndex(MessageBus messageBus) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
    DirectoryIndex directoryIndex = registerDirectoryIndex(messageBus);
    FileTypeRegistry fileTypeRegistry = new MockFileTypeManager();
    myProject.registerService(ProjectFileIndex.class, new ProjectFileIndexImpl(myProject, directoryIndex, fileTypeRegistry));
}
Also used : MockFileTypeManager(com.intellij.openapi.fileTypes.MockFileTypeManager) FileTypeRegistry(com.intellij.openapi.fileTypes.FileTypeRegistry)

Example 2 with FileTypeRegistry

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

the class AbstractConvertLineSeparatorsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent event) {
    final DataContext dataContext = event.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return;
    }
    final VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
    if (virtualFiles == null) {
        return;
    }
    VirtualFile projectVirtualDirectory = ProjectKt.getStateStore(project).getDirectoryStoreFile();
    final FileTypeRegistry fileTypeManager = FileTypeRegistry.getInstance();
    for (VirtualFile file : virtualFiles) {
        VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {

            @NotNull
            @Override
            public Result visitFileEx(@NotNull VirtualFile file) {
                if (shouldProcess(file, project)) {
                    changeLineSeparators(project, file, mySeparator);
                }
                return file.isDirectory() && (file.equals(projectVirtualDirectory) || fileTypeManager.isFileIgnored(file)) ? SKIP_CHILDREN : CONTINUE;
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) FileTypeRegistry(com.intellij.openapi.fileTypes.FileTypeRegistry) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 3 with FileTypeRegistry

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

the class DiffHttpService method readContent.

@Nullable
private static String readContent(@NotNull JsonReader reader, @NotNull List<DiffContent> contents, @NotNull List<String> titles, @Nullable String defaultFileTypeName) throws IOException {
    FileTypeRegistry fileTypeRegistry = FileTypeRegistry.getInstance();
    FileType defaultFileType = defaultFileTypeName == null ? null : fileTypeRegistry.findFileTypeByName(defaultFileTypeName);
    reader.beginArray();
    while (reader.hasNext()) {
        String title = null;
        String fileType = null;
        String content = null;
        reader.beginObject();
        while (reader.hasNext()) {
            String name = reader.nextName();
            if (name.equals("title")) {
                title = reader.nextString();
            } else if (name.equals("fileType")) {
                fileType = reader.nextString();
            } else if (name.equals("content")) {
                content = reader.nextString();
            } else {
                reader.skipValue();
            }
        }
        reader.endObject();
        if (content == null) {
            return "content is not specified";
        }
        FileType type = fileType == null ? defaultFileType : fileTypeRegistry.findFileTypeByName(fileType);
        contents.add(DiffContentFactory.getInstance().create(content, type));
        titles.add(StringUtil.isEmptyOrSpaces(title) ? "" : title);
    }
    reader.endArray();
    return null;
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType) FileTypeRegistry(com.intellij.openapi.fileTypes.FileTypeRegistry) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with FileTypeRegistry

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

the class ApplicationManager method setApplication.

public static void setApplication(@NotNull Application instance, @NotNull Getter<FileTypeRegistry> fileTypeRegistryGetter, @NotNull Disposable parent) {
    final Application old = ourApplication;
    final Getter<FileTypeRegistry> oldFileTypeRegistry = FileTypeRegistry.ourInstanceGetter;
    Disposer.register(parent, new Disposable() {

        @Override
        public void dispose() {
            if (old != null) {
                // to prevent NPEs in threads still running
                setApplication(old);
                //noinspection AssignmentToStaticFieldFromInstanceMethod
                FileTypeRegistry.ourInstanceGetter = oldFileTypeRegistry;
            }
        }
    });
    setApplication(instance);
    FileTypeRegistry.ourInstanceGetter = fileTypeRegistryGetter;
}
Also used : Disposable(com.intellij.openapi.Disposable) FileTypeRegistry(com.intellij.openapi.fileTypes.FileTypeRegistry)

Example 5 with FileTypeRegistry

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

the class StubVersionMap method updateState.

private void updateState() throws IOException {
    final long currentStubIndexStamp = IndexingStamp.getIndexCreationStamp(StubUpdatingIndex.INDEX_ID);
    File allIndexedFiles = allIndexedFilesRegistryFile();
    List<String> removedFileTypes = new ArrayList<>();
    List<FileType> updatedFileTypes = new ArrayList<>();
    List<FileType> addedFileTypes = new ArrayList<>();
    long lastUsedCounter = currentStubIndexStamp;
    boolean canUsePreviousMappings = allIndexedFiles.exists();
    FileTypeRegistry fileTypeRegistry = FileTypeRegistry.getInstance();
    Set<FileType> loadedFileTypes = new THashSet<>();
    if (canUsePreviousMappings) {
        List<String> stringList = StringUtil.split(FileUtil.loadFile(allIndexedFiles, ourEncoding), LINE_SEPARATOR);
        long allIndexedFilesVersion = Long.parseLong(stringList.get(0));
        if (allIndexedFilesVersion == currentStubIndexStamp) {
            for (int i = 1, size = stringList.size(); i < size; ++i) {
                List<String> strings = StringUtil.split(stringList.get(i), RECORD_SEPARATOR);
                String fileTypeName = strings.get(0);
                long usedTimeStamp = Long.parseLong(strings.get(2));
                lastUsedCounter = Math.min(lastUsedCounter, usedTimeStamp);
                FileType fileType = fileTypeRegistry.findFileTypeByName(fileTypeName);
                if (fileType == null)
                    removedFileTypes.add(fileTypeName);
                else {
                    loadedFileTypes.add(fileType);
                    Object owner = getVersionOwner(fileType);
                    if (owner == null)
                        removedFileTypes.add(fileTypeName);
                    else {
                        if (!Comparing.equal(strings.get(1), typeAndVersion(owner))) {
                            updatedFileTypes.add(fileType);
                        } else {
                            registerStamp(fileType, usedTimeStamp);
                        }
                    }
                }
            }
        } else {
            canUsePreviousMappings = false;
        }
    }
    for (FileType fileType : fileTypeToVersionOwner.keySet()) {
        if (!loadedFileTypes.contains(fileType)) {
            addedFileTypes.add(fileType);
        }
    }
    if (canUsePreviousMappings && (!addedFileTypes.isEmpty() || !removedFileTypes.isEmpty())) {
        StubUpdatingIndex.LOG.info("requesting complete stub index rebuild due to changes: " + (addedFileTypes.isEmpty() ? "" : "added file types:" + StringUtil.join(addedFileTypes, FileType::getName, ",") + ";") + (removedFileTypes.isEmpty() ? "" : "removed file types:" + StringUtil.join(removedFileTypes, ",")));
        // StubVersionMap will be recreated
        throw new IOException();
    }
    // important to start with value smaller and progress downwards
    long counter = lastUsedCounter - 1;
    for (FileType fileType : ContainerUtil.concat(updatedFileTypes, addedFileTypes)) {
        while (versionToFileType.containsKey(counter)) --counter;
        registerStamp(fileType, counter);
    }
    if (!addedFileTypes.isEmpty() || !updatedFileTypes.isEmpty() || !removedFileTypes.isEmpty()) {
        if (!addedFileTypes.isEmpty()) {
            StubUpdatingIndex.LOG.info("Following new file types will be indexed:" + StringUtil.join(addedFileTypes, FileType::getName, ","));
        }
        if (!updatedFileTypes.isEmpty()) {
            StubUpdatingIndex.LOG.info("Stub version was changed for " + StringUtil.join(updatedFileTypes, FileType::getName, ","));
        }
        if (!removedFileTypes.isEmpty()) {
            StubUpdatingIndex.LOG.info("Following file types will not be indexed:" + StringUtil.join(removedFileTypes, ","));
        }
        StringBuilder allFileTypes = new StringBuilder();
        allFileTypes.append(currentStubIndexStamp).append(LINE_SEPARATOR);
        for (FileType fileType : fileTypeToVersionOwner.keySet()) {
            Object owner = fileTypeToVersionOwner.get(fileType);
            long timestamp = fileTypeToVersion.get(fileType);
            allFileTypes.append(fileType.getName()).append(RECORD_SEPARATOR).append(typeAndVersion(owner)).append(RECORD_SEPARATOR).append(timestamp).append(LINE_SEPARATOR);
        }
        FileUtil.writeToFile(allIndexedFiles, allFileTypes.toString().getBytes(ourEncoding));
    }
    myStubIndexStamp = currentStubIndexStamp;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileTypeRegistry(com.intellij.openapi.fileTypes.FileTypeRegistry) THashSet(gnu.trove.THashSet) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) File(java.io.File)

Aggregations

FileTypeRegistry (com.intellij.openapi.fileTypes.FileTypeRegistry)6 FileType (com.intellij.openapi.fileTypes.FileType)2 MockApplicationEx (com.intellij.mock.MockApplicationEx)1 Disposable (com.intellij.openapi.Disposable)1 Result (com.intellij.openapi.application.Result)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 MockFileTypeManager (com.intellij.openapi.fileTypes.MockFileTypeManager)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 VirtualFileVisitor (com.intellij.openapi.vfs.VirtualFileVisitor)1 THashSet (gnu.trove.THashSet)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1