use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-community by JetBrains.
the class PlatformIdTableBuilding method getTodoIndexer.
@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, final VirtualFile virtualFile) {
final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType) fileType).isSameFileType()) {
SubstitutedFileType sft = (SubstitutedFileType) fileType;
extIndexer = new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), virtualFile), getTodoIndexer(sft.getFileType(), virtualFile));
} else {
extIndexer = TodoIndexers.INSTANCE.forFileType(fileType);
}
if (extIndexer != null) {
return extIndexer;
}
if (fileType instanceof LanguageFileType) {
final Language lang = ((LanguageFileType) fileType).getLanguage();
final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
if (commentTokens != null) {
return new TokenSetTodoIndexer(commentTokens, virtualFile);
}
}
if (fileType instanceof CustomSyntaxTableFileType) {
return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, virtualFile);
}
return null;
}
use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-plugins by JetBrains.
the class AngularUiRouterDiagramBuilder method getModuleFiles.
@NotNull
private Set<VirtualFile> getModuleFiles(PsiFile file, String mainModule) {
Set<VirtualFile> moduleFiles = myModuleRecursiveDependencies.get(file);
if (moduleFiles != null)
return moduleFiles;
final NonCyclicQueue<String> modulesQueue = new NonCyclicQueue<>();
final NonCyclicQueue<VirtualFile> filesQueue = new NonCyclicQueue<VirtualFile>() {
@Override
protected boolean check(VirtualFile file) {
// do not add lib (especially angular) files
return !NodeModuleUtil.isFromNodeModules(myProject, file);
}
};
if (!StringUtil.isEmptyOrSpaces(mainModule)) {
modulesQueue.add(mainModule);
}
filesQueue.add(file.getVirtualFile());
while (!modulesQueue.isEmpty()) {
final String moduleName = modulesQueue.removeNext();
moduleDependenciesStep(moduleName, filesQueue, modulesQueue);
}
while (!filesQueue.isEmpty()) {
final VirtualFile moduleFile = filesQueue.removeNext();
filesDependenciesStep(moduleFile, filesQueue);
}
Set<VirtualFile> processed = filesQueue.getProcessed();
final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(myProject);
processed = new HashSet<>(ContainerUtil.filter(processed, file1 -> file1.getFileType() instanceof LanguageFileType && ((LanguageFileType) file1.getFileType()).getLanguage().isKindOf(JavascriptLanguage.INSTANCE) && projectScope.contains(file1)));
myModuleRecursiveDependencies.put(file, processed);
return processed;
}
use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-plugins by JetBrains.
the class LanguageListCompletionContributor method doFillVariants.
private static void doFillVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
for (CodeFenceLanguageProvider provider : LanguageGuesser.INSTANCE.getCodeFenceLanguageProviders()) {
final List<LookupElement> lookups = provider.getCompletionVariantsForInfoString(parameters);
for (LookupElement lookupElement : lookups) {
result.addElement(LookupElementDecorator.withInsertHandler(lookupElement, (context, item) -> {
new MyInsertHandler(parameters).handleInsert(context, item);
lookupElement.handleInsert(context);
}));
}
}
for (Map.Entry<String, Language> entry : LanguageGuesser.INSTANCE.getLangToLanguageMap().entrySet()) {
final Language language = entry.getValue();
final LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(entry.getKey()).withIcon(new DeferredIconImpl<>(null, language, true, language1 -> {
final LanguageFileType fileType = language1.getAssociatedFileType();
return fileType != null ? fileType.getIcon() : null;
})).withTypeText(language.getDisplayName(), true).withInsertHandler(new MyInsertHandler(parameters));
result.addElement(lookupElementBuilder);
}
}
use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-community by JetBrains.
the class CheckRegExpForm method createUIComponents.
private void createUIComponents() {
myProject = myRegexpFile.getProject();
Document document = PsiDocumentManager.getInstance(myProject).getDocument(myRegexpFile);
final Language language = myRegexpFile.getLanguage();
final LanguageFileType fileType;
if (language instanceof RegExpLanguage) {
fileType = RegExpLanguage.INSTANCE.getAssociatedFileType();
} else {
// for correct syntax highlighting
fileType = new RegExpFileType(language);
}
myRegExp = new EditorTextField(document, myProject, fileType);
final String sampleText = PropertiesComponent.getInstance(myProject).getValue(LAST_EDITED_REGEXP, "Sample Text");
mySampleText = new EditorTextField(sampleText, myProject, PlainTextFileType.INSTANCE) {
@Override
protected void updateBorder(@NotNull EditorEx editor) {
setupBorder(editor);
}
};
mySampleText.setOneLineMode(false);
int preferredWidth = Math.max(JBUI.scale(250), myRegExp.getPreferredSize().width);
myRegExp.setPreferredWidth(preferredWidth);
mySampleText.setPreferredWidth(preferredWidth);
myRootPanel = new JPanel(new BorderLayout()) {
Disposable disposable;
Alarm updater;
@Override
public void addNotify() {
super.addNotify();
disposable = Disposer.newDisposable();
IdeFocusManager.getGlobalInstance().requestFocus(mySampleText, true);
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
IdeFocusManager.findInstance().requestFocus(myRegExp.getFocusTarget(), true);
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("shift TAB"), mySampleText);
updater = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, disposable);
DocumentAdapter documentListener = new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
update();
}
};
myRegExp.addDocumentListener(documentListener);
mySampleText.addDocumentListener(documentListener);
update();
mySampleText.selectAll();
}
public void update() {
final TransactionId transactionId = TransactionGuard.getInstance().getContextTransaction();
updater.cancelAllRequests();
if (!updater.isDisposed()) {
updater.addRequest(() -> {
final RegExpMatchResult result = isMatchingText(myRegexpFile, mySampleText.getText());
TransactionGuard.getInstance().submitTransaction(myProject, transactionId, () -> setBalloonState(result));
}, 200);
}
}
@Override
public void removeNotify() {
super.removeNotify();
Disposer.dispose(disposable);
PropertiesComponent.getInstance(myProject).setValue(LAST_EDITED_REGEXP, mySampleText.getText());
}
};
myRootPanel.setBorder(JBUI.Borders.empty(UIUtil.DEFAULT_VGAP, UIUtil.DEFAULT_HGAP));
}
use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-plugins by JetBrains.
the class FlexCssElementDescriptorProvider method isMyContext.
public boolean isMyContext(@Nullable PsiElement context) {
if (context == null || !context.isValid())
return false;
PsiFile file = context.getContainingFile();
if (file == null)
return false;
if (HtmlUtil.hasHtml(file))
return false;
final VirtualFile vFile = file.getOriginalFile().getVirtualFile();
if (vFile != null) {
final FileType type = vFile.getFileType();
if (type instanceof LanguageFileType) {
Language lang = ((LanguageFileType) type).getLanguage();
if (lang.isKindOf(CSSLanguage.INSTANCE) && !lang.is(CSSLanguage.INSTANCE))
return false;
}
}
Module module = findModuleForPsiElement(file);
if (module == null) {
file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(context);
if (file != null) {
module = findModuleForPsiElement(file);
}
}
if (module == null || ModuleType.get(module) != FlexModuleType.getInstance()) {
return false;
}
if (vFile != null) {
CssDialect dialect = CssDialectMappings.getInstance(context.getProject()).getMapping(vFile);
return dialect == null || dialect == FlexCSSDialect.getInstance();
}
return true;
}
Aggregations