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();
}
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));
}
}
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;
}
Aggregations