Search in sources :

Example 1 with NamedElement

use of org.elixir_lang.psi.NamedElement in project intellij-elixir by KronicDeth.

the class MultiResolve method indexedNamedElements.

/*
     * Private Static Methods
     */
@NotNull
private static Collection<NamedElement> indexedNamedElements(@NotNull PsiNamedElement match, @NotNull String unaliasedName) {
    Project project = match.getProject();
    Collection<NamedElement> indexNamedElementCollection;
    if (DumbService.isDumb(project)) {
        indexNamedElementCollection = Collections.emptyList();
    } else {
        indexNamedElementCollection = StubIndex.getElements(AllName.KEY, unaliasedName, project, GlobalSearchScope.allScope(project), NamedElement.class);
    }
    return indexNamedElementCollection;
}
Also used : Project(com.intellij.openapi.project.Project) NamedElement(org.elixir_lang.psi.NamedElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with NamedElement

use of org.elixir_lang.psi.NamedElement 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 3 with NamedElement

use of org.elixir_lang.psi.NamedElement in project intellij-elixir by KronicDeth.

the class Module method annotate.

@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull com.intellij.lang.annotation.AnnotationHolder annotationHolder) {
    if (psiElement instanceof ErlangAtom) {
        ErlangAtom erlangAtom = (ErlangAtom) psiElement;
        String name = erlangAtom.getName();
        if (name.startsWith(ELIXIR_ALIAS_PREFIX)) {
            Project project = psiElement.getProject();
            Collection<NamedElement> namedElementCollection = StubIndex.getElements(AllName.KEY, name, project, GlobalSearchScope.allScope(project), NamedElement.class);
            if (namedElementCollection.size() > 0) {
                TextRange textRange = psiElement.getTextRange();
                String unprefixedName = name.substring(ELIXIR_ALIAS_PREFIX.length(), name.length());
                Annotation annotation = annotationHolder.createInfoAnnotation(textRange, "Resolves to Elixir Module " + unprefixedName);
                annotation.setTextAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT);
            } else {
                TextRange textRange = psiElement.getTextRange();
                annotationHolder.createErrorAnnotation(textRange, "Unresolved Elixir Module");
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) TextRange(com.intellij.openapi.util.TextRange) ErlangAtom(org.intellij.erlang.psi.ErlangAtom) NamedElement(org.elixir_lang.psi.NamedElement) Annotation(com.intellij.lang.annotation.Annotation)

Example 4 with NamedElement

use of org.elixir_lang.psi.NamedElement in project intellij-elixir by KronicDeth.

the class Element method getName.

/**
     * The name of the {@link #navigationItem}.
     *
     * @return the {@link NamedElement#getName()} if {@link #navigationItem} is a {@link NamedElement}; otherwise,
     *   {@code null}.
     */
@Nullable
@Override
public String getName() {
    String name = null;
    if (navigationItem instanceof NamedElement) {
        NamedElement namedElement = (NamedElement) navigationItem;
        name = namedElement.getName();
    }
    return name;
}
Also used : NamedElement(org.elixir_lang.psi.NamedElement) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with NamedElement

use of org.elixir_lang.psi.NamedElement in project intellij-elixir by KronicDeth.

the class TestFinder method corresponding.

@NotNull
private static Collection<PsiElement> corresponding(@NotNull PsiElement element, @NotNull Function<String, String> correspondingName, @NotNull Condition<Call> correspondingCallCondition) {
    Call sourceElement = sourceElement(element);
    Collection<PsiElement> correspondingCollection = new ArrayList<PsiElement>();
    if (sourceElement != null && sourceElement instanceof StubBased) {
        StubBased sourceStubBased = (StubBased) sourceElement;
        @SuppressWarnings("unchecked") Set<String> canonicalNameSet = sourceStubBased.canonicalNameSet();
        if (!canonicalNameSet.isEmpty()) {
            Project project = element.getProject();
            GlobalSearchScope scope = GlobalSearchScope.projectScope(project);
            for (String canonicalName : canonicalNameSet) {
                String correspondingCanonicalName = correspondingName.fun(canonicalName);
                if (correspondingCanonicalName != null) {
                    Collection<NamedElement> correspondingElements = StubIndex.getElements(AllName.KEY, correspondingCanonicalName, project, scope, NamedElement.class);
                    for (NamedElement correspondingElement : correspondingElements) {
                        if (correspondingElement instanceof Call) {
                            Call correspondingCall = (Call) correspondingElement;
                            if (correspondingCallCondition.value(correspondingCall)) {
                                correspondingCollection.add(correspondingCall);
                            }
                        }
                    }
                }
            }
        }
    }
    return correspondingCollection;
}
Also used : Call(org.elixir_lang.psi.call.Call) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ArrayList(java.util.ArrayList) StubBased(org.elixir_lang.psi.call.StubBased) NamedElement(org.elixir_lang.psi.NamedElement) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NamedElement (org.elixir_lang.psi.NamedElement)5 Project (com.intellij.openapi.project.Project)3 NotNull (org.jetbrains.annotations.NotNull)3 PsiElement (com.intellij.psi.PsiElement)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 Call (org.elixir_lang.psi.call.Call)2 Annotation (com.intellij.lang.annotation.Annotation)1 NavigationItem (com.intellij.navigation.NavigationItem)1 TextRange (com.intellij.openapi.util.TextRange)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AtUnqualifiedNoParenthesesCall (org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall)1 StubBased (org.elixir_lang.psi.call.StubBased)1 ErlangAtom (org.intellij.erlang.psi.ErlangAtom)1 Nullable (org.jetbrains.annotations.Nullable)1