Search in sources :

Example 81 with Contract

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

the class ElixirPsiImplUtil method exportedArity.

@Contract(pure = true)
public static int exportedArity(@NotNull final UnqualifiedNoParenthesesCall unqualifiedNoParenthesesCall) {
    int arity = MaybeExported.UNEXPORTED_ARITY;
    if (isExported(unqualifiedNoParenthesesCall)) {
        Pair<String, IntRange> nameArityRange = CallDefinitionClause.nameArityRange(unqualifiedNoParenthesesCall);
        if (nameArityRange != null) {
            IntRange arityRange = nameArityRange.second;
            if (arityRange != null) {
                int minimumArity = arityRange.getMinimumInteger();
                int maximumArity = arityRange.getMaximumInteger();
                if (minimumArity == maximumArity) {
                    arity = minimumArity;
                }
            }
        }
    }
    return arity;
}
Also used : IntRange(org.apache.commons.lang.math.IntRange) Contract(org.jetbrains.annotations.Contract)

Example 82 with Contract

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

the class ElixirPsiImplUtil method quote.

@Contract(pure = true)
@NotNull
public static OtpErlangObject quote(@NotNull final ElixirStabBody stabBody) {
    PsiElement[] children = stabBody.getChildren();
    Deque<OtpErlangObject> quotedChildren = new ArrayDeque<OtpErlangObject>();
    for (PsiElement child : children) {
        // skip endOfExpression
        if (isUnquoted(child)) {
            continue;
        }
        Quotable quotableChild = (Quotable) child;
        OtpErlangObject quotedChild = quotableChild.quote();
        quotedChildren.add(quotedChild);
    }
    return buildBlock(quotedChildren);
}
Also used : LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 83 with Contract

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

the class ElixirPsiImplUtil method quote.

@Contract(pure = true)
@NotNull
public static OtpErlangObject quote(@NotNull final ElixirList list) {
    PsiElement[] listArguments = list.getChildren();
    List<OtpErlangObject> quotedListArgumentList = new ArrayList<OtpErlangObject>(listArguments.length);
    if (listArguments.length > 0) {
        for (int i = 0; i < listArguments.length - 1; i++) {
            Quotable listArgument = (Quotable) listArguments[i];
            quotedListArgumentList.add(listArgument.quote());
        }
        PsiElement lastListArgument = listArguments[listArguments.length - 1];
        if (lastListArgument instanceof ElixirKeywords) {
            QuotableKeywordList quotableKeywordList = (QuotableKeywordList) lastListArgument;
            for (Quotable keywordPair : quotableKeywordList.quotableKeywordPairList()) {
                quotedListArgumentList.add(keywordPair.quote());
            }
        } else {
            Quotable quotable = (Quotable) lastListArgument;
            quotedListArgumentList.add(quotable.quote());
        }
    }
    OtpErlangObject[] quotedListArguments = new OtpErlangObject[quotedListArgumentList.size()];
    quotedListArgumentList.toArray(quotedListArguments);
    return elixirCharList(new OtpErlangList(quotedListArguments));
}
Also used : LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 84 with Contract

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

the class ElixirPsiImplUtil method quote.

@Contract(pure = true)
@NotNull
public static OtpErlangObject quote(@NotNull final ElixirTuple tuple) {
    ASTNode node = tuple.getNode();
    ASTNode[] openingCurlies = node.getChildren(TokenSet.create(ElixirTypes.OPENING_CURLY));
    assert openingCurlies.length == 1;
    ASTNode openingCurly = openingCurlies[0];
    PsiElement[] children = tuple.getChildren();
    OtpErlangObject[] quotedChildren = new OtpErlangObject[children.length];
    int i = 0;
    for (PsiElement child : children) {
        Quotable quotableChild = (Quotable) child;
        quotedChildren[i++] = quotableChild.quote();
    }
    OtpErlangObject quoted;
    // 2-tuples are literals in quoted form
    if (quotedChildren.length == 2) {
        quoted = new OtpErlangTuple(quotedChildren);
    } else {
        quoted = quotedFunctionCall("{}", metadata(openingCurly), quotedChildren);
    }
    return quoted;
}
Also used : ASTNode(com.intellij.lang.ASTNode) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 85 with Contract

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

the class ElixirPsiImplUtil method functionName.

@Contract(pure = true)
@Nullable
public static String functionName(@NotNull final Call call) {
    String functionName = null;
    PsiElement element = call.functionNameElement();
    if (element != null) {
        functionName = element.getText();
    }
    return functionName;
}
Also used : 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