use of com.intellij.psi.NavigatablePsiElement in project intellij-community by JetBrains.
the class PyHierarchyNodeDescriptor method update.
@Override
public boolean update() {
boolean changes = super.update();
final CompositeAppearance oldText = myHighlightedText;
myHighlightedText = new CompositeAppearance();
NavigatablePsiElement element = (NavigatablePsiElement) getPsiElement();
if (element == null) {
final String invalidPrefix = IdeBundle.message("node.hierarchy.invalid");
if (!myHighlightedText.getText().startsWith(invalidPrefix)) {
myHighlightedText.getBeginning().addText(invalidPrefix, HierarchyNodeDescriptor.getInvalidPrefixAttributes());
}
return true;
}
final ItemPresentation presentation = element.getPresentation();
if (presentation != null) {
if (element instanceof PyFunction) {
final PyClass cls = ((PyFunction) element).getContainingClass();
if (cls != null) {
myHighlightedText.getEnding().addText(cls.getName() + ".");
}
}
myHighlightedText.getEnding().addText(presentation.getPresentableText());
myHighlightedText.getEnding().addText(" " + presentation.getLocationString(), HierarchyNodeDescriptor.getPackageNameAttributes());
}
myName = myHighlightedText.getText();
if (!Comparing.equal(myHighlightedText, oldText)) {
changes = true;
}
return changes;
}
use of com.intellij.psi.NavigatablePsiElement in project intellij-community by JetBrains.
the class PyLineMarkerProviderTest method testOverriding.
/**
* Checks method has "up" arrow when overrides, and this arrow works
*/
public void testOverriding() throws Exception {
myFixture.copyDirectoryToProject("lineMarkerTest", "");
myFixture.configureByFile("spam.py");
final ASTNode functionNode = myFixture.getElementAtCaret().getNode();
// We need IDENTIFIER node
final ASTNode[] functionChildren = functionNode.getChildren(TokenSet.create(PyTokenTypes.IDENTIFIER));
assert functionChildren.length == 1 : "Wrong number of identifiers: " + functionChildren.length;
final PsiElement element = functionChildren[0].getPsi();
@SuppressWarnings("unchecked") final LineMarkerInfo<PsiElement> lineMarkerInfo = new PyLineMarkerProvider().getLineMarkerInfo(element);
Assert.assertNotNull("No gutter displayed", lineMarkerInfo);
final GutterIconNavigationHandler<PsiElement> handler = lineMarkerInfo.getNavigationHandler();
Assert.assertNotNull("Gutter has no navigation handle", handler);
handler.navigate(new MouseEvent(new JLabel(), 0, 0, 0, 0, 0, 0, false), element);
final NavigatablePsiElement[] targets = PyLineMarkerNavigator.getNavigationTargets(element);
Assert.assertNotNull("No navigation targets found", targets);
Assert.assertThat("Wrong number of targets found", targets, Matchers.arrayWithSize(1));
final NavigatablePsiElement parentMethod = targets[0];
Assert.assertThat("Navigation target has wrong type", parentMethod, Matchers.instanceOf(PyPossibleClassMember.class));
final PyClass parentClass = ((PyPossibleClassMember) parentMethod).getContainingClass();
Assert.assertNotNull("Function overrides other function, but no parent displayed", parentClass);
Assert.assertEquals("Wrong parent class name", "Eggs", parentClass.getName());
}
use of com.intellij.psi.NavigatablePsiElement in project kotlin by JetBrains.
the class AbstractLineMarkersTest method assertNavigationElements.
private void assertNavigationElements(List<LineMarkerInfo> markers) {
List<String> navigationDataComments = KotlinTestUtils.getLastCommentsInFile((KtFile) myFixture.getFile(), KotlinTestUtils.CommentType.BLOCK_COMMENT, false);
if (navigationDataComments.isEmpty())
return;
for (String navigationComment : navigationDataComments) {
final String description = getLineMarkerDescription(navigationComment);
LineMarkerInfo navigateMarker = ContainerUtil.find(markers, new Condition<LineMarkerInfo>() {
@Override
public boolean value(LineMarkerInfo marker) {
String tooltip = marker.getLineMarkerTooltip();
return tooltip != null && tooltip.startsWith(description);
}
});
assertNotNull(String.format("Can't find marker for navigation check with description \"%s\"", description), navigateMarker);
GutterIconNavigationHandler handler = navigateMarker.getNavigationHandler();
if (handler instanceof SuperDeclarationMarkerNavigationHandler) {
PsiElement element = navigateMarker.getElement();
//noinspection unchecked
handler.navigate(null, element);
List<NavigatablePsiElement> navigateElements = ((SuperDeclarationMarkerNavigationHandler) handler).getNavigationElements();
Collections.sort(navigateElements, new Comparator<NavigatablePsiElement>() {
@Override
public int compare(@NotNull NavigatablePsiElement first, @NotNull NavigatablePsiElement second) {
String elementFirstStr = ReferenceUtils.renderAsGotoImplementation(first);
String elementSecondStr = ReferenceUtils.renderAsGotoImplementation(second);
return elementFirstStr.compareTo(elementSecondStr);
}
});
String actualNavigationData = NavigationTestUtils.getNavigateElementsText(myFixture.getProject(), navigateElements);
assertSameLines(getExpectedNavigationText(navigationComment), actualNavigationData);
} else {
Assert.fail("Only SuperDeclarationMarkerNavigationHandler are supported in navigate check");
}
}
}
use of com.intellij.psi.NavigatablePsiElement in project intellij-community by JetBrains.
the class PsiElementListNavigator method navigateOrCreatePopup.
@Nullable
private static JBPopup navigateOrCreatePopup(final NavigatablePsiElement[] targets, final String title, final String findUsagesTitle, final ListCellRenderer listRenderer, @Nullable final ListBackgroundUpdaterTask listUpdaterTask) {
return navigateOrCreatePopup(targets, title, findUsagesTitle, listRenderer, listUpdaterTask, selectedElements -> {
for (Object element : selectedElements) {
PsiElement selected = (PsiElement) element;
LOG.assertTrue(selected.isValid());
((NavigatablePsiElement) selected).navigate(true);
}
});
}
use of com.intellij.psi.NavigatablePsiElement in project intellij-community by JetBrains.
the class PsiElementListNavigator method navigateOrCreatePopup.
/**
* listUpdaterTask should be started after alarm is initialized so one-item popup won't blink
*/
@Nullable
public static JBPopup navigateOrCreatePopup(@NotNull final NavigatablePsiElement[] targets, final String title, final String findUsagesTitle, final ListCellRenderer listRenderer, @Nullable final ListBackgroundUpdaterTask listUpdaterTask, @NotNull final Consumer<Object[]> consumer) {
if (targets.length == 0)
return null;
if (targets.length == 1 && (listUpdaterTask == null || listUpdaterTask.isFinished())) {
consumer.consume(targets);
return null;
}
final CollectionListModel<NavigatablePsiElement> model = new CollectionListModel<>(targets);
final JBList list = new JBList(model);
HintUpdateSupply.installSimpleHintUpdateSupply(list);
list.setTransferHandler(new TransferHandler() {
@Nullable
@Override
protected Transferable createTransferable(JComponent c) {
final Object[] selectedValues = list.getSelectedValues();
final PsiElement[] copy = new PsiElement[selectedValues.length];
for (int i = 0; i < selectedValues.length; i++) {
copy[i] = (PsiElement) selectedValues[i];
}
return new PsiCopyPasteManager.MyTransferable(copy);
}
@Override
public int getSourceActions(JComponent c) {
return COPY;
}
});
list.setCellRenderer(listRenderer);
list.setFont(EditorUtil.getEditorFont());
final PopupChooserBuilder builder = new PopupChooserBuilder(list);
if (listRenderer instanceof PsiElementListCellRenderer) {
((PsiElementListCellRenderer) listRenderer).installSpeedSearch(builder);
}
PopupChooserBuilder popupChooserBuilder = builder.setTitle(title).setMovable(true).setResizable(true).setItemChoosenCallback(() -> {
int[] ids = list.getSelectedIndices();
if (ids == null || ids.length == 0)
return;
Object[] selectedElements = list.getSelectedValues();
consumer.consume(selectedElements);
}).setCancelCallback(() -> {
HintUpdateSupply.hideHint(list);
if (listUpdaterTask != null) {
listUpdaterTask.cancelTask();
}
return true;
});
final Ref<UsageView> usageView = new Ref<>();
if (findUsagesTitle != null) {
popupChooserBuilder = popupChooserBuilder.setCouldPin(popup -> {
final List<NavigatablePsiElement> items = model.getItems();
usageView.set(FindUtil.showInUsageView(null, items.toArray(new PsiElement[items.size()]), findUsagesTitle, targets[0].getProject()));
popup.cancel();
return false;
});
}
final JBPopup popup = popupChooserBuilder.createPopup();
builder.getScrollPane().setBorder(null);
builder.getScrollPane().setViewportBorder(null);
if (listUpdaterTask != null) {
listUpdaterTask.init((AbstractPopup) popup, list, usageView);
}
return popup;
}
Aggregations