Search in sources :

Example 31 with LanguageFileType

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

the class MatcherImpl method findMatches.

/**
   * Finds the matches of given pattern starting from given tree element.
   * @throws MalformedPatternException
   * @throws UnsupportedPatternException
   */
protected void findMatches(MatchResultSink sink, final MatchOptions options) throws MalformedPatternException, UnsupportedPatternException {
    CompiledPattern compiledPattern = prepareMatching(sink, options);
    if (compiledPattern == null) {
        return;
    }
    matchContext.getSink().setMatchingProcess(scheduler);
    scheduler.init();
    progress = matchContext.getSink().getProgressIndicator();
    if (isTesting) {
        // testing mode;
        final PsiElement[] elements = ((LocalSearchScope) options.getScope()).getScope();
        PsiElement parent = elements[0].getParent();
        if (elements.length > 0 && matchContext.getPattern().getStrategy().continueMatching(parent != null ? parent : elements[0])) {
            visitor.matchContext(new SsrFilteringNodeIterator(new ArrayBackedNodeIterator(elements)));
        } else {
            final LanguageFileType fileType = (LanguageFileType) matchContext.getOptions().getFileType();
            final Language language = fileType.getLanguage();
            for (PsiElement element : elements) {
                match(element, language);
            }
        }
        matchContext.getSink().matchingFinished();
        return;
    }
    if (!findMatches(options, compiledPattern)) {
        return;
    }
    if (scheduler.getTaskQueueEndAction() == null) {
        scheduler.setTaskQueueEndAction(() -> matchContext.getSink().matchingFinished());
    }
    scheduler.executeNext();
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) SsrFilteringNodeIterator(com.intellij.structuralsearch.impl.matcher.iterators.SsrFilteringNodeIterator) ArrayBackedNodeIterator(com.intellij.dupLocator.iterators.ArrayBackedNodeIterator)

Example 32 with LanguageFileType

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

the class FindDialog method updateFileTypeForEditorComponent.

private void updateFileTypeForEditorComponent(@NotNull ComboBox inputComboBox) {
    final Component editorComponent = inputComboBox.getEditor().getEditorComponent();
    if (editorComponent instanceof EditorTextField) {
        boolean isRegexp = myCbRegularExpressions.isSelectedWhenSelectable();
        FileType fileType = PlainTextFileType.INSTANCE;
        if (isRegexp) {
            Language regexpLanguage = Language.findLanguageByID("RegExp");
            if (regexpLanguage != null) {
                LanguageFileType regexpFileType = regexpLanguage.getAssociatedFileType();
                if (regexpFileType != null) {
                    fileType = regexpFileType;
                }
            }
        }
        String fileName = isRegexp ? "a.regexp" : "a.txt";
        final PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText(fileName, fileType, ((EditorTextField) editorComponent).getText(), -1, true);
        ((EditorTextField) editorComponent).setNewDocumentAndFileType(fileType, PsiDocumentManager.getInstance(myProject).getDocument(file));
    }
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) PlainTextFileType(com.intellij.openapi.fileTypes.PlainTextFileType) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) PsiFile(com.intellij.psi.PsiFile) JTextComponent(javax.swing.text.JTextComponent)

Example 33 with LanguageFileType

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

the class BraceMatchingUtil method getBraceMatcher.

@NotNull
public static BraceMatcher getBraceMatcher(@NotNull FileType fileType, @NotNull Language lang) {
    PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(lang);
    if (matcher != null) {
        if (matcher instanceof XmlAwareBraceMatcher) {
            return (XmlAwareBraceMatcher) matcher;
        } else if (matcher instanceof PairedBraceMatcherAdapter) {
            return (BraceMatcher) matcher;
        } else {
            return new PairedBraceMatcherAdapter(matcher, lang);
        }
    }
    final BraceMatcher byFileType = getBraceMatcherByFileType(fileType);
    if (byFileType != null)
        return byFileType;
    if (fileType instanceof LanguageFileType) {
        final Language language = ((LanguageFileType) fileType).getLanguage();
        if (lang != language) {
            final FileType type1 = lang.getAssociatedFileType();
            if (type1 != null) {
                final BraceMatcher braceMatcher = getBraceMatcherByFileType(type1);
                if (braceMatcher != null) {
                    return braceMatcher;
                }
            }
            matcher = LanguageBraceMatching.INSTANCE.forLanguage(language);
            if (matcher != null) {
                return new PairedBraceMatcherAdapter(matcher, language);
            }
        }
    }
    return BraceMatcherHolder.ourDefaultBraceMatcher;
}
Also used : PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) PairedBraceMatcher(com.intellij.lang.PairedBraceMatcher) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) NotNull(org.jetbrains.annotations.NotNull)

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