Search in sources :

Example 6 with StubBased

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

the class ElixirPsiImplUtil method canonicalName.

@Nullable
public static String canonicalName(@NotNull StubBased stubBased) {
    String canonicalName;
    if (isModular(stubBased)) {
        String canonicalNameSuffix = null;
        if (Implementation.is(stubBased)) {
            String protocolName = Implementation.protocolName(stubBased);
            PsiElement forNameElement = Implementation.forNameElement(stubBased);
            String forName = null;
            if (forNameElement != null) {
                forName = forNameElement.getText();
            }
            canonicalNameSuffix = StringUtil.notNullize(protocolName, "?") + "." + StringUtil.notNullize(forName, "?");
        } else if (Module.is(stubBased) || Protocol.is(stubBased)) {
            canonicalNameSuffix = org.elixir_lang.navigation.item_presentation.modular.Module.presentableText(stubBased);
        }
        Call enclosing = enclosingModularMacroCall(stubBased);
        if (enclosing instanceof StubBased) {
            StubBased enclosingStubBased = (StubBased) enclosing;
            String canonicalNamePrefix = enclosingStubBased.canonicalName();
            canonicalName = StringUtil.notNullize(canonicalNamePrefix, "?") + "." + StringUtil.notNullize(canonicalNameSuffix, "?");
        } else {
            canonicalName = StringUtil.notNullize(canonicalNameSuffix, "?");
        }
    } else {
        canonicalName = stubBased.getName();
    }
    return canonicalName;
}
Also used : Call(org.elixir_lang.psi.call.Call) CallDefinitionClause.enclosingModularMacroCall(org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall) StubBased(org.elixir_lang.psi.call.StubBased) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with StubBased

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

the class Stub method hasCanonicalNames.

/*
     * Private Instance Methods
     */
private boolean hasCanonicalNames(Call call) {
    boolean hasCanonicalNames = false;
    if (call instanceof StubBased) {
        StubBased stubBased = (StubBased) call;
        hasCanonicalNames = stubBased.canonicalNameSet().size() > 0;
    }
    return hasCanonicalNames;
}
Also used : StubBased(org.elixir_lang.psi.call.StubBased)

Example 8 with StubBased

use of org.elixir_lang.psi.call.StubBased 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

StubBased (org.elixir_lang.psi.call.StubBased)8 Call (org.elixir_lang.psi.call.Call)6 CallDefinitionClause.enclosingModularMacroCall (org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall)4 Nullable (org.jetbrains.annotations.Nullable)4 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)3 NotNull (org.jetbrains.annotations.NotNull)3 ArrayList (java.util.ArrayList)2 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 NamedElement (org.elixir_lang.psi.NamedElement)1 Contract (org.jetbrains.annotations.Contract)1