Search in sources :

Example 11 with Contract

use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.

the class CallDefinitionClause method childCallTreeElements.

@Contract(pure = true)
@Nullable
private TreeElement[] childCallTreeElements(@Nullable Call[] childCalls) {
    TreeElement[] treeElements = null;
    if (childCalls != null) {
        List<TreeElement> treeElementList = new ArrayList<TreeElement>(childCalls.length);
        for (Call childCall : childCalls) {
            addChildCall(treeElementList, childCall);
        }
        treeElements = treeElementList.toArray(new TreeElement[treeElementList.size()]);
    }
    return treeElements;
}
Also used : Call(org.elixir_lang.psi.call.Call) ElixirPsiImplUtil.enclosingMacroCall(org.elixir_lang.psi.impl.ElixirPsiImplUtil.enclosingMacroCall) ArrayList(java.util.ArrayList) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with Contract

use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.

the class CallDefinitionSpecification method is.

@Contract(pure = true)
public static boolean is(@NotNull final Call call) {
    boolean is = false;
    if (call instanceof AtUnqualifiedNoParenthesesCall) {
        AtUnqualifiedNoParenthesesCall atUnqualifiedNoParenthesesCall = (AtUnqualifiedNoParenthesesCall) call;
        String moduleAttributeName = ElixirPsiImplUtil.moduleAttributeName(atUnqualifiedNoParenthesesCall);
        if (moduleAttributeName.equals("@spec")) {
            is = true;
        }
    }
    return is;
}
Also used : AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) Contract(org.jetbrains.annotations.Contract)

Example 13 with Contract

use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.

the class ElixirPsiImplUtil method maybeAliasToModular.

/**
     * @return {@link Call} for the {@code defmodule}, {@code defimpl}, or {@code defprotocol} that defines
     *   {@code maybeAlias} after it is resolved through any {@code alias}es.
     */
@Contract(pure = true)
@Nullable
public static Call maybeAliasToModular(@NotNull final PsiElement maybeAlias, @NotNull PsiElement maxScope) {
    PsiElement maybeQualifiableAlias = stripAccessExpression(maybeAlias);
    Call modular = null;
    if (maybeQualifiableAlias instanceof QualifiableAlias) {
        QualifiableAlias qualifiableAlias = (QualifiableAlias) maybeQualifiableAlias;
        if (!recursiveKernelImport(qualifiableAlias, maxScope)) {
            /* need to construct reference directly as qualified aliases don't return a reference except for the
                   outermost */
            PsiPolyVariantReference reference = new org.elixir_lang.reference.Module(qualifiableAlias, maxScope);
            modular = aliasToModular(qualifiableAlias, reference);
        }
    }
    return modular;
}
Also used : Call(org.elixir_lang.psi.call.Call) CallDefinitionClause.enclosingModularMacroCall(org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall) Module(org.elixir_lang.structure_view.element.modular.Module) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with Contract

use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.

the class ElixirPsiImplUtil method resolvedFinalArity.

@Contract(pure = true)
@NotNull
public static int resolvedFinalArity(@NotNull final org.elixir_lang.psi.call.StubBased<Stub> stubBased) {
    Stub stub = stubBased.getStub();
    Integer resolvedFinalArity;
    if (stub != null) {
        resolvedFinalArity = stub.resolvedFinalArity();
    } else {
        resolvedFinalArity = resolvedFinalArity((Call) stubBased);
    }
    if (resolvedFinalArity == null) {
        resolvedFinalArity = 0;
    }
    return resolvedFinalArity;
}
Also used : BigInteger(java.math.BigInteger) Call(org.elixir_lang.psi.call.Call) CallDefinitionClause.enclosingModularMacroCall(org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall) Stub(org.elixir_lang.psi.stub.call.Stub) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with Contract

use of org.jetbrains.annotations.Contract in project intellij-elixir by KronicDeth.

the class ElixirPsiImplUtil method enclosingMacroCall.

/**
     *
     * @param call
     * @return {@code null} if call is at top-level
     */
@Contract(pure = true)
@Nullable
public static Call enclosingMacroCall(PsiElement element) {
    Call enclosingMacroCall = null;
    PsiElement parent = element.getParent();
    if (parent instanceof ElixirDoBlock) {
        PsiElement grandParent = parent.getParent();
        if (grandParent instanceof Call) {
            enclosingMacroCall = (Call) grandParent;
        }
    } else if (parent instanceof ElixirStabBody) {
        PsiElement grandParent = parent.getParent();
        if (grandParent instanceof ElixirStab) {
            PsiElement greatGrandParent = grandParent.getParent();
            if (greatGrandParent instanceof ElixirBlockItem) {
                PsiElement greatGreatGrandParent = greatGrandParent.getParent();
                if (greatGreatGrandParent instanceof ElixirBlockList) {
                    PsiElement greatGreatGreatGrandParent = greatGreatGrandParent.getParent();
                    if (greatGreatGreatGrandParent instanceof ElixirDoBlock) {
                        PsiElement greatGreatGreatGreatGrandParent = greatGreatGreatGrandParent.getParent();
                        if (greatGreatGreatGreatGrandParent instanceof Call) {
                            enclosingMacroCall = (Call) greatGreatGreatGreatGrandParent;
                        }
                    }
                }
            } else if (greatGrandParent instanceof ElixirDoBlock) {
                PsiElement greatGreatGrandParent = greatGrandParent.getParent();
                if (greatGreatGrandParent instanceof Call) {
                    enclosingMacroCall = (Call) greatGreatGrandParent;
                }
            } else if (greatGrandParent instanceof ElixirParentheticalStab) {
                PsiElement greatGreatGrandParent = greatGrandParent.getParent();
                if (greatGreatGrandParent instanceof ElixirAccessExpression) {
                    enclosingMacroCall = enclosingMacroCall(greatGreatGrandParent);
                }
            }
        } else if (grandParent instanceof ElixirStabOperation) {
            PsiElement stabOperationParent = grandParent.getParent();
            if (stabOperationParent instanceof ElixirStab) {
                PsiElement stabParent = stabOperationParent.getParent();
                if (stabParent instanceof ElixirAnonymousFunction) {
                    PsiElement anonymousFunctionParent = stabParent.getParent();
                    if (anonymousFunctionParent instanceof ElixirAccessExpression) {
                        PsiElement accessExpressionParent = anonymousFunctionParent.getParent();
                        if (accessExpressionParent instanceof Arguments) {
                            PsiElement argumentsParent = accessExpressionParent.getParent();
                            if (argumentsParent instanceof ElixirMatchedParenthesesArguments) {
                                PsiElement matchedParenthesesArgumentsParent = argumentsParent.getParent();
                                if (matchedParenthesesArgumentsParent instanceof Call) {
                                    Call matchedParenthesesArgumentsParentCall = (Call) matchedParenthesesArgumentsParent;
                                    if (matchedParenthesesArgumentsParentCall.isCalling("Enum", "map") || matchedParenthesesArgumentsParentCall.isCalling("Enum", "each")) {
                                        enclosingMacroCall = enclosingMacroCall(matchedParenthesesArgumentsParentCall);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else if (parent instanceof Arguments || parent instanceof Match || parent instanceof QualifiedAlias || parent instanceof QualifiedMultipleAliases) {
        enclosingMacroCall = enclosingMacroCall(parent);
    } else if (parent instanceof Call) {
        Call parentCall = (Call) parent;
        if (parentCall.isCalling(KERNEL, ALIAS)) {
            enclosingMacroCall = parentCall;
        }
    } else if (parent instanceof QuotableKeywordPair) {
        QuotableKeywordPair parentKeywordPair = (QuotableKeywordPair) parent;
        if (hasKeywordKey(parentKeywordPair, "do")) {
            PsiElement grandParent = parent.getParent();
            if (grandParent instanceof QuotableKeywordList) {
                PsiElement greatGrandParent = grandParent.getParent();
                if (greatGrandParent instanceof ElixirNoParenthesesOneArgument) {
                    PsiElement greatGreatGrandParent = greatGrandParent.getParent();
                    if (greatGreatGrandParent instanceof Call) {
                        enclosingMacroCall = (Call) greatGreatGrandParent;
                    }
                }
            }
        }
    }
    return enclosingMacroCall;
}
Also used : Call(org.elixir_lang.psi.call.Call) CallDefinitionClause.enclosingModularMacroCall(org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Contract (org.jetbrains.annotations.Contract)111 NotNull (org.jetbrains.annotations.NotNull)48 Nullable (org.jetbrains.annotations.Nullable)40 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)29 PsiElement (com.intellij.psi.PsiElement)19 Call (org.elixir_lang.psi.call.Call)17 ASTNode (com.intellij.lang.ASTNode)14 CallDefinitionClause.enclosingModularMacroCall (org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall)9 PsiFile (com.intellij.psi.PsiFile)6 IElementType (com.intellij.psi.tree.IElementType)6 BigInteger (java.math.BigInteger)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Quotable (org.elixir_lang.psi.Quotable)5 Project (com.intellij.openapi.project.Project)4 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)3 Matcher (java.util.regex.Matcher)3 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)2 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)2 TextRange (com.intellij.openapi.util.TextRange)2 File (java.io.File)2