Search in sources :

Example 1 with Call

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

the class Builder method isCollapsedByDefault.

/**
     * Returns the default collapsed state for the folding region related to the specified node.
     *
     * @param node the node for which the collapsed state is requested.
     * @return true if the region is collapsed by default, false otherwise.
     */
@Override
public boolean isCollapsedByDefault(@NotNull ASTNode node) {
    PsiElement element = node.getPsi();
    boolean isCollapsedByDefault = false;
    if (element instanceof AtNonNumericOperation) {
        isCollapsedByDefault = ElixirFoldingSettings.getInstance().isReplaceModuleAttributesWithValues();
    } else {
        PsiElement[] children = element.getChildren();
        for (PsiElement child : children) {
            if (child instanceof Call) {
                Call call = (Call) child;
                for (String resolvedFunctionName : RESOLVED_FUNCTION_NAMES) {
                    if (call.isCalling(KERNEL, resolvedFunctionName)) {
                        isCollapsedByDefault = ElixirFoldingSettings.getInstance().isCollapseElixirModuleDirectiveGroups();
                        break;
                    }
                }
            }
        }
    }
    return isCollapsedByDefault;
}
Also used : Call(org.elixir_lang.psi.call.Call) PsiElement(com.intellij.psi.PsiElement)

Example 2 with Call

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

the class CallDefinitionClause method execute.

/*
     * Private Instance Methods
     */
private boolean execute(@NotNull Call element, @NotNull final ResolveState state) {
    boolean keepProcessing = true;
    if (org.elixir_lang.structure_view.element.CallDefinitionClause.is(element)) {
        keepProcessing = executeOnCallDefinitionClause(element, state);
    } else if (Import.is(element)) {
        final ResolveState importState = state.put(IMPORT_CALL, element);
        try {
            Import.callDefinitionClauseCallWhile(element, new Function<Call, Boolean>() {

                @Override
                public Boolean fun(Call callDefinitionClause) {
                    return executeOnCallDefinitionClause(callDefinitionClause, importState);
                }
            });
        } catch (StackOverflowError stackOverflowError) {
            Logger.error(CallDefinitionClause.class, "StackOverflowError while processing import", element);
        }
    } else if (Module.is(element)) {
        Call[] childCalls = macroChildCalls(element);
        if (childCalls != null) {
            for (Call childCall : childCalls) {
                if (!execute(childCall, state)) {
                    break;
                }
            }
        }
        // Only check MultiResolve.keepProcessing at the end of a Module to all multiple arities
        keepProcessing = keepProcessing();
        if (keepProcessing) {
            // the implicit `import Kernel` and `import Kernel.SpecialForms`
            keepProcessing = implicitImports(element, state);
        }
    }
    return keepProcessing;
}
Also used : Function(com.intellij.util.Function) Call(org.elixir_lang.psi.call.Call) ResolveState(com.intellij.psi.ResolveState)

Example 3 with Call

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

the class Issue480Test method assertResolvedNameArityRange.

private void assertResolvedNameArityRange(@NotNull PsiElement element, @NotNull String name, int arity) {
    PsiReference reference = element.getReference();
    assertNotNull(reference);
    PsiElement resolved = reference.resolve();
    assertNotNull(resolved);
    assertInstanceOf(resolved, ElixirIdentifier.class);
    PsiElement maybeDefMaybeCall = resolved.getParent().getParent().getParent();
    assertInstanceOf(maybeDefMaybeCall, Call.class);
    Call maybeDefCall = (Call) maybeDefMaybeCall;
    assertTrue(CallDefinitionClause.is(maybeDefCall));
    assertEquals(pair(name, new IntRange(arity)), nameArityRange(maybeDefCall));
}
Also used : Call(org.elixir_lang.psi.call.Call) IntRange(org.apache.commons.lang.math.IntRange) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 4 with Call

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

the class Issue480Test method assertUnresolvableReferenceNameArityRange.

/*
     * Private Instance Methods
     */
private void assertUnresolvableReferenceNameArityRange(@NotNull String name, int arity) {
    PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assertNotNull(elementAtCaret);
    PsiElement grandParent = elementAtCaret.getParent().getParent();
    assertNotNull(grandParent);
    assertInstanceOf(grandParent, Call.class);
    Call grandParentCall = (Call) grandParent;
    assertEquals(name, grandParentCall.functionName());
    assertEquals(arity, grandParentCall.resolvedFinalArity());
    PsiReference reference = grandParent.getReference();
    assertNotNull(reference);
    PsiElement resolved = reference.resolve();
    assertNull(resolved);
}
Also used : Call(org.elixir_lang.psi.call.Call) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 5 with Call

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

the class CallDefinitionHeadTest method assertIssue468CallDefinitionHeadClauseHead.

/*
     * Private Instance Methods
     */
private void assertIssue468CallDefinitionHeadClauseHead() {
    PsiElement element = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent().getParent();
    assertNotNull(element);
    assertInstanceOf(element, Call.class);
    Call call = (Call) element;
    assertTrue("Call at caret is not a call definition clause", CallDefinitionClause.is(call));
    PsiElement head = CallDefinitionClause.head(call);
    assertNotNull("Call definition has a null head", head);
    assertEquals("create(state = %__MODULE__{ecto_schema_module: ecto_schema_module, view: view}, params)", CallDefinitionHead.stripGuard(head).getText());
}
Also used : Call(org.elixir_lang.psi.call.Call) PsiElement(com.intellij.psi.PsiElement)

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