Search in sources :

Example 1 with RelatedItemLineMarkerInfo

use of com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo in project intellij-community by JetBrains.

the class PyiRelatedItemLineMarkerProvider method createLineMarkerInfo.

@NotNull
private static RelatedItemLineMarkerInfo<PsiElement> createLineMarkerInfo(@NotNull PsiElement element, @NotNull PsiElement relatedElement, @NotNull String itemTitle) {
    final SmartPointerManager pointerManager = SmartPointerManager.getInstance(element.getProject());
    final SmartPsiElementPointer<PsiElement> relatedElementPointer = pointerManager.createSmartPsiElementPointer(relatedElement);
    final String stubFileName = relatedElement.getContainingFile().getName();
    return new RelatedItemLineMarkerInfo<>(element, element.getTextRange(), ICON, Pass.LINE_MARKERS, element1 -> itemTitle + " in " + stubFileName, new GutterIconNavigationHandler<PsiElement>() {

        @Override
        public void navigate(MouseEvent e, PsiElement elt) {
            final PsiElement restoredRelatedElement = relatedElementPointer.getElement();
            if (restoredRelatedElement == null) {
                return;
            }
            final int offset = restoredRelatedElement instanceof PsiFile ? -1 : restoredRelatedElement.getTextOffset();
            final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(restoredRelatedElement);
            if (virtualFile != null && virtualFile.isValid()) {
                new OpenFileDescriptor(restoredRelatedElement.getProject(), virtualFile, offset).navigate(true);
            }
        }
    }, GutterIconRenderer.Alignment.RIGHT, GotoRelatedItem.createItems(Collections.singletonList(relatedElement)));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SmartPointerManager(com.intellij.psi.SmartPointerManager) MouseEvent(java.awt.event.MouseEvent) RelatedItemLineMarkerInfo(com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with RelatedItemLineMarkerInfo

use of com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo in project Perl5-IDEA by Camelcade.

the class PerlLineMarkersTest method doTest.

private void doTest() {
    initWithFileSmart();
    List<GutterMark> allMarkers = myFixture.findAllGutters();
    String text = myFixture.getDocument(myFixture.getFile()).getText();
    StringBuilder b = new StringBuilder();
    for (GutterMark gutterMarker : allMarkers) {
        if (gutterMarker instanceof LineMarkerInfo.LineMarkerGutterIconRenderer) {
            LineMarkerInfo lineMarkerInfo = ((LineMarkerInfo.LineMarkerGutterIconRenderer) gutterMarker).getLineMarkerInfo();
            b.append(lineMarkerInfo.startOffset).append(" - ").append(lineMarkerInfo.endOffset).append(": ").append('\'').append(text.substring(lineMarkerInfo.startOffset, lineMarkerInfo.endOffset)).append('\'').append(": ").append(lineMarkerInfo.getLineMarkerTooltip()).append("\n");
            if (!(lineMarkerInfo instanceof RelatedItemLineMarkerInfo)) {
                b.append("Uknown targets: ").append(lineMarkerInfo.getClass().getSimpleName()).append("\n");
                continue;
            }
            Collection<GotoRelatedItem> gotoRelatedItems = ((RelatedItemLineMarkerInfo) lineMarkerInfo).createGotoRelatedItems();
            b.append("Targets: ").append(gotoRelatedItems.size()).append("\n");
            for (GotoRelatedItem gotoRelatedItem : gotoRelatedItems) {
                PsiElement element = gotoRelatedItem.getElement();
                if (element != null) {
                    b.append("\t").append(serializePsiElement(element)).append("\n");
                }
            }
        } else {
            b.append(gutterMarker);
        }
        b.append("\n");
    }
    UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), b.toString());
}
Also used : RelatedItemLineMarkerInfo(com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) RelatedItemLineMarkerInfo(com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo) GutterMark(com.intellij.codeInsight.daemon.GutterMark) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) PsiElement(com.intellij.psi.PsiElement)

Example 3 with RelatedItemLineMarkerInfo

use of com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo in project intellij-community by JetBrains.

the class RelatedItemLineMarkerGotoAdapter method getItems.

@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull PsiElement context) {
    List<PsiElement> parents = new ArrayList<>();
    PsiElement current = context;
    Set<Language> languages = new HashSet<>();
    while (current != null) {
        parents.add(current);
        languages.add(current.getLanguage());
        if (current instanceof PsiFile)
            break;
        current = current.getParent();
    }
    List<LineMarkerProvider> providers = new ArrayList<>();
    for (Language language : languages) {
        providers.addAll(LineMarkersPass.getMarkerProviders(language, context.getProject()));
    }
    List<GotoRelatedItem> items = new ArrayList<>();
    for (LineMarkerProvider provider : providers) {
        if (provider instanceof RelatedItemLineMarkerProvider) {
            List<RelatedItemLineMarkerInfo> markers = new ArrayList<>();
            RelatedItemLineMarkerProvider relatedItemLineMarkerProvider = (RelatedItemLineMarkerProvider) provider;
            for (PsiElement parent : parents) {
                ContainerUtil.addIfNotNull(markers, relatedItemLineMarkerProvider.getLineMarkerInfo(parent));
            }
            relatedItemLineMarkerProvider.collectNavigationMarkers(parents, markers, true);
            addItemsForMarkers(markers, items);
        }
    }
    return items;
}
Also used : RelatedItemLineMarkerProvider(com.intellij.codeInsight.daemon.RelatedItemLineMarkerProvider) LineMarkerProvider(com.intellij.codeInsight.daemon.LineMarkerProvider) RelatedItemLineMarkerInfo(com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo) Language(com.intellij.lang.Language) RelatedItemLineMarkerProvider(com.intellij.codeInsight.daemon.RelatedItemLineMarkerProvider) PsiFile(com.intellij.psi.PsiFile) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RelatedItemLineMarkerInfo (com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo)3 PsiElement (com.intellij.psi.PsiElement)3 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)2 PsiFile (com.intellij.psi.PsiFile)2 NotNull (org.jetbrains.annotations.NotNull)2 GutterMark (com.intellij.codeInsight.daemon.GutterMark)1 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)1 LineMarkerProvider (com.intellij.codeInsight.daemon.LineMarkerProvider)1 RelatedItemLineMarkerProvider (com.intellij.codeInsight.daemon.RelatedItemLineMarkerProvider)1 Language (com.intellij.lang.Language)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 SmartPointerManager (com.intellij.psi.SmartPointerManager)1 MouseEvent (java.awt.event.MouseEvent)1