Search in sources :

Example 1 with BreadcrumbsInfoProvider

use of com.intellij.xml.breadcrumbs.BreadcrumbsInfoProvider in project intellij-community by JetBrains.

the class YAMLBreadcrumbsTest method getBreadcrumbs.

// TODO move this method and class to platform when breadcrumbs are moved there, too
@NotNull
private static List<BreadcrumbsItem> getBreadcrumbs(@NotNull CodeInsightTestFixture fixture) {
    PsiElement element = fixture.getFile().findElementAt(fixture.getCaretOffset());
    if (element == null) {
        return Collections.emptyList();
    }
    final Language language = element.getContainingFile().getLanguage();
    final BreadcrumbsInfoProvider provider = ContainerUtil.find(Extensions.getExtensions(BreadcrumbsInfoProvider.EP_NAME), (p) -> Arrays.asList(p.getLanguages()).contains(language));
    if (provider == null) {
        return Collections.emptyList();
    }
    List<BreadcrumbsItem> result = new ArrayList<>();
    while (element != null) {
        if (provider.acceptElement(element)) {
            result.add(new MockBreadcrumbsItem(provider.getElementInfo(element), provider.getElementTooltip(element)));
        }
        element = provider.getParent(element);
    }
    return result;
}
Also used : Language(com.intellij.lang.Language) ArrayList(java.util.ArrayList) BreadcrumbsInfoProvider(com.intellij.xml.breadcrumbs.BreadcrumbsInfoProvider) BreadcrumbsItem(com.intellij.xml.breadcrumbs.BreadcrumbsItem) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Language (com.intellij.lang.Language)1 PsiElement (com.intellij.psi.PsiElement)1 BreadcrumbsInfoProvider (com.intellij.xml.breadcrumbs.BreadcrumbsInfoProvider)1 BreadcrumbsItem (com.intellij.xml.breadcrumbs.BreadcrumbsItem)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1