Search in sources :

Example 1 with BreadcrumbsItem

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

the class YAMLBreadcrumbsTest method testAll.

public void testAll() {
    myFixture.configureByText(YAMLFileType.YML, INPUT);
    final CaretModel caretModel = myFixture.getEditor().getCaretModel();
    final String result = caretModel.getAllCarets().stream().map(Caret::getOffset).collect(Collectors.toList()).stream().map((offset) -> {
        caretModel.moveToOffset(offset);
        return getBreadcrumbs(myFixture).stream().map(BreadcrumbsItem::toString).reduce((left, right) -> right + left).orElse("[]");
    }).reduce((left, right) -> left + "\n------\n" + right).orElse("");
    assertSameLines(OUTPUT, result);
}
Also used : Language(com.intellij.lang.Language) Extensions(com.intellij.openapi.extensions.Extensions) BreadcrumbsItem(com.intellij.xml.breadcrumbs.BreadcrumbsItem) Arrays(java.util.Arrays) CodeInsightTestFixture(com.intellij.testFramework.fixtures.CodeInsightTestFixture) ContainerUtil(com.intellij.util.containers.ContainerUtil) CaretModel(com.intellij.openapi.editor.CaretModel) Collectors(java.util.stream.Collectors) Caret(com.intellij.openapi.editor.Caret) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) YAMLFileType(org.jetbrains.yaml.YAMLFileType) LightPlatformCodeInsightFixtureTestCase(com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase) PsiElement(com.intellij.psi.PsiElement) BreadcrumbsInfoProvider(com.intellij.xml.breadcrumbs.BreadcrumbsInfoProvider) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) CaretModel(com.intellij.openapi.editor.CaretModel) BreadcrumbsItem(com.intellij.xml.breadcrumbs.BreadcrumbsItem)

Example 2 with BreadcrumbsItem

use of com.intellij.xml.breadcrumbs.BreadcrumbsItem 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)2 PsiElement (com.intellij.psi.PsiElement)2 BreadcrumbsInfoProvider (com.intellij.xml.breadcrumbs.BreadcrumbsInfoProvider)2 BreadcrumbsItem (com.intellij.xml.breadcrumbs.BreadcrumbsItem)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 Caret (com.intellij.openapi.editor.Caret)1 CaretModel (com.intellij.openapi.editor.CaretModel)1 Extensions (com.intellij.openapi.extensions.Extensions)1 CodeInsightTestFixture (com.intellij.testFramework.fixtures.CodeInsightTestFixture)1 LightPlatformCodeInsightFixtureTestCase (com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Nullable (org.jetbrains.annotations.Nullable)1 YAMLFileType (org.jetbrains.yaml.YAMLFileType)1