use of com.intellij.psi.NavigatablePsiElement in project intellij-community by JetBrains.
the class InspectionResultsViewUtil method getNavigatableForInvalidNode.
@Nullable
static Navigatable getNavigatableForInvalidNode(ProblemDescriptionNode node) {
RefEntity element = node.getElement();
while (element != null && !element.isValid()) {
element = element.getOwner();
}
if (!(element instanceof RefElement))
return null;
PsiElement containingElement = ((RefElement) element).getElement();
if (!(containingElement instanceof NavigatablePsiElement) || !containingElement.isValid())
return null;
final int lineNumber = node.getLineNumber();
if (lineNumber != -1) {
final PsiFile containingFile = containingElement.getContainingFile();
if (containingFile != null) {
final VirtualFile file = containingFile.getVirtualFile();
final Document document = FileDocumentManager.getInstance().getDocument(file);
if (document != null && document.getLineCount() > lineNumber) {
return new OpenFileDescriptor(containingElement.getProject(), file, lineNumber, 0);
}
}
}
return (Navigatable) containingElement;
}
use of com.intellij.psi.NavigatablePsiElement in project intellij-plugins by JetBrains.
the class DartHierarchyNodeDescriptor method update.
@Override
public boolean update() {
boolean changes = super.update();
final CompositeAppearance oldText = myHighlightedText;
myHighlightedText = new CompositeAppearance();
NavigatablePsiElement element = (NavigatablePsiElement) getPsiElement();
if (element == null) {
return invalidElement();
}
final ItemPresentation presentation = element.getPresentation();
if (presentation != null) {
if (element instanceof DartMethodDeclaration) {
if (DartComponentType.typeOf(element) != DartComponentType.CONSTRUCTOR) {
// Do not print constructors as Class.Class.Class(args) Class
final DartClass cls = PsiTreeUtil.getParentOfType(element, DartClass.class);
if (cls != null) {
myHighlightedText.getEnding().addText(cls.getName() + ".");
}
}
}
myHighlightedText.getEnding().addText(presentation.getPresentableText());
PsiFile file = element.getContainingFile();
if (file != null) {
myHighlightedText.getEnding().addText(" (" + file.getName() + ")", HierarchyNodeDescriptor.getPackageNameAttributes());
}
}
myName = myHighlightedText.getText();
if (!Comparing.equal(myHighlightedText, oldText)) {
changes = true;
}
return changes;
}
use of com.intellij.psi.NavigatablePsiElement in project intellij-plugins by JetBrains.
the class DartServerGotoSuperHandler method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
final PsiElement at = file.findElementAt(editor.getCaretModel().getOffset());
final DartComponent inComponent = PsiTreeUtil.getParentOfType(at, DartComponent.class);
final DartComponent inClass = PsiTreeUtil.getParentOfType(at, DartClass.class);
if (inClass == null || inComponent == null || inComponent.getComponentName() == null) {
return;
}
final boolean isInClass = inComponent instanceof DartClass;
// ask for the super type hierarchy
final VirtualFile virtualFile = file.getVirtualFile();
final int offset = inComponent.getComponentName().getTextRange().getStartOffset();
final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(project).search_getTypeHierarchy(virtualFile, offset, true);
// build list of DartComponent(s)
final List<DartComponent> supers = Lists.newArrayList();
if (!items.isEmpty()) {
TypeHierarchyItem seed = items.get(0);
{
final Integer superIndex = seed.getSuperclass();
if (superIndex != null) {
final TypeHierarchyItem superItem = items.get(superIndex);
addSuperComponent(project, supers, isInClass, superItem);
}
}
for (int superIndex : seed.getMixins()) {
final TypeHierarchyItem superItem = items.get(superIndex);
addSuperComponent(project, supers, isInClass, superItem);
}
for (int superIndex : seed.getInterfaces()) {
final TypeHierarchyItem superItem = items.get(superIndex);
addSuperComponent(project, supers, isInClass, superItem);
}
}
// prepare the title
final String title;
if (isInClass) {
title = DartBundle.message("goto.super.class.chooser.title");
} else {
title = CodeInsightBundle.message("goto.super.method.chooser.title");
}
// open DartComponent(s)
final NavigatablePsiElement[] targets = DartResolveUtil.getComponentNameArray(supers);
PsiElementListNavigator.openTargets(editor, targets, title, null, new DefaultPsiElementCellRenderer());
}
use of com.intellij.psi.NavigatablePsiElement in project intellij-plugins by JetBrains.
the class DartStructureViewElement method getPresentableText.
@Nullable
@Override
public String getPresentableText() {
final NavigatablePsiElement element = getElement();
final ItemPresentation presentation = element == null ? null : element.getPresentation();
return presentation == null ? null : presentation.getPresentableText();
}
use of com.intellij.psi.NavigatablePsiElement in project intellij-community by JetBrains.
the class PyLineMarkerNavigator method navigate.
@Override
public void navigate(final MouseEvent e, final T elt) {
final List<NavigatablePsiElement> navElements = new ArrayList<>();
final Query<T> elementQuery = search(elt, TypeEvalContext.userInitiated(elt.getProject(), elt.getContainingFile()));
if (elementQuery == null) {
return;
}
elementQuery.forEach(psiElement -> {
if (psiElement instanceof NavigatablePsiElement) {
navElements.add((NavigatablePsiElement) psiElement);
}
return true;
});
/**
* For test purposes, we should be able to access list of methods to check em.
* {@link PsiElementListNavigator} simply opens then (hence it is swing-based) and can't be used in tests.
* So, in unit tests we save data in element and data could be obtained with {@link #getNavigationTargets(UserDataHolder)}
*/
final NavigatablePsiElement[] methods = navElements.toArray(new NavigatablePsiElement[navElements.size()]);
if (ApplicationManager.getApplication().isUnitTestMode()) {
elt.putUserData(MARKERS, methods);
} else {
PsiElementListNavigator.openTargets(e, methods, getTitle(elt), null, new DefaultPsiElementCellRenderer());
}
}
Aggregations