Search in sources :

Example 41 with Navigatable

use of com.intellij.pom.Navigatable in project android by JetBrains.

the class OpenFileHyperlink method execute.

@Override
protected void execute(@NotNull Project project) {
    VirtualFile projectFile = project.getProjectFile();
    if (projectFile == null) {
        // This is the default project. This will NEVER happen.
        return;
    }
    VirtualFile file = projectFile.getParent().getFileSystem().findFileByPath(myFilePath);
    if (file != null) {
        Navigatable openFile = new OpenFileDescriptor(project, file, myLineNumber, myColumn, false);
        if (openFile.canNavigate()) {
            openFile.navigate(true);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Navigatable(com.intellij.pom.Navigatable)

Example 42 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-plugins by JetBrains.

the class ResolveExternalInlineStyleSourceAction method find.

private Navigatable find(XmlTag parent, boolean firstLevel) {
    for (XmlTag xmlTag : parent.getSubTags()) {
        String localName = xmlTag.getLocalName();
        if (firstLevel && ignoredRootTags.contains(localName)) {
            continue;
        }
        XmlElementDescriptor xmlTagDescriptor = xmlTag.getDescriptor();
        if (xmlTagDescriptor instanceof ClassBackedElementDescriptor) {
            Navigatable result;
            if (xmlTagDescriptor.getQualifiedName().equals(elementFqn)) {
                result = findTargetIfStyleDeclarationOwner(xmlTag);
                if (result != null) {
                    return result;
                }
            }
            result = find(xmlTag, false);
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag) Navigatable(com.intellij.pom.Navigatable)

Example 43 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-plugins by JetBrains.

the class ResolveExternalInlineStyleSourceAction method findTargetIfStyleDeclarationOwner.

private Navigatable findTargetIfStyleDeclarationOwner(XmlTag parent) {
    int foundCount = 0;
    Navigatable target = null;
    for (XmlAttribute attribute : parent.getAttributes()) {
        XmlAttributeDescriptor descriptor = attribute.getDescriptor();
        // 8
        if (descriptor instanceof AnnotationBackedDescriptor) {
            String ourValue = properties.get(descriptor.getName());
            if (ourValue != null) {
                if (attribute.getDisplayValue().equals(ourValue)) {
                    foundCount++;
                    if (descriptor.getName().equals(targetStyleName)) {
                        target = (Navigatable) attribute;
                    }
                    if (foundCount == properties.size()) {
                        return target;
                    }
                }
            }
        }
    }
    for (XmlTag tag : parent.getSubTags()) {
        XmlElementDescriptor descriptor = tag.getDescriptor();
        if (descriptor instanceof AnnotationBackedDescriptor && ((PsiPresentableMetaData) descriptor).getTypeName().equals(FlexAnnotationNames.STYLE)) {
            String ourValue = properties.get(descriptor.getName());
            if (ourValue != null) {
                if (tag.getSubTags().length == 0 && tag.getValue().getTrimmedText().equals(ourValue)) {
                    foundCount++;
                    if (descriptor.getName().equals(targetStyleName)) {
                        target = (Navigatable) tag;
                    }
                    if (foundCount == properties.size()) {
                        return target;
                    }
                }
            }
        }
    }
    return null;
}
Also used : PsiPresentableMetaData(com.intellij.psi.meta.PsiPresentableMetaData) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) Navigatable(com.intellij.pom.Navigatable) XmlTag(com.intellij.psi.xml.XmlTag)

Example 44 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class SlicePanel method createTree.

@NotNull
private JTree createTree() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    final Tree tree = new Tree(new DefaultTreeModel(root));
    tree.setOpaque(false);
    tree.setToggleClickCount(-1);
    SliceUsageCellRendererBase renderer = myProvider.getRenderer();
    renderer.setOpaque(false);
    tree.setCellRenderer(renderer);
    UIUtil.setLineStyleAngled(tree);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setSelectionPath(new TreePath(root.getPath()));
    //ActionGroup group = (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_METHOD_HIERARCHY_POPUP);
    //PopupHandler.installPopupHandler(tree, group, ActionPlaces.METHOD_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
    EditSourceOnDoubleClickHandler.install(tree);
    new TreeSpeedSearch(tree);
    TreeUtil.installActions(tree);
    ToolTipManager.sharedInstance().registerComponent(tree);
    myAutoScrollToSourceHandler.install(tree);
    tree.getSelectionModel().addTreeSelectionListener(e -> treeSelectionChanged());
    tree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                List<Navigatable> navigatables = getNavigatables();
                if (navigatables.isEmpty())
                    return;
                for (Navigatable navigatable : navigatables) {
                    if (navigatable instanceof AbstractTreeNode && ((AbstractTreeNode) navigatable).getValue() instanceof Usage) {
                        navigatable = (Usage) ((AbstractTreeNode) navigatable).getValue();
                    }
                    if (navigatable.canNavigateToSource()) {
                        navigatable.navigate(false);
                        if (navigatable instanceof Usage) {
                            ((Usage) navigatable).highlightInEditor();
                        }
                    }
                }
                e.consume();
            }
        }
    });
    tree.addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) {
        }

        @Override
        public void treeWillExpand(TreeExpansionEvent event) {
            TreePath path = event.getPath();
            SliceNode node = fromPath(path);
            node.calculateDupNode();
        }
    });
    return tree;
}
Also used : TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) Usage(com.intellij.usages.Usage) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Navigatable(com.intellij.pom.Navigatable) KeyEvent(java.awt.event.KeyEvent) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree) ArrayList(java.util.ArrayList) List(java.util.List) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) NotNull(org.jetbrains.annotations.NotNull)

Example 45 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class XDebuggerUtilImpl method createPositionByElement.

@Override
@Nullable
public XSourcePosition createPositionByElement(PsiElement element) {
    if (element == null)
        return null;
    PsiFile psiFile = element.getContainingFile();
    if (psiFile == null)
        return null;
    final VirtualFile file = psiFile.getVirtualFile();
    if (file == null)
        return null;
    final SmartPsiElementPointer<PsiElement> pointer = SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element);
    return new XSourcePosition() {

        private volatile XSourcePosition myDelegate;

        private XSourcePosition getDelegate() {
            if (myDelegate == null) {
                myDelegate = ReadAction.compute(() -> {
                    PsiElement elem = pointer.getElement();
                    return XSourcePositionImpl.createByOffset(pointer.getVirtualFile(), elem != null ? elem.getTextOffset() : -1);
                });
            }
            return myDelegate;
        }

        @Override
        public int getLine() {
            return getDelegate().getLine();
        }

        @Override
        public int getOffset() {
            return getDelegate().getOffset();
        }

        @NotNull
        @Override
        public VirtualFile getFile() {
            return file;
        }

        @NotNull
        @Override
        public Navigatable createNavigatable(@NotNull Project project) {
            // no need to create delegate here, it may be expensive
            if (myDelegate != null) {
                return myDelegate.createNavigatable(project);
            }
            PsiElement elem = pointer.getElement();
            if (elem instanceof Navigatable) {
                return ((Navigatable) elem);
            }
            return NonNavigatable.INSTANCE;
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) NotNull(org.jetbrains.annotations.NotNull) NonNavigatable(com.intellij.pom.NonNavigatable) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.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