Search in sources :

Example 11 with NavigationItem

use of com.intellij.navigation.NavigationItem in project intellij-plugins by JetBrains.

the class FlexHighlightingTest method checkNavigatableSymbols.

private void checkNavigatableSymbols(String s) {
    JavaScriptIndex scriptIndex = JavaScriptIndex.getInstance(myProject);
    String[] strings = scriptIndex.getSymbolNames();
    Arrays.sort(strings);
    assertTrue(Arrays.binarySearch(strings, s) >= 0);
    NavigationItem[] navigationItems = scriptIndex.getSymbolsByName(s, true);
    assertTrue(navigationItems.length > 0);
    boolean containedInLibrarySwf = false;
    for (NavigationItem navigationItem : navigationItems) {
        if (navigationItem instanceof JSNamedElement && "library.swf".equals(((PsiElement) navigationItem).getContainingFile().getName())) {
            containedInLibrarySwf = true;
            break;
        }
    }
    assertTrue(containedInLibrarySwf);
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) JavaScriptIndex(com.intellij.lang.javascript.index.JavaScriptIndex)

Example 12 with NavigationItem

use of com.intellij.navigation.NavigationItem in project intellij-plugins by JetBrains.

the class FlexXmlBackedMembersIndex method getItemsByName.

public static Collection<NavigationItem> getItemsByName(final String name, Project project) {
    Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(NAME, name, GlobalSearchScope.projectScope(project));
    final Collection<NavigationItem> result = new ArrayList<>();
    for (VirtualFile vFile : files) {
        PsiFile file = PsiManager.getInstance(project).findFile(vFile);
        if (!(file instanceof XmlFile)) {
            continue;
        }
        process((XmlFile) file, element -> {
            if (name.equals(getName(element))) {
                if (element instanceof JSNamedElement) {
                    result.add((JSNamedElement) element);
                } else {
                    XmlAttribute id = ((XmlTag) element).getAttribute("id");
                    if (id != null) {
                        XmlAttributeValue valueElement = id.getValueElement();
                        PsiElement[] children;
                        if (valueElement != null && (children = valueElement.getChildren()).length == 3) {
                            result.add(new TagNavigationItem(children[1], name));
                        }
                    }
                }
            }
        }, true);
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) NavigationItem(com.intellij.navigation.NavigationItem) PsiElementNavigationItem(com.intellij.navigation.PsiElementNavigationItem) JSNamedElement(com.intellij.lang.javascript.psi.JSNamedElement) FakePsiElement(com.intellij.psi.impl.FakePsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 13 with NavigationItem

use of com.intellij.navigation.NavigationItem in project intellij-elixir by KronicDeth.

the class GotoSymbolContributor method getItemsByName.

/*
     * Instance Methods
     */
/**
     * Returns the list of navigation items matching the specified name.
     *
     * @param name                   the name selected from the list.
     * @param pattern                the original pattern entered in the dialog
     * @param project                the project in which the navigation is performed.
     * @param includeNonProjectItems if true, the navigation items for non-project items (for example,
     *                               library classes) should be included in the returned array.
     * @return the array of navigation items.
     */
@NotNull
@Override
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
    GlobalSearchScope scope = globalSearchScope(project, includeNonProjectItems);
    Collection<NamedElement> result = StubIndex.getElements(AllName.KEY, name, project, scope, NamedElement.class);
    List<NavigationItem> items = ContainerUtil.newArrayListWithCapacity(result.size());
    EnclosingModularByCall enclosingModularByCall = new EnclosingModularByCall();
    Map<CallDefinition.Tuple, CallDefinition> callDefinitionByTuple = new HashMap<CallDefinition.Tuple, CallDefinition>();
    for (final NamedElement element : result) {
        // Use navigation element so that source element is used for compiled elements
        PsiElement sourceElement = element.getNavigationElement();
        if (sourceElement instanceof Call) {
            getItemsByNameFromCall(name, items, enclosingModularByCall, callDefinitionByTuple, (Call) sourceElement);
        }
    }
    return items.toArray(new NavigationItem[items.size()]);
}
Also used : Call(org.elixir_lang.psi.call.Call) AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) NavigationItem(com.intellij.navigation.NavigationItem) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) HashMap(java.util.HashMap) NamedElement(org.elixir_lang.psi.NamedElement) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with NavigationItem

use of com.intellij.navigation.NavigationItem in project intellij-plugins by JetBrains.

the class FlexXmlBackedSymbolContributor method getItemsByName.

@NotNull
public NavigationItem[] getItemsByName(String name, final String pattern, Project project, boolean includeNonProjectItems) {
    Collection<NavigationItem> result = new THashSet<>();
    result.addAll(FlexXmlBackedMembersIndex.getItemsByName(name, project));
    for (NavigationItem item : JavaScriptClassContributor.getItemsByNameStatic(name, project, includeNonProjectItems)) {
        if (item instanceof XmlBackedJSClassImpl) {
            result.add(item);
        }
    }
    return result.toArray(new NavigationItem[result.size()]);
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with NavigationItem

use of com.intellij.navigation.NavigationItem in project intellij-community by JetBrains.

the class GotoFileCellRenderer method customizeNonPsiElementLeftRenderer.

@Override
protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) {
    if (!(value instanceof NavigationItem))
        return false;
    NavigationItem item = (NavigationItem) value;
    TextAttributes attributes = getNavigationItemAttributes(item);
    SimpleTextAttributes nameAttributes = attributes != null ? SimpleTextAttributes.fromTextAttributes(attributes) : null;
    Color color = list.getForeground();
    if (nameAttributes == null)
        nameAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, color);
    renderer.append(item + " ", nameAttributes);
    ItemPresentation itemPresentation = item.getPresentation();
    assert itemPresentation != null;
    renderer.setIcon(itemPresentation.getIcon(true));
    String locationString = itemPresentation.getLocationString();
    if (!StringUtil.isEmpty(locationString)) {
        renderer.append(locationString, new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.GRAY));
    }
    return true;
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) JBColor(com.intellij.ui.JBColor) ItemPresentation(com.intellij.navigation.ItemPresentation) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Aggregations

NavigationItem (com.intellij.navigation.NavigationItem)25 ItemPresentation (com.intellij.navigation.ItemPresentation)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 NotNull (org.jetbrains.annotations.NotNull)6 PsiFile (com.intellij.psi.PsiFile)5 PsiElementNavigationItem (com.intellij.navigation.PsiElementNavigationItem)4 PsiElement (com.intellij.psi.PsiElement)4 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 ArrayList (java.util.ArrayList)4 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)3 Project (com.intellij.openapi.project.Project)3 ChooseByNameContributor (com.intellij.navigation.ChooseByNameContributor)2 Logger (com.intellij.openapi.diagnostic.Logger)2 com.intellij.psi (com.intellij.psi)2 HintManager (com.intellij.codeInsight.hint.HintManager)1 DebuggerBundle (com.intellij.debugger.DebuggerBundle)1 NoDataException (com.intellij.debugger.NoDataException)1 SourcePosition (com.intellij.debugger.SourcePosition)1 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 PositionManagerImpl (com.intellij.debugger.engine.PositionManagerImpl)1