Search in sources :

Example 1 with Callable

use of org.elixir_lang.reference.Callable in project intellij-elixir by KronicDeth.

the class ElixirPsiImplUtil method getReference.

@Nullable
public static PsiReference getReference(@NotNull Call call) {
    PsiReference reference = null;
    /* if the call is just the identifier for a module attribute reference, then don't return a Callable reference,
           and instead let {@link #getReference(AtNonNumbericOperation) handle it */
    if (!(call instanceof UnqualifiedNoArgumentsCall && call.getParent() instanceof AtNonNumericOperation) && // if a bitstring segment option then the option is a pseudo-function
    !isBitStreamSegmentOption(call)) {
        PsiElement parent = call.getParent();
        if (parent instanceof Type) {
            PsiElement grandParent = parent.getParent();
            AtUnqualifiedNoParenthesesCall moduleAttribute = null;
            PsiElement maybeArgument = grandParent;
            if (grandParent instanceof When) {
                maybeArgument = grandParent.getParent();
            }
            if (maybeArgument instanceof ElixirNoParenthesesOneArgument) {
                PsiElement maybeModuleAttribute = maybeArgument.getParent();
                if (maybeModuleAttribute instanceof AtUnqualifiedNoParenthesesCall) {
                    moduleAttribute = (AtUnqualifiedNoParenthesesCall) maybeModuleAttribute;
                }
                if (moduleAttribute != null) {
                    String name = moduleAttributeName(moduleAttribute);
                    if (name.equals("@spec")) {
                        reference = new org.elixir_lang.reference.CallDefinitionClause(call, moduleAttribute);
                    }
                }
            }
        }
        if (reference == null) {
            if (CallDefinitionClause.is(call) || Implementation.is(call) || Module.is(call) || Protocol.is(call)) {
                reference = Callable.definer(call);
            } else {
                reference = new Callable(call);
            }
        }
    }
    return reference;
}
Also used : Callable(org.elixir_lang.reference.Callable) IElementType(com.intellij.psi.tree.IElementType) Type(org.elixir_lang.psi.operation.Type) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1 IElementType (com.intellij.psi.tree.IElementType)1 Type (org.elixir_lang.psi.operation.Type)1 Callable (org.elixir_lang.reference.Callable)1 Nullable (org.jetbrains.annotations.Nullable)1