Search in sources :

Example 41 with FileType

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

the class BlockSupportImpl method makeFullParse.

@NotNull
private static DiffLog makeFullParse(@NotNull PsiFileImpl fileImpl, @NotNull FileASTNode oldFileNode, @NotNull CharSequence newFileText, @NotNull ProgressIndicator indicator, @NotNull CharSequence lastCommittedText) {
    if (fileImpl instanceof PsiCodeFragment) {
        FileElement parent = fileImpl.getTreeElement();
        final FileElement holderElement = new DummyHolder(fileImpl.getManager(), fileImpl.getContext()).getTreeElement();
        holderElement.rawAddChildren(fileImpl.createContentLeafElement(holderElement.getCharTable().intern(newFileText, 0, newFileText.length())));
        DiffLog diffLog = new DiffLog();
        diffLog.appendReplaceFileElement(parent, (FileElement) holderElement.getFirstChildNode());
        return diffLog;
    } else {
        FileViewProvider viewProvider = fileImpl.getViewProvider();
        viewProvider.getLanguages();
        FileType fileType = viewProvider.getVirtualFile().getFileType();
        String fileName = fileImpl.getName();
        final LightVirtualFile lightFile = new LightVirtualFile(fileName, fileType, newFileText, viewProvider.getVirtualFile().getCharset(), fileImpl.getViewProvider().getModificationStamp());
        lightFile.setOriginalFile(viewProvider.getVirtualFile());
        FileViewProvider copy = viewProvider.createCopy(lightFile);
        if (copy.isEventSystemEnabled()) {
            throw new AssertionError("Copied view provider must be non-physical for reparse to deliver correct events: " + viewProvider);
        }
        copy.getLanguages();
        // optimization: do not convert file contents to bytes to determine if we should codeinsight it
        SingleRootFileViewProvider.doNotCheckFileSizeLimit(lightFile);
        PsiFileImpl newFile = getFileCopy(fileImpl, copy);
        newFile.setOriginalFile(fileImpl);
        final FileElement newFileElement = (FileElement) newFile.getNode();
        final FileElement oldFileElement = (FileElement) oldFileNode;
        if (!lastCommittedText.toString().equals(oldFileElement.getText())) {
            throw new IncorrectOperationException(viewProvider.toString());
        }
        DiffLog diffLog = mergeTrees(fileImpl, oldFileElement, newFileElement, indicator, lastCommittedText);
        ((PsiManagerEx) fileImpl.getManager()).getFileManager().setViewProvider(lightFile, null);
        return diffLog;
    }
}
Also used : DummyHolder(com.intellij.psi.impl.source.DummyHolder) FileType(com.intellij.openapi.fileTypes.FileType) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with FileType

use of com.intellij.openapi.fileTypes.FileType 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 43 with FileType

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

the class FileDocumentManagerImpl method getDocument.

@Override
@Nullable
public Document getDocument(@NotNull final VirtualFile file) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    DocumentEx document = (DocumentEx) getCachedDocument(file);
    if (document == null) {
        if (!file.isValid() || file.isDirectory() || isBinaryWithoutDecompiler(file))
            return null;
        boolean tooLarge = FileUtilRt.isTooLarge(file.getLength());
        if (file.getFileType().isBinary() && tooLarge)
            return null;
        final CharSequence text = tooLarge ? LoadTextUtil.loadText(file, getPreviewCharCount(file)) : LoadTextUtil.loadText(file);
        synchronized (lock) {
            document = (DocumentEx) getCachedDocument(file);
            // Double checking
            if (document != null)
                return document;
            document = (DocumentEx) createDocument(text, file);
            document.setModificationStamp(file.getModificationStamp());
            final FileType fileType = file.getFileType();
            document.setReadOnly(tooLarge || !file.isWritable() || fileType.isBinary());
            if (!(file instanceof LightVirtualFile || file.getFileSystem() instanceof NonPhysicalFileSystem)) {
                document.addDocumentListener(myPhysicalDocumentChangeTracker);
            }
            if (file instanceof LightVirtualFile) {
                registerDocument(document, file);
            } else {
                document.putUserData(FILE_KEY, file);
                cacheDocument(file, document);
            }
        }
        myMultiCaster.fileContentLoaded(file, document);
    }
    return document;
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) UnknownFileType(com.intellij.openapi.fileTypes.UnknownFileType) FileType(com.intellij.openapi.fileTypes.FileType) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Nullable(org.jetbrains.annotations.Nullable)

Example 44 with FileType

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

the class HttpVirtualFileImpl method getFileType.

@Override
@NotNull
public FileType getFileType() {
    if (myFileInfo == null) {
        return super.getFileType();
    }
    VirtualFile localFile = myFileInfo.getLocalFile();
    if (localFile != null) {
        return localFile.getFileType();
    }
    FileType fileType = super.getFileType();
    if (myInitialFileType == null) {
        myInitialFileType = fileType;
    }
    return fileType;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileType(com.intellij.openapi.fileTypes.FileType) NotNull(org.jetbrains.annotations.NotNull)

Example 45 with FileType

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

the class NextPrevWordTest method testRegexpCharsAreNotTreatedAsSeparateWords.

public void testRegexpCharsAreNotTreatedAsSeparateWords() {
    FileType regExpFileType = FileTypeManagerEx.getInstanceEx().findFileTypeByName("RegExp");
    assertNotNull(regExpFileType);
    myFixture.configureByText(regExpFileType, "<caret>abc");
    myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD);
    myFixture.checkResult("abc<caret>");
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType)

Aggregations

FileType (com.intellij.openapi.fileTypes.FileType)198 VirtualFile (com.intellij.openapi.vfs.VirtualFile)60 NotNull (org.jetbrains.annotations.NotNull)38 Language (com.intellij.lang.Language)31 PsiFile (com.intellij.psi.PsiFile)31 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)30 Nullable (org.jetbrains.annotations.Nullable)28 Project (com.intellij.openapi.project.Project)27 Document (com.intellij.openapi.editor.Document)20 IncorrectOperationException (com.intellij.util.IncorrectOperationException)13 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)11 Editor (com.intellij.openapi.editor.Editor)10 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)10 CustomSyntaxTableFileType (com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)10 PlainTextFileType (com.intellij.openapi.fileTypes.PlainTextFileType)9 UnknownFileType (com.intellij.openapi.fileTypes.UnknownFileType)9 BraceMatcher (com.intellij.codeInsight.highlighting.BraceMatcher)8 AbstractFileType (com.intellij.openapi.fileTypes.impl.AbstractFileType)8 PsiElement (com.intellij.psi.PsiElement)8