Search in sources :

Example 11 with Call

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

the class MultiResolve method addToResolveResultList.

private void addToResolveResultList(@NotNull PsiElement element, ResolveState state, boolean validResult) {
    Boolean declaringScope = state.get(DECLARING_SCOPE);
    if (declaringScope == null || declaringScope) {
        PsiElement lastBinding = state.get(LAST_BINDING_KEY);
        boolean added = false;
        /* if LAST_BINDING_KEY is set, then we're checking if a right-hand match is bound higher up, so an effective
               recursive call.  If the recursive call got the same result, stop the recursion by not checking for
               rebinding */
        if (lastBinding == null || !element.isEquivalentTo(lastBinding)) {
            if (!(element instanceof Call) || !isInDeclaringScope((Call) element, state) || /* if maybe a macro, then it could potentially not be a macro, in which case prefer the early
                           declaration */
            Boolean.TRUE.equals(state.get(MAYBE_MACRO))) {
                Match matchAncestor = PsiTreeUtil.getContextOfType(element, Match.class);
                if (matchAncestor != null) {
                    PsiElement rightOperand = matchAncestor.rightOperand();
                    if (rightOperand != null) {
                        /* right-hand match can only be declarative if it is not already bound, so need to try to
                           resolve further up to try to find if {@code element} is already bound */
                        if (PsiTreeUtil.isAncestor(rightOperand, element, false)) {
                            // previous sibling or parent to search for earlier binding
                            PsiElement expression = previousExpression(matchAncestor);
                            if (expression != null) {
                                List<ResolveResult> preboundResolveResultList = resolveResultList(name, incompleteCode, expression, ResolveState.initial().put(ENTRANCE, matchAncestor).put(LAST_BINDING_KEY, element));
                                if (preboundResolveResultList != null && preboundResolveResultList.size() > 0) {
                                    if (resolveResultList == null) {
                                        resolveResultList = preboundResolveResultList;
                                    } else {
                                        resolveResultList.addAll(preboundResolveResultList);
                                    }
                                    added = true;
                                }
                            }
                        }
                    }
                }
            }
        }
        // either non-right match declaration or recursive call didn't find a rebinding
        if (!added) {
            addToResolveResultList(new PsiElementResolveResult(element, validResult));
        }
    }
}
Also used : Call(org.elixir_lang.psi.call.Call) Match(org.elixir_lang.psi.operation.Match)

Example 12 with Call

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

the class ResolvableName method down.

/*
     * Private Static Methods
     */
@Nullable
private static List<String> down(@NotNull Call qualifier) {
    List<String> nameList = null;
    if (qualifier.isCalling(KERNEL, __MODULE__, 0)) {
        Call enclosingCall = enclosingModularMacroCall(qualifier);
        if (enclosingCall != null && enclosingCall instanceof StubBased) {
            StubBased enclosingStubBasedCall = (StubBased) enclosingCall;
            String canonicalName = enclosingStubBasedCall.canonicalName();
            if (canonicalName != null) {
                nameList = new ArrayList<String>();
                nameList.add(canonicalName);
            }
        }
    }
    return nameList;
}
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) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with Call

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

the class Model method isSuitable.

@Override
protected boolean isSuitable(PsiElement element) {
    boolean suitable = false;
    // checks if the class is good
    if (super.isSuitable(element)) {
        // calls can be nested in calls, so need to check for sure
        if (element instanceof Call) {
            Call call = (Call) element;
            suitable = isSuitable(call);
        } else if (element instanceof ElixirAtom) {
            ElixirAtom atom = (ElixirAtom) element;
            suitable = Field.is(atom);
        } else if (element instanceof QuotableKeywordPair) {
            QuotableKeywordPair quotableKeywordPair = (QuotableKeywordPair) element;
            suitable = FieldWithDefaultValue.is(quotableKeywordPair);
        }
    }
    return suitable;
}
Also used : Call(org.elixir_lang.psi.call.Call) ElixirAtom(org.elixir_lang.psi.ElixirAtom) QuotableKeywordPair(org.elixir_lang.psi.QuotableKeywordPair)

Example 14 with Call

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

the class TestFinder method isTest.

@Override
public boolean isTest(@NotNull PsiElement element) {
    Call sourceElement = findSourceElement(element);
    boolean isTest = false;
    if (sourceElement != null && sourceElement instanceof StubBased) {
        StubBased sourceStubBased = (StubBased) sourceElement;
        @SuppressWarnings("unchecked") Set<String> canonicalNameSet = sourceStubBased.canonicalNameSet();
        if (!canonicalNameSet.isEmpty()) {
            for (String canonicalName : canonicalNameSet) {
                if (canonicalName.endsWith("Test")) {
                    isTest = true;
                    break;
                }
            }
        }
    }
    return isTest;
}
Also used : Call(org.elixir_lang.psi.call.Call) StubBased(org.elixir_lang.psi.call.StubBased)

Example 15 with Call

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

the class TestFinder method parentCallSourceElement.

@Nullable
private static Call parentCallSourceElement(@NotNull PsiElement from) {
    Call parentCall = PsiTreeUtil.getParentOfType(from, Call.class);
    Call sourceElement = null;
    if (parentCall != null) {
        sourceElement = sourceElement(parentCall);
    }
    return sourceElement;
}
Also used : Call(org.elixir_lang.psi.call.Call) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Call (org.elixir_lang.psi.call.Call)90 PsiElement (com.intellij.psi.PsiElement)45 Nullable (org.jetbrains.annotations.Nullable)34 CallDefinitionClause.enclosingModularMacroCall (org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall)20 NotNull (org.jetbrains.annotations.NotNull)19 Contract (org.jetbrains.annotations.Contract)16 AtUnqualifiedNoParenthesesCall (org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall)14 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)13 IntRange (org.apache.commons.lang.math.IntRange)10 PsiReference (com.intellij.psi.PsiReference)9 ArrayList (java.util.ArrayList)9 StubBased (org.elixir_lang.psi.call.StubBased)7 Type (org.elixir_lang.psi.operation.Type)5 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)4 Pair (com.intellij.openapi.util.Pair)4 ElixirPsiImplUtil.enclosingMacroCall (org.elixir_lang.psi.impl.ElixirPsiImplUtil.enclosingMacroCall)4 Stub (org.elixir_lang.psi.stub.call.Stub)4 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)3 PsiPolyVariantReference (com.intellij.psi.PsiPolyVariantReference)3 ResolveResult (com.intellij.psi.ResolveResult)3