Search in sources :

Example 26 with LanguageFileType

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

the class CoreStubTreeLoader method canHaveStub.

@Override
public boolean canHaveStub(VirtualFile file) {
    final FileType fileType = file.getFileType();
    if (fileType instanceof LanguageFileType) {
        Language l = ((LanguageFileType) fileType).getLanguage();
        ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
        if (parserDefinition == null)
            return false;
        final IFileElementType elementType = parserDefinition.getFileNodeType();
        return elementType instanceof IStubFileElementType && ((IStubFileElementType) elementType).shouldBuildStubFor(file);
    } else if (fileType.isBinary()) {
        final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
        return builder != null && builder.acceptsFile(file);
    }
    return false;
}
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)

Example 27 with LanguageFileType

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

the class InspectionListCellRenderer method getIcon.

@NotNull
private static Icon getIcon(@NotNull InspectionToolWrapper tool) {
    Icon icon = null;
    final Language language = Language.findLanguageByID(tool.getLanguage());
    if (language != null) {
        final LanguageFileType fileType = language.getAssociatedFileType();
        if (fileType != null) {
            icon = fileType.getIcon();
        }
    }
    if (icon == null) {
        icon = UnknownFileType.INSTANCE.getIcon();
    }
    assert icon != null;
    return icon;
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with LanguageFileType

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

the class PsiFileFactoryImpl method createFileFromText.

@Override
@NotNull
public PsiFile createFileFromText(@NotNull String name, @NotNull FileType fileType, @NotNull CharSequence text, long modificationStamp, final boolean eventSystemEnabled, boolean markAsCopy) {
    final LightVirtualFile virtualFile = new LightVirtualFile(name, fileType, text, modificationStamp);
    if (fileType instanceof LanguageFileType) {
        final Language language = LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType) fileType).getLanguage(), virtualFile, myManager.getProject());
        final PsiFile file = trySetupPsiForFile(virtualFile, language, eventSystemEnabled, markAsCopy);
        if (file != null)
            return file;
    }
    final SingleRootFileViewProvider singleRootFileViewProvider = new SingleRootFileViewProvider(myManager, virtualFile, eventSystemEnabled);
    final PsiPlainTextFileImpl plainTextFile = new PsiPlainTextFileImpl(singleRootFileViewProvider);
    if (markAsCopy)
        CodeEditUtil.setNodeGenerated(plainTextFile.getNode(), true);
    return plainTextFile;
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) PsiPlainTextFileImpl(com.intellij.psi.impl.source.PsiPlainTextFileImpl) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with LanguageFileType

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

the class IdTableBuilding method getFileTypeIndexer.

@Nullable
public static FileTypeIdIndexer getFileTypeIndexer(FileType fileType) {
    final FileTypeIdIndexer idIndexer = ourIdIndexers.get(fileType);
    if (idIndexer != null) {
        return idIndexer;
    }
    final FileTypeIdIndexer extIndexer = IdIndexers.INSTANCE.forFileType(fileType);
    if (extIndexer != null) {
        return extIndexer;
    }
    final WordsScanner customWordsScanner = CacheBuilderRegistry.getInstance().getCacheBuilder(fileType);
    if (customWordsScanner != null) {
        return new WordsScannerFileTypeIdIndexerAdapter(customWordsScanner);
    }
    if (fileType instanceof LanguageFileType) {
        final Language lang = ((LanguageFileType) fileType).getLanguage();
        final FindUsagesProvider findUsagesProvider = LanguageFindUsages.INSTANCE.forLanguage(lang);
        WordsScanner scanner = findUsagesProvider == null ? null : findUsagesProvider.getWordsScanner();
        if (scanner == null) {
            scanner = new SimpleWordsScanner();
        }
        return new WordsScannerFileTypeIdIndexerAdapter(scanner);
    }
    if (fileType instanceof CustomSyntaxTableFileType) {
        return new WordsScannerFileTypeIdIndexerAdapter(createCustomFileTypeScanner(((CustomSyntaxTableFileType) fileType).getSyntaxTable()));
    }
    return null;
}
Also used : FindUsagesProvider(com.intellij.lang.findUsages.FindUsagesProvider) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with LanguageFileType

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

the class PatternCompiler method compilePattern.

public static CompiledPattern compilePattern(final Project project, final MatchOptions options) throws MalformedPatternException, UnsupportedOperationException {
    FileType fileType = options.getFileType();
    assert fileType instanceof LanguageFileType;
    Language language = ((LanguageFileType) fileType).getLanguage();
    StructuralSearchProfile profile = StructuralSearchUtil.getProfileByLanguage(language);
    assert profile != null;
    CompiledPattern result = profile.createCompiledPattern();
    final String[] prefixes = result.getTypedVarPrefixes();
    assert prefixes.length > 0;
    final CompileContext context = new CompileContext();
    if (ApplicationManager.getApplication().isUnitTestMode())
        lastTestingContext = context;
    try {
        context.init(result, options, project, options.getScope() instanceof GlobalSearchScope);
        List<PsiElement> elements = compileByAllPrefixes(project, options, result, context, prefixes);
        final CompiledPattern pattern = context.getPattern();
        checkForUnknownVariables(pattern, elements);
        pattern.setNodes(elements);
        if (context.getSearchHelper().doOptimizing() && context.getSearchHelper().isScannedSomething()) {
            final Set<PsiFile> set = context.getSearchHelper().getFilesSetToScan();
            final List<PsiFile> filesToScan = new ArrayList<>(set.size());
            final GlobalSearchScope scope = (GlobalSearchScope) options.getScope();
            for (final PsiFile file : set) {
                if (!scope.contains(file.getVirtualFile())) {
                    continue;
                }
                if (file instanceof PsiFileImpl) {
                    ((PsiFileImpl) file).clearCaches();
                }
                filesToScan.add(file);
            }
            if (filesToScan.size() == 0) {
                throw new MalformedPatternException(SSRBundle.message("ssr.will.not.find.anything"));
            }
            result.setScope(new LocalSearchScope(PsiUtilCore.toPsiElementArray(filesToScan)));
        }
    } finally {
        context.clear();
    }
    return result;
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) TIntArrayList(gnu.trove.TIntArrayList) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) CompiledPattern(com.intellij.structuralsearch.impl.matcher.CompiledPattern)

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