Search in sources :

Example 76 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 AtUnqualifiedNoParenthesesCall atUnqualifiedNoParenthesesCall) {
    ElixirAtIdentifier atIdentifier = atUnqualifiedNoParenthesesCall.getAtIdentifier();
    Quotable operator = atIdentifier.getAtPrefixOperator();
    OtpErlangObject quotedOperator = operator.quote();
    ASTNode node = atIdentifier.getNode();
    ASTNode[] identifierNodes = node.getChildren(IDENTIFIER_TOKEN_SET);
    assert identifierNodes.length == 1;
    ASTNode identifierNode = identifierNodes[0];
    String identifier = identifierNode.getText();
    OtpErlangObject quotedIdentifier = new OtpErlangAtom(identifier);
    QuotableArguments noParenthesesOneArgument = atUnqualifiedNoParenthesesCall.getNoParenthesesOneArgument();
    OtpErlangObject[] quotedArguments = noParenthesesOneArgument.quoteArguments();
    ElixirDoBlock doBlock = atUnqualifiedNoParenthesesCall.getDoBlock();
    OtpErlangObject quotedOperand = quotedBlockCall(quotedIdentifier, metadata(operator), quotedArguments, doBlock);
    return quotedFunctionCall(quotedOperator, metadata(operator), quotedOperand);
}
Also used : ASTNode(com.intellij.lang.ASTNode) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 77 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 UnqualifiedParenthesesCall unqualifiedParenthesesCall) {
    ASTNode identifierNode = unqualifiedParenthesesCall.getNode().getFirstChildNode();
    OtpErlangList metadata = metadata(unqualifiedParenthesesCall);
    OtpErlangObject quotedIdentifier = new OtpErlangAtom(identifierNode.getText());
    ElixirMatchedParenthesesArguments matchedParenthesesArguments = unqualifiedParenthesesCall.getMatchedParenthesesArguments();
    List<ElixirParenthesesArguments> parenthesesArgumentsList = matchedParenthesesArguments.getParenthesesArgumentsList();
    ElixirDoBlock doBlock = unqualifiedParenthesesCall.getDoBlock();
    return quotedParenthesesCall(quotedIdentifier, metadata, parenthesesArgumentsList, doBlock);
}
Also used : ASTNode(com.intellij.lang.ASTNode) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 78 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 Infix infix) {
    Quotable leftOperand = infix.leftOperand();
    OtpErlangObject quotedLeftOperand = leftOperand.quote();
    Operator operator = infix.operator();
    OtpErlangObject quotedOperator = operator.quote();
    PsiElement rightOperand = infix.rightOperand();
    OtpErlangObject quotedRightOperand;
    if (rightOperand != null && rightOperand instanceof Quotable) {
        Quotable quotableRightOperand = (Quotable) rightOperand;
        quotedRightOperand = quotableRightOperand.quote();
    } else {
        // this is not valid Elixir quoting, but something needs to be there for quoting to work
        quotedRightOperand = NIL;
    }
    return quotedFunctionCall(quotedOperator, metadata(operator), quotedLeftOperand, quotedRightOperand);
}
Also used : LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 79 with Contract

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

the class ElixirPsiImplUtil method resolvedFunctionName.

@Contract(pure = true)
@NotNull
public static String resolvedFunctionName(@NotNull final org.elixir_lang.psi.call.StubBased<Stub> stubBased) {
    Stub stub = stubBased.getStub();
    String resolvedFunctionName;
    if (stub != null) {
        resolvedFunctionName = stub.resolvedFunctionName();
    } else {
        resolvedFunctionName = resolvedFunctionName((Call) stubBased);
    }
    //noinspection ConstantConditions
    return resolvedFunctionName;
}
Also used : 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 80 with Contract

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

the class ElixirPsiImplUtil method excessWhitespace.

/* Returns a virtual PsiElement representing the spaces at the end of charListHeredocLineWhitespace that are not
     * consumed by prefixLength.
     *
     * @return null if prefixLength is greater than or equal to text length of charListHeredcoLineWhitespace.
     */
@Contract(pure = true)
@Nullable
public static ASTNode excessWhitespace(@NotNull final ElixirHeredocLinePrefix heredocLinePrefix, @NotNull final IElementType fragmentType, final int prefixLength) {
    int availableLength = heredocLinePrefix.getTextLength();
    int excessLength = availableLength - prefixLength;
    ASTNode excessWhitespaceASTNode = null;
    if (excessLength > 0) {
        char[] excessWhitespaceChars = new char[excessLength];
        Arrays.fill(excessWhitespaceChars, ' ');
        String excessWhitespaceString = new String(excessWhitespaceChars);
        excessWhitespaceASTNode = Factory.createSingleLeafElement(fragmentType, excessWhitespaceString, 0, excessLength, null, heredocLinePrefix.getManager());
    }
    return excessWhitespaceASTNode;
}
Also used : ASTNode(com.intellij.lang.ASTNode) 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