Search in sources :

Example 26 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 ElixirCharToken charToken) {
    ASTNode[] children = charToken.getNode().getChildren(null);
    if (children.length != 2) {
        throw new NotImplementedException("CharToken expected to be ?(<character>|<escape sequence>)");
    }
    final ASTNode tokenized = children[1];
    IElementType tokenizedElementType = tokenized.getElementType();
    int codePoint;
    if (tokenizedElementType == ElixirTypes.CHAR_LIST_FRAGMENT) {
        if (tokenized.getTextLength() != 1) {
            throw new NotImplementedException("Tokenized character expected to only be one character long");
        }
        String tokenizedString = tokenized.getText();
        codePoint = tokenizedString.codePointAt(0);
    } else {
        EscapeSequence escapeSequence = (EscapeSequence) tokenized.getPsi();
        codePoint = escapeSequence.codePoint();
    }
    return new OtpErlangLong(codePoint);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) NotImplementedException(org.apache.commons.lang.NotImplementedException) ASTNode(com.intellij.lang.ASTNode) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with Contract

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

the class ElixirPsiImplUtil method primaryArity.

@Contract(pure = true)
@Nullable
public static Integer primaryArity(@NotNull final Call call) {
    PsiElement[] primaryArguments = call.primaryArguments();
    Integer primaryArity = null;
    if (primaryArguments != null) {
        primaryArity = primaryArguments.length;
    }
    return primaryArity;
}
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 28 with Contract

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

the class ElixirPsiImplUtil method mergeFragments.

@NotNull
@Contract(pure = true)
private static Queue<ASTNode> mergeFragments(@NotNull Deque<ASTNode> unmergedNodes, IElementType fragmentType, @NotNull PsiManager manager) {
    Queue<ASTNode> mergedNodes = new LinkedList<ASTNode>();
    StringBuilder fragmentStringBuilder = null;
    for (ASTNode unmergedNode : unmergedNodes) {
        if (unmergedNode.getElementType() == fragmentType) {
            if (fragmentStringBuilder == null) {
                fragmentStringBuilder = new StringBuilder();
            }
            String fragment = unmergedNode.getText();
            fragmentStringBuilder.append(fragment);
        } else {
            addMergedFragments(mergedNodes, fragmentType, fragmentStringBuilder, manager);
            fragmentStringBuilder = null;
            mergedNodes.add(unmergedNode);
        }
    }
    addMergedFragments(mergedNodes, fragmentType, fragmentStringBuilder, manager);
    return mergedNodes;
}
Also used : ASTNode(com.intellij.lang.ASTNode) NotNull(org.jetbrains.annotations.NotNull) Contract(org.jetbrains.annotations.Contract)

Example 29 with Contract

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

the class ElixirPsiImplUtil method secondaryArity.

@Contract(pure = true)
@Nullable
public static Integer secondaryArity(@NotNull final Call call) {
    PsiElement[] secondaryArguments = call.secondaryArguments();
    Integer secondaryArity = null;
    if (secondaryArguments != null) {
        secondaryArity = secondaryArguments.length;
    }
    return secondaryArity;
}
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 30 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 Digits digits) {
    final String text = digits.getText();
    final int base = digits.base();
    OtpErlangLong quoted;
    try {
        long value = Long.parseLong(text, base);
        quoted = new OtpErlangLong(value);
    } catch (NumberFormatException exception) {
        BigInteger value = new BigInteger(text, base);
        quoted = new OtpErlangLong(value);
    }
    return quoted;
}
Also used : BigInteger(java.math.BigInteger) 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