Search in sources :

Example 6 with NavigatablePsiElement

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;
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) VirtualFile(com.intellij.openapi.vfs.VirtualFile) RefEntity(com.intellij.codeInspection.reference.RefEntity) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Document(com.intellij.openapi.editor.Document) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with NavigatablePsiElement

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;
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartMethodDeclaration(com.jetbrains.lang.dart.psi.DartMethodDeclaration) ItemPresentation(com.intellij.navigation.ItemPresentation) CompositeAppearance(com.intellij.openapi.roots.ui.util.CompositeAppearance) PsiFile(com.intellij.psi.PsiFile) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement)

Example 8 with NavigatablePsiElement

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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartClass(com.jetbrains.lang.dart.psi.DartClass) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement)

Example 9 with NavigatablePsiElement

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();
}
Also used : ItemPresentation(com.intellij.navigation.ItemPresentation) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with NavigatablePsiElement

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());
    }
}
Also used : DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) ArrayList(java.util.ArrayList) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement)

Aggregations

NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)11 PsiElement (com.intellij.psi.PsiElement)7 Nullable (org.jetbrains.annotations.Nullable)4 ItemPresentation (com.intellij.navigation.ItemPresentation)3 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)2 CompositeAppearance (com.intellij.openapi.roots.ui.util.CompositeAppearance)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 DartClass (com.jetbrains.lang.dart.psi.DartClass)2 PyClass (com.jetbrains.python.psi.PyClass)2 MouseEvent (java.awt.event.MouseEvent)2 GutterIconNavigationHandler (com.intellij.codeInsight.daemon.GutterIconNavigationHandler)1 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)1 ListBackgroundUpdaterTask (com.intellij.codeInsight.navigation.ListBackgroundUpdaterTask)1 RefElement (com.intellij.codeInspection.reference.RefElement)1 RefEntity (com.intellij.codeInspection.reference.RefEntity)1 FindUtil (com.intellij.find.FindUtil)1 PsiCopyPasteManager (com.intellij.ide.PsiCopyPasteManager)1 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)1 PsiElementListCellRenderer (com.intellij.ide.util.PsiElementListCellRenderer)1