Search in sources :

Example 1 with QuotableKeywordList

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

the class Overridable method getChildren.

/**
 * Returns the list of children of the tree element.
 *
 * @return the list of children.
 */
@NotNull
@Override
public TreeElement[] getChildren() {
    QuotableKeywordList keywordArguments = keywordArguments(navigationItem);
    TreeElement[] children;
    if (keywordArguments != null) {
        List<QuotableKeywordPair> quotableKeywordPairList = keywordArguments.quotableKeywordPairList();
        List<TreeElement> treeElementList = new ArrayList<TreeElement>(quotableKeywordPairList.size());
        for (QuotableKeywordPair quotableKeywordPair : quotableKeywordPairList) {
            Quotable keywordKey = quotableKeywordPair.getKeywordKey();
            OtpErlangObject quotedKeywordKey = keywordKey.quote();
            String name;
            if (quotedKeywordKey instanceof OtpErlangAtom) {
                OtpErlangAtom keywordKeyAtom = (OtpErlangAtom) quotedKeywordKey;
                name = keywordKeyAtom.atomValue();
            } else {
                name = keywordKey.getText();
            }
            Quotable keywordValue = quotableKeywordPair.getKeywordValue();
            OtpErlangObject quotedKeywordValue = keywordValue.quote();
            Integer arity = null;
            if (quotedKeywordValue instanceof OtpErlangLong) {
                OtpErlangLong keywordValueErlangLong = (OtpErlangLong) quotedKeywordValue;
                try {
                    arity = keywordValueErlangLong.intValue();
                } catch (OtpErlangRangeException e) {
                    arity = null;
                }
            }
            boolean overridable = true;
            // noinspection ConstantConditions
            treeElementList.add(new CallReference(modular, quotableKeywordPair, Timed.Time.RUN, overridable, name, arity));
        }
        children = treeElementList.toArray(new TreeElement[treeElementList.size()]);
    } else {
        children = new TreeElement[0];
    }
    return children;
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) ArrayList(java.util.ArrayList) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) Quotable(org.elixir_lang.psi.Quotable) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) QuotableKeywordList(org.elixir_lang.psi.QuotableKeywordList) QuotableKeywordPair(org.elixir_lang.psi.QuotableKeywordPair) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with QuotableKeywordList

use of org.elixir_lang.psi.QuotableKeywordList 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 = 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 3 with QuotableKeywordList

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

the class FieldWithDefaultValue method is.

/*
     * Static Methods
     */
public static boolean is(QuotableKeywordPair quotableKeywordPair) {
    boolean fieldWithDefaultValue = false;
    PsiElement parent = quotableKeywordPair.getParent();
    if (parent instanceof QuotableKeywordList) {
        PsiElement grandParent = parent.getParent();
        if (grandParent instanceof ElixirNoParenthesesOneArgument) {
            PsiElement greatGrandParent = grandParent.getParent();
            if (greatGrandParent instanceof Call) {
                Call greatGrandParentCall = (Call) greatGrandParent;
                fieldWithDefaultValue = Structure.is(greatGrandParentCall);
            }
        }
    }
    return fieldWithDefaultValue;
}
Also used : Call(org.elixir_lang.psi.call.Call) ElixirNoParenthesesOneArgument(org.elixir_lang.psi.ElixirNoParenthesesOneArgument) QuotableKeywordList(org.elixir_lang.psi.QuotableKeywordList) PsiElement(com.intellij.psi.PsiElement)

Aggregations

QuotableKeywordList (org.elixir_lang.psi.QuotableKeywordList)3 PsiElement (com.intellij.psi.PsiElement)2 NotNull (org.jetbrains.annotations.NotNull)2 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ElixirAccessExpression (org.elixir_lang.psi.ElixirAccessExpression)1 ElixirList (org.elixir_lang.psi.ElixirList)1 ElixirNoParenthesesOneArgument (org.elixir_lang.psi.ElixirNoParenthesesOneArgument)1 Quotable (org.elixir_lang.psi.Quotable)1 QuotableKeywordPair (org.elixir_lang.psi.QuotableKeywordPair)1 Call (org.elixir_lang.psi.call.Call)1