use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class PsiNavigateUtil method navigate.
public static void navigate(@Nullable final PsiElement psiElement) {
if (psiElement != null && psiElement.isValid()) {
final PsiElement navigationElement = psiElement.getNavigationElement();
final int offset = navigationElement instanceof PsiFile ? -1 : navigationElement.getTextOffset();
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(psiElement);
if (virtualFile != null && virtualFile.isValid()) {
new OpenFileDescriptor(navigationElement.getProject(), virtualFile, offset).navigate(true);
} else if (navigationElement instanceof Navigatable) {
((Navigatable) navigationElement).navigate(true);
}
}
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class InspectionResultsView method getSelectedNavigatable.
@Nullable
private Navigatable getSelectedNavigatable(final CommonProblemDescriptor descriptor, final PsiElement psiElement) {
if (descriptor instanceof ProblemDescriptorBase) {
Navigatable navigatable = ((ProblemDescriptorBase) descriptor).getNavigatable();
if (navigatable != null) {
return navigatable;
}
}
if (psiElement == null || !psiElement.isValid())
return null;
PsiFile containingFile = psiElement.getContainingFile();
VirtualFile virtualFile = containingFile == null ? null : containingFile.getVirtualFile();
if (virtualFile != null) {
int startOffset = psiElement.getTextOffset();
if (descriptor instanceof ProblemDescriptorBase) {
final TextRange textRange = ((ProblemDescriptorBase) descriptor).getTextRangeForNavigation();
if (textRange != null) {
if (virtualFile instanceof VirtualFileWindow) {
virtualFile = ((VirtualFileWindow) virtualFile).getDelegate();
}
startOffset = textRange.getStartOffset();
}
}
return new OpenFileDescriptor(myProject, virtualFile, startOffset);
}
return null;
}
use of com.intellij.pom.Navigatable 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.pom.Navigatable in project intellij-community by JetBrains.
the class ShowUsagesAction method prepareTable.
@NotNull
private Runnable prepareTable(final MyTable table, final Editor editor, final RelativePoint popupPosition, final FindUsagesHandler handler, final int maxUsages, @NotNull final FindUsagesOptions options, final boolean previewMode) {
SpeedSearchBase<JTable> speedSearch = new MySpeedSearch(table);
speedSearch.setComparator(new SpeedSearchComparator(false));
table.setRowHeight(PlatformIcons.CLASS_ICON.getIconHeight() + 2);
table.setShowGrid(false);
table.setShowVerticalLines(false);
table.setShowHorizontalLines(false);
table.setTableHeader(null);
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
table.setIntercellSpacing(new Dimension(0, 0));
final AtomicReference<List<Object>> selectedUsages = new AtomicReference<>();
final AtomicBoolean moreUsagesSelected = new AtomicBoolean();
final AtomicBoolean outsideScopeUsagesSelected = new AtomicBoolean();
table.getSelectionModel().addListSelectionListener(e -> {
selectedUsages.set(null);
outsideScopeUsagesSelected.set(false);
moreUsagesSelected.set(false);
List<Object> usages = null;
for (int i : table.getSelectedRows()) {
Object value = table.getValueAt(i, 0);
if (value instanceof UsageNode) {
Usage usage = ((UsageNode) value).getUsage();
if (usage == USAGES_OUTSIDE_SCOPE_SEPARATOR) {
outsideScopeUsagesSelected.set(true);
usages = null;
break;
} else if (usage == MORE_USAGES_SEPARATOR) {
moreUsagesSelected.set(true);
usages = null;
break;
} else {
if (usages == null)
usages = new ArrayList<>();
usages.add(usage instanceof UsageInfo2UsageAdapter ? ((UsageInfo2UsageAdapter) usage).getUsageInfo().copy() : usage);
}
}
}
selectedUsages.set(usages);
});
final Runnable itemChosenCallback = () -> {
if (moreUsagesSelected.get()) {
appendMoreUsages(editor, popupPosition, handler, maxUsages, options);
return;
}
if (outsideScopeUsagesSelected.get()) {
options.searchScope = GlobalSearchScope.projectScope(handler.getProject());
showElementUsages(editor, popupPosition, handler, maxUsages, options);
return;
}
List<Object> usages = selectedUsages.get();
if (usages != null) {
for (Object usage : usages) {
if (usage instanceof UsageInfo) {
UsageViewUtil.navigateTo((UsageInfo) usage, true);
} else if (usage instanceof Navigatable) {
((Navigatable) usage).navigate(true);
}
}
}
};
if (previewMode) {
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
if (UIUtil.isActionClick(e, MouseEvent.MOUSE_RELEASED) && !UIUtil.isSelectionButtonDown(e) && !e.isConsumed()) {
itemChosenCallback.run();
}
}
});
table.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
itemChosenCallback.run();
}
}
});
}
return itemChosenCallback;
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class GotoClassAction method gotoActionPerformed.
@Override
public void gotoActionPerformed(@NotNull AnActionEvent e) {
final Project project = e.getProject();
if (project == null)
return;
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.class");
PsiDocumentManager.getInstance(project).commitAllDocuments();
final GotoClassModel2 model = new GotoClassModel2(project);
showNavigationPopup(e, model, new GotoActionCallback<Language>() {
@Override
protected ChooseByNameFilter<Language> createFilter(@NotNull ChooseByNamePopup popup) {
return new ChooseByNameLanguageFilter(popup, model, GotoClassSymbolConfiguration.getInstance(project), project);
}
@Override
public void elementChosen(ChooseByNamePopup popup, Object element) {
ApplicationManager.getApplication().runReadAction(() -> {
if (element instanceof PsiElement && ((PsiElement) element).isValid()) {
PsiElement psiElement = getElement(((PsiElement) element), popup);
psiElement = psiElement.getNavigationElement();
VirtualFile file = PsiUtilCore.getVirtualFile(psiElement);
if (file != null && popup.getLinePosition() != -1) {
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition());
Navigatable n = descriptor.setUseCurrentWindow(popup.isOpenInCurrentWindowRequested());
if (n.canNavigate()) {
n.navigate(true);
return;
}
}
if (file != null && popup.getMemberPattern() != null) {
NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested());
Navigatable member = findMember(popup.getMemberPattern(), psiElement, file);
if (member != null) {
member.navigate(true);
}
}
NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested());
} else {
EditSourceUtil.navigate(((NavigationItem) element), true, popup.isOpenInCurrentWindowRequested());
}
});
}
}, IdeBundle.message("go.to.class.toolwindow.title"), true);
}
Aggregations