Java Code Examples for com.intellij.psi.FileViewProvider#getLanguages()
The following examples show how to use
com.intellij.psi.FileViewProvider#getLanguages() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParsingTestCase.java From consulo with Apache License 2.0 | 6 votes |
public static void doCheckResult(String myFullDataPath, PsiFile file, boolean checkAllPsiRoots, String targetDataName, boolean skipSpaces, boolean printRanges) throws IOException { FileViewProvider provider = file.getViewProvider(); Set<Language> languages = provider.getLanguages(); if (!checkAllPsiRoots || languages.size() == 1) { doCheckResult(myFullDataPath, targetDataName + ".txt", toParseTreeText(file, skipSpaces, printRanges).trim()); return; } for (Language language : languages) { PsiFile root = provider.getPsi(language); String expectedName = targetDataName + "." + language.getID() + ".txt"; doCheckResult(myFullDataPath, expectedName, toParseTreeText(root, skipSpaces, printRanges).trim()); } }
Example 2
Source File: StubTreeBuilder.java From consulo with Apache License 2.0 | 6 votes |
/** * Order is deterministic. First element matches {@link FileViewProvider#getStubBindingRoot()} */ @Nonnull public static List<Pair<IStubFileElementType, PsiFile>> getStubbedRoots(@Nonnull FileViewProvider viewProvider) { final List<Trinity<Language, IStubFileElementType, PsiFile>> roots = new SmartList<>(); final PsiFile stubBindingRoot = viewProvider.getStubBindingRoot(); for (Language language : viewProvider.getLanguages()) { final PsiFile file = viewProvider.getPsi(language); if (file instanceof PsiFileImpl) { final IElementType type = ((PsiFileImpl)file).getElementTypeForStubBuilder(); if (type != null) { roots.add(Trinity.create(language, (IStubFileElementType)type, file)); } } } ContainerUtil.sort(roots, (o1, o2) -> { if (o1.third == stubBindingRoot) return o2.third == stubBindingRoot ? 0 : -1; else if (o2.third == stubBindingRoot) return 1; else return StringUtil.compare(o1.first.getID(), o2.first.getID(), false); }); return ContainerUtil.map(roots, trinity -> Pair.create(trinity.second, trinity.third)); }
Example 3
Source File: ExternalToolPass.java From consulo with Apache License 2.0 | 6 votes |
@RequiredReadAction @Override public void doCollectInformation(@Nonnull ProgressIndicator progress) { myDocumentChanged = false; final FileViewProvider viewProvider = myFile.getViewProvider(); final Set<Language> relevantLanguages = viewProvider.getLanguages(); for (Language language : relevantLanguages) { PsiFile psiRoot = viewProvider.getPsi(language); if (!HighlightingLevelManager.getInstance(myProject).shouldInspect(psiRoot)) continue; final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, psiRoot); if (!externalAnnotators.isEmpty()) { DaemonCodeAnalyzerEx daemonCodeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(myProject); boolean errorFound = daemonCodeAnalyzer.getFileStatusMap().wasErrorFound(myDocument); for(ExternalAnnotator externalAnnotator: externalAnnotators) { final Object collectedInfo = externalAnnotator.collectInformation(psiRoot, myEditor, errorFound); if (collectedInfo != null) { myAnnotator2DataMap.put(externalAnnotator, new MyData(psiRoot, collectedInfo)); } } } } }
Example 4
Source File: BreadcrumbsUtilEx.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public static BreadcrumbsProvider findProvider(boolean checkSettings, @Nonnull FileViewProvider viewProvider) { EditorSettingsExternalizable settings = EditorSettingsExternalizable.getInstance(); if (checkSettings && !settings.isBreadcrumbsShown()) return null; Language baseLang = viewProvider.getBaseLanguage(); if (checkSettings && !isBreadcrumbsShownFor(baseLang)) return null; BreadcrumbsProvider provider = BreadcrumbsUtil.getInfoProvider(baseLang); if (provider == null) { for (Language language : viewProvider.getLanguages()) { if (!checkSettings || isBreadcrumbsShownFor(language)) { provider = BreadcrumbsUtil.getInfoProvider(language); if (provider != null) break; } } } return provider; }
Example 5
Source File: GotoCustomRegionDialog.java From consulo with Apache License 2.0 | 6 votes |
@RequiredReadAction private Collection<FoldingDescriptor> getCustomFoldingDescriptors() { Set<FoldingDescriptor> foldingDescriptors = new HashSet<FoldingDescriptor>(); final Document document = myEditor.getDocument(); PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject); PsiFile file = documentManager != null ? documentManager.getPsiFile(document) : null; if (file != null) { final FileViewProvider viewProvider = file.getViewProvider(); for (final Language language : viewProvider.getLanguages()) { final PsiFile psi = viewProvider.getPsi(language); final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language); if (psi != null) { for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, false)) { CustomFoldingBuilder customFoldingBuilder = getCustomFoldingBuilder(foldingBuilder, descriptor); if (customFoldingBuilder != null) { if (customFoldingBuilder.isCustomRegionStart(descriptor.getElement())) { foldingDescriptors.add(descriptor); } } } } } } return foldingDescriptors; }
Example 6
Source File: GotoCustomRegionAction.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @RequiredReadAction private static Collection<FoldingDescriptor> getCustomFoldingDescriptors(@Nonnull Editor editor, @Nonnull Project project) { Set<FoldingDescriptor> foldingDescriptors = new HashSet<>(); final Document document = editor.getDocument(); PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project); PsiFile file = documentManager != null ? documentManager.getPsiFile(document) : null; if (file != null) { final FileViewProvider viewProvider = file.getViewProvider(); for (final Language language : viewProvider.getLanguages()) { final PsiFile psi = viewProvider.getPsi(language); final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language); if (psi != null) { for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, false)) { CustomFoldingBuilder customFoldingBuilder = getCustomFoldingBuilder(foldingBuilder, descriptor); if (customFoldingBuilder != null) { if (customFoldingBuilder.isCustomRegionStart(descriptor.getElement())) { foldingDescriptors.add(descriptor); } } } } } } return foldingDescriptors; }
Example 7
Source File: Divider.java From consulo with Apache License 2.0 | 5 votes |
public static void divideInsideAndOutsideAllRoots(@Nonnull PsiFile file, @Nonnull TextRange restrictRange, @Nonnull TextRange priorityRange, @Nonnull Condition<PsiFile> rootFilter, @Nonnull Processor<DividedElements> processor) { final FileViewProvider viewProvider = file.getViewProvider(); for (Language language : viewProvider.getLanguages()) { final PsiFile root = viewProvider.getPsi(language); if (!rootFilter.value(root)) { continue; } divideInsideAndOutsideInOneRoot(root, restrictRange, priorityRange, processor); } }
Example 8
Source File: LanguageUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @RequiredReadAction public static Language getRootLanguage(@Nonnull PsiElement element) { final FileViewProvider provider = element.getContainingFile().getViewProvider(); final Set<Language> languages = provider.getLanguages(); if (languages.size() > 1) { PsiElement current = element; while (current != null) { final Language language = current.getLanguage(); if (languages.contains(language)) return language; current = current.getParent(); } } return provider.getBaseLanguage(); }
Example 9
Source File: PsiFileBase.java From consulo with Apache License 2.0 | 5 votes |
private static Language findLanguage(Language baseLanguage, FileViewProvider viewProvider) { final Set<Language> languages = viewProvider.getLanguages(); for (final Language actualLanguage : languages) { if (actualLanguage.isKindOf(baseLanguage)) { return actualLanguage; } } throw new AssertionError( "Language " + baseLanguage + " doesn't participate in view provider " + viewProvider + ": " + new ArrayList<Language>(languages)); }
Example 10
Source File: LineMarkersPass.java From consulo with Apache License 2.0 | 5 votes |
@RequiredReadAction @Override public void doCollectInformation(@Nonnull ProgressIndicator progress) { final List<LineMarkerInfo<PsiElement>> lineMarkers = new ArrayList<>(); FileViewProvider viewProvider = myFile.getViewProvider(); for (Language language : viewProvider.getLanguages()) { final PsiFile root = viewProvider.getPsi(language); HighlightingLevelManager highlightingLevelManager = HighlightingLevelManager.getInstance(myProject); if (!highlightingLevelManager.shouldHighlight(root)) continue; Divider.divideInsideAndOutsideInOneRoot(root, myRestrictRange, myPriorityBounds, elements -> { Collection<LineMarkerProvider> providers = getMarkerProviders(language, myProject); List<LineMarkerProvider> providersList = new ArrayList<>(providers); queryProviders(elements.inside, root, providersList, (element, info) -> { lineMarkers.add(info); ApplicationManager.getApplication().invokeLater(() -> { if (isValid()) { LineMarkersUtil.addLineMarkerToEditorIncrementally(myProject, getDocument(), info); } }, myProject.getDisposed()); }); queryProviders(elements.outside, root, providersList, (element, info) -> lineMarkers.add(info)); return true; }); } myMarkers = mergeLineMarkers(lineMarkers, getDocument()); if (LOG.isDebugEnabled()) { LOG.debug("LineMarkersPass.doCollectInformation. lineMarkers: " + lineMarkers + "; merged: " + myMarkers); } }
Example 11
Source File: ConfigureHighlightingLevel.java From consulo with Apache License 2.0 | 4 votes |
@Nullable public static JBPopup getConfigureHighlightingLevelPopup(DataContext context) { PsiFile psi = context.getData(CommonDataKeys.PSI_FILE); if (psi == null) { return null; } if (!psi.isValid() || psi.getProject().isDisposed()) return null; FileViewProvider provider = psi.getViewProvider(); Set<Language> languages = provider.getLanguages(); if (languages.isEmpty()) return null; VirtualFile file = psi.getVirtualFile(); if (file == null) { return null; } ProjectFileIndex index = ProjectFileIndex.getInstance(psi.getProject()); boolean isAllInspectionsEnabled = index.isInContent(file) || !index.isInLibrary(file); boolean isSeparatorNeeded = languages.size() > 1; DefaultActionGroup group = new DefaultActionGroup(); languages.stream().sorted((o1, o2) -> o1.getDisplayName().compareTo(o2.getDisplayName())).forEach(it -> { if (isSeparatorNeeded) { group.add(AnSeparator.create(it.getDisplayName())); } group.add(new LevelAction(InspectionsLevel.NONE, provider, it)); group.add(new LevelAction(InspectionsLevel.ERRORS, provider, it)); if (isAllInspectionsEnabled) { group.add(new LevelAction(InspectionsLevel.ALL, provider, it)); } }); group.add(AnSeparator.create()); group.add(new ConfigureInspectionsAction()); String title = DaemonBundle.message("popup.title.configure.highlighting.level", psi.getVirtualFile().getPresentableName()); return JBPopupFactory.getInstance().createActionGroupPopup(title, group, context, true, null, 100); }