use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class GotoClassAction method findMember.
@Nullable
private static Navigatable findMember(String pattern, PsiElement psiElement, VirtualFile file) {
final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiElement.getLanguage());
final StructureViewBuilder builder = factory == null ? null : factory.getStructureViewBuilder(psiElement.getContainingFile());
final FileEditor[] editors = FileEditorManager.getInstance(psiElement.getProject()).getEditors(file);
if (builder == null || editors.length == 0) {
return null;
}
final StructureView view = builder.createStructureView(editors[0], psiElement.getProject());
try {
final StructureViewTreeElement element = findElement(view.getTreeModel().getRoot(), psiElement, 4);
if (element == null) {
return null;
}
final MinusculeMatcher matcher = NameUtil.buildMatcher(pattern).build();
int max = Integer.MIN_VALUE;
Object target = null;
for (TreeElement treeElement : element.getChildren()) {
if (treeElement instanceof StructureViewTreeElement) {
String presentableText = treeElement.getPresentation().getPresentableText();
if (presentableText != null) {
final int degree = matcher.matchingDegree(presentableText);
if (degree > max) {
max = degree;
target = ((StructureViewTreeElement) treeElement).getValue();
}
}
}
}
return target instanceof Navigatable ? (Navigatable) target : null;
} finally {
Disposer.dispose(view);
}
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class OverridingDefineRenderer method doClickAction.
static void doClickAction(AnActionEvent e, Collection<Define> set, String title) {
if (set.size() == 1) {
final Navigatable n = (Navigatable) set.iterator().next().getPsiElement();
OpenSourceUtil.navigate(true, n);
} else {
final Define[] array = set.toArray(new Define[set.size()]);
NavigationUtil.getPsiElementPopup(ContainerUtil.map(array, define -> define.getPsiElement(), PsiElement.EMPTY_ARRAY), title).show(new RelativePoint((MouseEvent) e.getInputEvent()));
}
}
use of com.intellij.pom.Navigatable in project kotlin by JetBrains.
the class GotoSuperActionHandler method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(GotoSuperAction.FEATURE_ID);
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
if (element == null)
return;
@SuppressWarnings("unchecked") KtDeclaration declaration = PsiTreeUtil.getParentOfType(element, KtNamedFunction.class, KtClass.class, KtProperty.class, KtObjectDeclaration.class);
if (declaration == null)
return;
DeclarationDescriptor descriptor = ResolutionUtils.resolveToDescriptor(declaration, BodyResolveMode.PARTIAL);
List<PsiElement> superDeclarations = findSuperDeclarations(descriptor);
if (superDeclarations == null || superDeclarations.isEmpty())
return;
if (superDeclarations.size() == 1) {
Navigatable navigatable = EditSourceUtil.getDescriptor(superDeclarations.get(0));
if (navigatable != null && navigatable.canNavigate()) {
navigatable.navigate(true);
}
} else {
String message = getTitle(descriptor);
PsiElement[] superDeclarationsArray = PsiUtilCore.toPsiElementArray(superDeclarations);
JBPopup popup = descriptor instanceof ClassDescriptor ? NavigationUtil.getPsiElementPopup(superDeclarationsArray, message) : NavigationUtil.getPsiElementPopup(superDeclarationsArray, new KtFunctionPsiElementCellRenderer(), message);
popup.showInBestPositionFor(editor);
}
}
use of com.intellij.pom.Navigatable in project intellij by bazelbuild.
the class BlazeProblemsView method addMessage.
public void addMessage(IssueOutput issue, @Nullable Navigatable openInConsole) {
if (!problems.add(issue.toString())) {
return;
}
int count = problemCount.incrementAndGet();
if (count > MAX_ISSUES) {
return;
}
if (count == MAX_ISSUES) {
issue = IssueOutput.warn("Too many problems found. Only showing the first " + MAX_ISSUES).build();
}
VirtualFile file = issue.getFile() != null ? resolveVirtualFile(issue.getFile()) : null;
Navigatable navigatable = issue.getNavigatable();
if (navigatable == null && file != null) {
navigatable = new OpenFileDescriptor(project, file, issue.getLine() - 1, issue.getColumn() - 1);
}
IssueOutput.Category category = issue.getCategory();
int type = translateCategory(category);
String[] text = convertMessage(issue);
String groupName = file != null ? file.getPresentableUrl() : category.name();
addMessage(type, text, groupName, file, navigatable, openInConsole, getExportTextPrefix(issue), getRenderTextPrefix(issue));
if (focusProblemsViewOnIssue && !didFocusProblemsView.get()) {
didFocusProblemsView.set(true);
focusProblemsView();
}
}
use of com.intellij.pom.Navigatable in project intellij by bazelbuild.
the class IssueOutputFilter method getHyperlinkInfo.
@Nullable
private static HyperlinkInfo getHyperlinkInfo(IssueOutput issue) {
Navigatable navigatable = issue.getNavigatable();
if (navigatable != null) {
return project -> navigatable.navigate(true);
}
VirtualFile vf = resolveVirtualFile(issue.getFile());
return vf != null ? project -> new OpenFileDescriptor(project, vf, issue.getLine() - 1, issue.getColumn() - 1).navigate(true) : null;
}
Aggregations