Search in sources :

Example 6 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 UnqualifiedBracketOperation unqualifiedBracketOperation) {
    ASTNode node = unqualifiedBracketOperation.getNode();
    OtpErlangObject quotedIdentifier = new OtpErlangAtom(node.getFirstChildNode().getText());
    OtpErlangObject quotedContainer = quotedVariable(quotedIdentifier, metadata(unqualifiedBracketOperation));
    Quotable bracketArguments = unqualifiedBracketOperation.getBracketArguments();
    OtpErlangObject quotedBrackArguments = bracketArguments.quote();
    return quotedFunctionCall("Elixir.Access", "get", metadata(bracketArguments), quotedContainer, quotedBrackArguments);
}
Also used : ASTNode(com.intellij.lang.ASTNode) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

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

Example 8 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 ElixirAtom atom) {
    OtpErlangObject quoted;
    ElixirCharListLine charListLine = atom.getCharListLine();
    if (charListLine != null) {
        quoted = charListLine.quoteAsAtom();
    } else {
        ElixirStringLine stringLine = atom.getStringLine();
        if (stringLine != null) {
            quoted = stringLine.quoteAsAtom();
        } else {
            ASTNode atomNode = atom.getNode();
            ASTNode atomFragmentNode = atomNode.getLastChildNode();
            assert atomFragmentNode.getElementType() == ElixirTypes.ATOM_FRAGMENT;
            quoted = new OtpErlangAtom(atomFragmentNode.getText());
        }
    }
    return quoted;
}
Also used : ASTNode(com.intellij.lang.ASTNode) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with Contract

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

the class ElixirPsiImplUtil method resolvedFinalArityRange.

@Contract(pure = true)
@NotNull
public static IntRange resolvedFinalArityRange(@NotNull final Call call) {
    IntRange arityRange;
    PsiElement[] finalArguments = ElixirPsiImplUtil.finalArguments(call);
    if (finalArguments != null) {
        int defaultCount = defaultArgumentCount(finalArguments);
        int maximum = finalArguments.length;
        int minimum = maximum - defaultCount;
        arityRange = new IntRange(minimum, maximum);
    } else {
        arityRange = new IntRange(0);
    }
    return arityRange;
}
Also used : IntRange(org.apache.commons.lang.math.IntRange) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with Contract

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

the class ElixirPsiImplUtil method arguments.

@Contract(pure = true)
@NotNull
public static PsiElement[] arguments(@NotNull final ElixirNoParenthesesOneArgument noParenthesesOneArgument) {
    PsiElement[] children = noParenthesesOneArgument.getChildren();
    PsiElement[] arguments = children;
    if (children.length == 1) {
        PsiElement child = children[0];
        if (child instanceof Arguments) {
            Arguments childArguments = (Arguments) child;
            arguments = childArguments.arguments();
        }
    }
    return arguments;
}
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