Search in sources :

Example 86 with Contract

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

the class ElixirPsiImplUtil method getPresentation.

@Contract(pure = true)
@Nullable
public static ItemPresentation getPresentation(@NotNull final ElixirIdentifier identifier) {
    Parameter parameter = new Parameter(identifier);
    Parameter parameterizedParameter = Parameter.putParameterized(parameter);
    ItemPresentation itemPresentation = null;
    if ((parameterizedParameter.type == Parameter.Type.FUNCTION_NAME || parameterizedParameter.type == Parameter.Type.MACRO_NAME) && parameterizedParameter.parameterized != null) {
        final NavigatablePsiElement parameterized = parameterizedParameter.parameterized;
        if (parameterized instanceof Call) {
            CallDefinitionClause callDefinitionClause = CallDefinitionClause.fromCall((Call) parameterized);
            if (callDefinitionClause != null) {
                itemPresentation = callDefinitionClause.getPresentation();
            }
        }
    }
    return itemPresentation;
}
Also used : Call(org.elixir_lang.psi.call.Call) CallDefinitionClause.enclosingModularMacroCall(org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall) ItemPresentation(com.intellij.navigation.ItemPresentation) Parameter(org.elixir_lang.annonator.Parameter) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 87 with Contract

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

the class ElixirPsiImplUtil method resolvedPrimaryArity.

@Contract(pure = true)
@Nullable
public static Integer resolvedPrimaryArity(@NotNull final Call call) {
    Integer primaryArity = call.primaryArity();
    Integer resolvedPrimaryArity = primaryArity;
    /* do block and piping attach to the outer most parentheses, only count do block and piping for primary if there
           are no secondary. */
    if (call.secondaryArity() == null) {
        if (call.getDoBlock() != null) {
            if (primaryArity == null) {
                resolvedPrimaryArity = 1;
            } else {
                resolvedPrimaryArity += 1;
            }
        }
        PsiElement parent = call.getParent();
        if (isPipe(parent)) {
            Arrow parentPipeOperation = (Arrow) parent;
            PsiElement pipedInto = parentPipeOperation.rightOperand();
            /* only the right operand has its arity increased because it is the operand that has the output of the
                   left operand prepended to its arguments */
            if (pipedInto != null && call.isEquivalentTo(pipedInto)) {
                if (primaryArity == null) {
                    resolvedPrimaryArity = 1;
                } else {
                    resolvedPrimaryArity += 1;
                }
            }
        }
    }
    return resolvedPrimaryArity;
}
Also used : BigInteger(java.math.BigInteger) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 88 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 ElixirAssociationsBase associationsBase) {
    PsiElement[] children = associationsBase.getChildren();
    OtpErlangObject[] quotedChildren = new OtpErlangObject[children.length];
    int i = 0;
    for (PsiElement child : children) {
        Quotable quotableChild = (Quotable) child;
        quotedChildren[i++] = quotableChild.quote();
    }
    return new OtpErlangList(quotedChildren);
}
Also used : LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 89 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 AssociationOperation associationOperation) {
    PsiElement[] children = associationOperation.getChildren();
    // associationInfixOperator is private so not a PsiElement
    assert children.length == 2;
    OtpErlangObject[] quotedChildren = new OtpErlangObject[children.length];
    int i = 0;
    for (PsiElement child : children) {
        Quotable quotableChild = (Quotable) child;
        quotedChildren[i++] = quotableChild.quote();
    }
    return new OtpErlangTuple(quotedChildren);
}
Also used : LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 90 with Contract

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

the class ElixirPsiImplUtil method quoteArguments.

@Contract(pure = true)
@NotNull
public static OtpErlangObject[] quoteArguments(@NotNull final ElixirMapConstructionArguments mapConstructionArguments) {
    PsiElement[] arguments = mapConstructionArguments.arguments();
    List<OtpErlangObject> quotedArgumentList = new ArrayList<OtpErlangObject>();
    for (PsiElement argument : arguments) {
        Quotable quotableArgument = (Quotable) argument;
        OtpErlangList quotedArgument = (OtpErlangList) quotableArgument.quote();
        for (OtpErlangObject element : quotedArgument.elements()) {
            quotedArgumentList.add(element);
        }
    }
    OtpErlangObject[] quotedArguments = new OtpErlangObject[quotedArgumentList.size()];
    return quotedArgumentList.toArray(quotedArguments);
}
Also used : LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

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