Search in sources :

Example 16 with Contract

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

the class ElixirPsiImplUtil method getName.

@Contract(pure = true)
@Nullable
public static String getName(@NotNull NamedElement namedElement) {
    PsiElement nameIdentifier = namedElement.getNameIdentifier();
    String name = null;
    if (nameIdentifier != null) {
        name = nameIdentifier.getText();
    } else {
        if (namedElement instanceof Call) {
            Call call = (Call) namedElement;
            /* The name of the module defined by {@code defimpl PROTOCOL[ for: MODULE]} is derived by combining the
                   PROTOCOL and MODULE name into PROTOCOL.MODULE.  Neither piece is really the "name" or
                   "nameIdentifier" element of the implementation because changing the PROTOCOL make the implementation
                   just for that different Protocol and changing the MODULE makes the implementation for a different
                   MODULE.  If `for:` isn't given, it's really the enclosing {@code defmodule MODULE} whose name should
                   be changed. */
            if (Implementation.is(call)) {
                name = Implementation.name(call);
            }
        }
    }
    return name;
}
Also used : Call(org.elixir_lang.psi.call.Call) CallDefinitionClause.enclosingModularMacroCall(org.elixir_lang.structure_view.element.CallDefinitionClause.enclosingModularMacroCall) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 17 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 ElixirBitString bitString) {
    ASTNode node = bitString.getNode();
    ASTNode[] openingBits = node.getChildren(TokenSet.create(ElixirTypes.OPENING_BIT));
    assert openingBits.length == 1;
    ASTNode openingBit = openingBits[0];
    PsiElement[] children = bitString.getChildren();
    OtpErlangObject[] quotedChildren = new OtpErlangObject[children.length];
    int i = 0;
    for (PsiElement child : children) {
        Quotable quotableChild = (Quotable) child;
        quotedChildren[i++] = quotableChild.quote();
    }
    return quotedFunctionCall("<<>>", metadata(openingBit), quotedChildren);
}
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 18 with Contract

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

the class ElixirPsiImplUtil method isOutermostQualifiableAlias.

@Contract(pure = true)
public static boolean isOutermostQualifiableAlias(@NotNull QualifiableAlias qualifiableAlias) {
    PsiElement parent = qualifiableAlias.getParent();
    boolean outermost = false;
    /* prevents individual Aliases or tail qualified aliases of qualified chain from having reference separate
           reference from overall chain */
    if (!(parent instanceof QualifiableAlias)) {
        PsiElement grandParent = parent.getParent();
        // prevents first Alias of a qualified chain from having a separate reference from overall chain
        if (!(grandParent instanceof QualifiableAlias)) {
            outermost = true;
        }
    }
    return outermost;
}
Also used : LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Contract(org.jetbrains.annotations.Contract)

Example 19 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 Heredoc heredoc) {
    ElixirHeredocPrefix heredocPrefix = heredoc.getHeredocPrefix();
    int prefixLength = heredocPrefix.getTextLength();
    Deque<ASTNode> alignedNodeQueue = new LinkedList<ASTNode>();
    List<HeredocLine> heredocLineList = heredoc.getHeredocLineList();
    IElementType fragmentType = heredoc.getFragmentType();
    for (HeredocLine line : heredocLineList) {
        queueChildNodes(line, fragmentType, prefixLength, alignedNodeQueue);
    }
    Queue<ASTNode> mergedNodeQueue = mergeFragments(alignedNodeQueue, heredoc.getFragmentType(), heredoc.getManager());
    ASTNode[] mergedNodes = new ASTNode[mergedNodeQueue.size()];
    mergedNodeQueue.toArray(mergedNodes);
    return quotedChildNodes(heredoc, mergedNodes);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ASTNode(com.intellij.lang.ASTNode) Contract(org.jetbrains.annotations.Contract) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with Contract

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

the class ElixirPsiImplUtil method stripOnlyChildParent.

@Contract(pure = true)
@NotNull
public static PsiElement stripOnlyChildParent(@NotNull PsiElement parent) {
    PsiElement unwrapped = parent;
    PsiElement[] children = parent.getChildren();
    if (children.length == 1) {
        unwrapped = children[0];
    }
    return unwrapped;
}
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