Search in sources :

Example 66 with Navigatable

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);
    }
}
Also used : PsiStructureViewFactory(com.intellij.lang.PsiStructureViewFactory) LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StructureView(com.intellij.ide.structureView.StructureView) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Example 67 with Navigatable

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()));
    }
}
Also used : Define(org.intellij.plugins.relaxNG.model.Define) MouseEvent(java.awt.event.MouseEvent) RelativePoint(com.intellij.ui.awt.RelativePoint) Navigatable(com.intellij.pom.Navigatable)

Example 68 with Navigatable

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);
    }
}
Also used : JBPopup(com.intellij.openapi.ui.popup.JBPopup) PsiElement(com.intellij.psi.PsiElement) Navigatable(com.intellij.pom.Navigatable)

Example 69 with Navigatable

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();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) Navigatable(com.intellij.pom.Navigatable)

Example 70 with Navigatable

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;
}
Also used : ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) ToolWindow(com.intellij.openapi.wm.ToolWindow) Filter(com.intellij.execution.filters.Filter) VirtualFile(com.intellij.openapi.vfs.VirtualFile) TextRange(com.intellij.openapi.util.TextRange) BlazeConsoleToolWindowFactory(com.google.idea.blaze.base.console.BlazeConsoleToolWindowFactory) VfsUtils(com.google.idea.blaze.base.io.VfsUtils) File(java.io.File) ArrayList(java.util.ArrayList) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Parser(com.google.idea.blaze.base.issueparser.BlazeIssueParser.Parser) BlazeConsoleView(com.google.idea.blaze.base.console.BlazeConsoleView) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Project(com.intellij.openapi.project.Project) BlazeInvocationContext(com.google.idea.blaze.base.command.BlazeInvocationContext) Navigatable(com.intellij.pom.Navigatable) Logger(com.intellij.openapi.diagnostic.Logger) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) BlazeProblemsView(com.google.idea.blaze.base.ui.problems.BlazeProblemsView) Nullable(javax.annotation.Nullable) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Navigatable(com.intellij.pom.Navigatable) Nullable(javax.annotation.Nullable)

Aggregations

Navigatable (com.intellij.pom.Navigatable)70 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)19 Project (com.intellij.openapi.project.Project)14 Nullable (org.jetbrains.annotations.Nullable)14 PsiElement (com.intellij.psi.PsiElement)11 ArrayList (java.util.ArrayList)9 PsiFile (com.intellij.psi.PsiFile)7 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 TreePath (javax.swing.tree.TreePath)7 NotNull (org.jetbrains.annotations.NotNull)6 Editor (com.intellij.openapi.editor.Editor)4 List (java.util.List)4 TextRange (com.intellij.openapi.util.TextRange)3 XmlTag (com.intellij.psi.xml.XmlTag)3 BlazeConsoleView (com.google.idea.blaze.base.console.BlazeConsoleView)2 IssueOutput (com.google.idea.blaze.base.scope.output.IssueOutput)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Document (com.intellij.openapi.editor.Document)2