Search in sources :

Example 46 with FileType

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

the class ExternalToolContentExternalizer method chooseExtension.

private String chooseExtension() {
    DiffContent content = getContent();
    VirtualFile contentFile = content.getFile();
    String extension;
    if (contentFile != null) {
        extension = "." + contentFile.getExtension();
    } else {
        FileType contentType = content.getContentType();
        if (contentType == null)
            contentType = DiffUtil.chooseContentTypes(myRequest.getContents())[myIndex];
        extension = contentType != null ? "." + contentType.getDefaultExtension() : null;
    }
    return extension;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileType(com.intellij.openapi.fileTypes.FileType) DiffContent(com.intellij.openapi.diff.DiffContent)

Example 47 with FileType

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

the class CfmlBraceMatcher method isLBraceToken.

public boolean isLBraceToken(HighlighterIterator iterator, CharSequence fileText, FileType fileType) {
    final IElementType tokenType = iterator.getTokenType();
    PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(tokenType.getLanguage());
    if (matcher != null) {
        BracePair[] pairs = matcher.getPairs();
        for (BracePair pair : pairs) {
            if (pair.getLeftBraceType() == tokenType)
                return true;
        }
    }
    if (!tokenType.getLanguage().equals(CfmlLanguage.INSTANCE)) {
        FileType tokenFileType = iterator.getTokenType().getLanguage().getAssociatedFileType();
        if (tokenFileType != null && tokenFileType != CfmlFileType.INSTANCE) {
            for (FileTypeExtensionPoint<BraceMatcher> ext : Extensions.getExtensions(BraceMatcher.EP_NAME)) {
                if (ext.filetype != null && ext.filetype.equals(tokenFileType.getName())) {
                    return ext.getInstance().isLBraceToken(iterator, fileText, tokenFileType instanceof XmlFileType ? StdFileTypes.HTML : tokenFileType);
                }
            }
        }
    }
    for (BracePair pair : PAIRS) {
        if (pair.getLeftBraceType() == tokenType) {
            return true;
        }
    }
    return tokenType.equals(CfmlTokenTypes.OPENER) && (!CfmlUtil.isEndTagRequired(getTagName(fileText, iterator), null) || findEndTag(fileText, iterator));
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) BraceMatcher(com.intellij.codeInsight.highlighting.BraceMatcher) XmlFileType(com.intellij.ide.highlighter.XmlFileType) FileType(com.intellij.openapi.fileTypes.FileType) CfmlFileType(com.intellij.coldFusion.model.files.CfmlFileType) BracePair(com.intellij.lang.BracePair) XmlFileType(com.intellij.ide.highlighter.XmlFileType)

Example 48 with FileType

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

the class CfmlStructureViewTest method createStructureViewModel.

private StructureView createStructureViewModel() {
    VirtualFile virtualFile = myFixture.getFile().getVirtualFile();
    final FileType fileType = virtualFile.getFileType();
    final StructureViewBuilder structureViewBuilder;
    if (fileType == CfmlFileType.INSTANCE) {
        CfmlFileViewProvider viewProvider = (CfmlFileViewProvider) myFixture.getFile().getViewProvider();
        structureViewBuilder = LanguageStructureViewBuilder.INSTANCE.forLanguage(viewProvider.getBaseLanguage()).getStructureViewBuilder(viewProvider.getPsi(viewProvider.getBaseLanguage()));
    } else {
        structureViewBuilder = StructureViewBuilder.PROVIDER.getStructureViewBuilder(fileType, virtualFile, getProject());
    }
    return structureViewBuilder.createStructureView(FileEditorManager.getInstance(getProject()).getSelectedEditor(virtualFile), getProject());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) FileType(com.intellij.openapi.fileTypes.FileType) CfmlFileType(com.intellij.coldFusion.model.files.CfmlFileType) CfmlFileViewProvider(com.intellij.coldFusion.model.files.CfmlFileViewProvider)

Example 49 with FileType

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

the class ResourceFolderRepository method scanValueFile.

private void scanValueFile(String qualifiers, VirtualFile virtualFile, FolderConfiguration folderConfiguration) {
    FileType fileType = virtualFile.getFileType();
    if (fileType == StdFileTypes.XML) {
        if (myResourceFiles.containsKey(virtualFile)) {
            myInitialScanState.countCacheHit();
            return;
        }
        File file = VfsUtilCore.virtualToIoFile(virtualFile);
        try {
            ResourceFile resourceFile = myInitialScanState.loadFile(file);
            if (resourceFile == null) {
                // The file-based parser failed for some reason. Fall back to Psi in case it is more lax.
                myInitialScanState.queuePsiValueResourceScan(new PsiValueResourceQueueEntry(virtualFile, qualifiers, folderConfiguration));
                return;
            }
            for (ResourceItem item : resourceFile.getItems()) {
                ListMultimap<String, ResourceItem> map = getMap(item.getType(), true);
                map.put(item.getName(), item);
            }
            myInitialScanState.countCacheMiss();
            myResourceFiles.put(virtualFile, resourceFile);
        } catch (MergingException e) {
            // The file-based parser failed for some reason. Fall back to Psi in case it is more lax.
            myInitialScanState.queuePsiValueResourceScan(new PsiValueResourceQueueEntry(virtualFile, qualifiers, folderConfiguration));
        }
    }
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 50 with FileType

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

the class ResourceFolderRepository method scanFileResourceFolder.

private void scanFileResourceFolder(@NotNull VirtualFile directory, ResourceFolderType folderType, String qualifiers, FolderConfiguration folderConfiguration) {
    List<ResourceType> resourceTypes = FolderTypeRelationship.getRelatedResourceTypes(folderType);
    assert resourceTypes.size() >= 1 : folderType;
    ResourceType type = resourceTypes.get(0);
    boolean idGeneratingFolder = FolderTypeRelationship.isIdGeneratingFolderType(folderType);
    ListMultimap<String, ResourceItem> map = getMap(type, true);
    for (VirtualFile file : directory.getChildren()) {
        if (file.isValid() && !file.isDirectory()) {
            FileType fileType = file.getFileType();
            boolean idGeneratingFile = idGeneratingFolder && fileType == StdFileTypes.XML;
            if (PsiProjectListener.isRelevantFileType(fileType) || folderType == ResourceFolderType.RAW) {
                scanFileResourceFile(qualifiers, folderType, folderConfiguration, type, idGeneratingFile, map, file);
            }
        // TODO: Else warn about files that aren't expected to be found here?
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileType(com.intellij.openapi.fileTypes.FileType) ResourceType(com.android.resources.ResourceType)

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