Search in sources :

Example 21 with LanguageFileType

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

the class PsiFileGistImpl method getPsiFile.

private static PsiFile getPsiFile(@NotNull Project project, @NotNull VirtualFile file) {
    PsiFile psi = PsiManager.getInstance(project).findFile(file);
    if (psi == null || !(psi instanceof PsiFileImpl) || ((PsiFileImpl) psi).isContentsLoaded()) {
        return psi;
    }
    FileType fileType = file.getFileType();
    if (!(fileType instanceof LanguageFileType))
        return null;
    return FileContentImpl.createFileFromText(project, psi.getViewProvider().getContents(), (LanguageFileType) fileType, file, file.getName());
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) PsiFile(com.intellij.psi.PsiFile)

Example 22 with LanguageFileType

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

the class StubUpdatingIndex method canHaveStub.

public static boolean canHaveStub(@NotNull VirtualFile file) {
    final FileType fileType = file.getFileType();
    if (fileType instanceof LanguageFileType) {
        final Language l = ((LanguageFileType) fileType).getLanguage();
        final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
        if (parserDefinition == null) {
            return false;
        }
        final IFileElementType elementType = parserDefinition.getFileNodeType();
        if (elementType instanceof IStubFileElementType) {
            if (((IStubFileElementType) elementType).shouldBuildStubFor(file)) {
                return true;
            }
            FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
            if (file instanceof NewVirtualFile && fileBasedIndex instanceof FileBasedIndexImpl && ((FileBasedIndexImpl) fileBasedIndex).getIndex(INDEX_ID).isIndexedStateForFile(((NewVirtualFile) file).getId(), file)) {
                return true;
            }
        }
    }
    final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    return builder != null && builder.acceptsFile(file);
}
Also used : IFileElementType(com.intellij.psi.tree.IFileElementType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) ParserDefinition(com.intellij.lang.ParserDefinition) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile)

Example 23 with LanguageFileType

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

the class StubVersionMap method getVersionOwner.

private static Object getVersionOwner(FileType fileType) {
    Object owner = null;
    if (fileType instanceof LanguageFileType) {
        Language l = ((LanguageFileType) fileType).getLanguage();
        ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
        if (parserDefinition != null) {
            final IFileElementType type = parserDefinition.getFileNodeType();
            if (type instanceof IStubFileElementType) {
                owner = type;
            }
        }
    }
    BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    if (builder != null) {
        owner = builder;
    }
    return owner;
}
Also used : IFileElementType(com.intellij.psi.tree.IFileElementType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) ParserDefinition(com.intellij.lang.ParserDefinition) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) Language(com.intellij.lang.Language)

Example 24 with LanguageFileType

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

the class SearchDialog method updateDialectsAndContexts.

private void updateDialectsAndContexts() {
    final FileType fileType = (FileType) fileTypes.getSelectedItem();
    if (fileType instanceof LanguageFileType) {
        Language language = ((LanguageFileType) fileType).getLanguage();
        Language[] languageDialects = LanguageUtil.getLanguageDialects(language);
        Arrays.sort(languageDialects, Comparator.comparing(Language::getDisplayName));
        Language[] variants = new Language[languageDialects.length + 1];
        variants[0] = null;
        System.arraycopy(languageDialects, 0, variants, 1, languageDialects.length);
        dialects.setModel(new DefaultComboBoxModel<>(variants));
        dialects.setEnabled(variants.length > 1);
    }
    final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(fileType);
    if (profile instanceof StructuralSearchProfileBase) {
        final String[] contextNames = ((StructuralSearchProfileBase) profile).getContextNames();
        if (contextNames.length > 0) {
            contexts.setModel(new DefaultComboBoxModel<>(contextNames));
            contexts.setSelectedItem(contextNames[0]);
            contexts.setEnabled(true);
            return;
        }
    }
    contexts.setSelectedItem(null);
    contexts.setEnabled(false);
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType)

Example 25 with LanguageFileType

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

the class DuplicatesIndex method findDuplicatesProfile.

@Nullable
public static DuplicatesProfile findDuplicatesProfile(FileType fileType) {
    if (!(fileType instanceof LanguageFileType))
        return null;
    Language language = ((LanguageFileType) fileType).getLanguage();
    DuplicatesProfile profile = DuplicatesProfile.findProfileForLanguage(language);
    return profile != null && (ourEnabledOldProfiles && profile.supportDuplicatesIndex() || profile instanceof LightDuplicateProfile) ? profile : null;
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) DuplicatesProfile(com.intellij.dupLocator.DuplicatesProfile) LightDuplicateProfile(com.intellij.dupLocator.LightDuplicateProfile) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)33 Language (com.intellij.lang.Language)20 FileType (com.intellij.openapi.fileTypes.FileType)14 NotNull (org.jetbrains.annotations.NotNull)11 Nullable (org.jetbrains.annotations.Nullable)8 PsiFile (com.intellij.psi.PsiFile)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 ParserDefinition (com.intellij.lang.ParserDefinition)4 IFileElementType (com.intellij.psi.tree.IFileElementType)4 PsiElement (com.intellij.psi.PsiElement)3 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)3 IStubFileElementType (com.intellij.psi.tree.IStubFileElementType)3 CustomSyntaxTableFileType (com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)2 com.intellij.codeInsight.completion (com.intellij.codeInsight.completion)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 LookupElementDecorator (com.intellij.codeInsight.lookup.LookupElementDecorator)1 DocumentContent (com.intellij.diff.contents.DocumentContent)1