Search in sources :

Example 1 with ElixirList

use of org.elixir_lang.psi.ElixirList in project intellij-elixir by KronicDeth.

the class Exception method defaultValueElementByKeyElement.

/**
     * The default value elements for the struct defined for the exception.
     *
     * @return Maps the element for the key in the struct to the element in the default value.  When the list form of
     *   fields without default values is used, the Map value element is {@code  null}.
     */
@NotNull
public Map<PsiElement, PsiElement> defaultValueElementByKeyElement() {
    PsiElement[] finalArguments = ElixirPsiImplUtil.finalArguments(navigationItem);
    assert finalArguments != null;
    assert finalArguments.length == 1;
    PsiElement finalArgument = finalArguments[0];
    Map<PsiElement, PsiElement> defaultValueElementByKeyElement = new HashMap<PsiElement, PsiElement>(finalArguments.length);
    if (finalArgument instanceof ElixirAccessExpression) {
        PsiElement accessExpressionChild = stripAccessExpression(finalArgument);
        assert accessExpressionChild instanceof ElixirList;
        ElixirList list = (ElixirList) accessExpressionChild;
        PsiElement[] listChildren = list.getChildren();
        if (listChildren.length == 1) {
            PsiElement listChild = listChildren[0];
            if (listChild instanceof QuotableKeywordList) {
                QuotableKeywordList quotableKeywordList = (QuotableKeywordList) listChild;
                putQuotableKeywordList(defaultValueElementByKeyElement, quotableKeywordList);
            } else {
                defaultValueElementByKeyElement.put(listChild, null);
            }
        } else {
            for (PsiElement key : list.getChildren()) {
                defaultValueElementByKeyElement.put(key, null);
            }
        }
    } else if (finalArgument instanceof QuotableKeywordList) {
        QuotableKeywordList quotableKeywordList = (QuotableKeywordList) finalArgument;
        putQuotableKeywordList(defaultValueElementByKeyElement, quotableKeywordList);
    } else {
        assert finalArgument != null;
    }
    return defaultValueElementByKeyElement;
}
Also used : HashMap(java.util.HashMap) ElixirList(org.elixir_lang.psi.ElixirList) ElixirAccessExpression(org.elixir_lang.psi.ElixirAccessExpression) QuotableKeywordList(org.elixir_lang.psi.QuotableKeywordList) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ElixirList

use of org.elixir_lang.psi.ElixirList in project intellij-elixir by KronicDeth.

the class Delegation method callDefinitionHeadCallList.

/*
     * Static Methods
     */
public static List<Call> callDefinitionHeadCallList(Call defdelegateCall) {
    List<Call> callDefinitionHeadCallList = null;
    PsiElement[] finalArguments = ElixirPsiImplUtil.finalArguments(defdelegateCall);
    assert finalArguments != null;
    assert finalArguments.length > 0;
    PsiElement firstFinalArgument = finalArguments[0];
    if (firstFinalArgument instanceof ElixirAccessExpression) {
        PsiElement accessExpressionChild = stripAccessExpression(firstFinalArgument);
        if (accessExpressionChild instanceof ElixirList) {
            ElixirList list = (ElixirList) accessExpressionChild;
            Call[] listCalls = PsiTreeUtil.getChildrenOfType(list, Call.class);
            callDefinitionHeadCallList = filterCallDefinitionHeadCallList(listCalls);
        }
    } else if (firstFinalArgument instanceof Call) {
        Call call = (Call) firstFinalArgument;
        callDefinitionHeadCallList = filterCallDefinitionHeadCallList(call);
    }
    if (callDefinitionHeadCallList == null) {
        callDefinitionHeadCallList = Collections.emptyList();
    }
    return callDefinitionHeadCallList;
}
Also used : Call(org.elixir_lang.psi.call.Call) ElixirList(org.elixir_lang.psi.ElixirList) ElixirAccessExpression(org.elixir_lang.psi.ElixirAccessExpression) PsiElement(com.intellij.psi.PsiElement)

Example 3 with ElixirList

use of org.elixir_lang.psi.ElixirList in project intellij-elixir by KronicDeth.

the class Field method is.

/*
     * Static Methods
     */
public static boolean is(ElixirAtom atom) {
    boolean field = false;
    PsiElement parent = atom.getParent();
    if (parent instanceof ElixirAccessExpression && parent.getChildren().length == 1) {
        PsiElement grandParent = parent.getParent();
        if (grandParent instanceof ElixirList) {
            PsiElement greatGrandParent = grandParent.getParent();
            if (greatGrandParent instanceof ElixirAccessExpression && greatGrandParent.getChildren().length == 1) {
                PsiElement greatGreatGrandParent = greatGrandParent.getParent();
                if (greatGreatGrandParent instanceof ElixirNoParenthesesOneArgument) {
                    PsiElement greatGreatGreatGrandParent = greatGreatGrandParent.getParent();
                    if (greatGreatGreatGrandParent instanceof Call) {
                        Call greatGreatGreatGrandParentCall = (Call) greatGreatGreatGrandParent;
                        field = Structure.is(greatGreatGreatGrandParentCall);
                    }
                }
            }
        }
    }
    return field;
}
Also used : Call(org.elixir_lang.psi.call.Call) ElixirNoParenthesesOneArgument(org.elixir_lang.psi.ElixirNoParenthesesOneArgument) ElixirList(org.elixir_lang.psi.ElixirList) ElixirAccessExpression(org.elixir_lang.psi.ElixirAccessExpression) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)3 ElixirAccessExpression (org.elixir_lang.psi.ElixirAccessExpression)3 ElixirList (org.elixir_lang.psi.ElixirList)3 Call (org.elixir_lang.psi.call.Call)2 HashMap (java.util.HashMap)1 ElixirNoParenthesesOneArgument (org.elixir_lang.psi.ElixirNoParenthesesOneArgument)1 QuotableKeywordList (org.elixir_lang.psi.QuotableKeywordList)1 NotNull (org.jetbrains.annotations.NotNull)1