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)));
}
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());
}
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;
}
Aggregations