Search in sources :

Example 1 with OtpErlangObject

use of com.ericsson.otp.erlang.OtpErlangObject in project intellij-elixir by KronicDeth.

the class ElixirMapXValue method computeChild.

@Override
protected void computeChild(XValueChildrenList children, int childIdx) {
    OtpErlangObject key = getValue().keys()[childIdx];
    OtpErlangObject value = getValue().get(key);
    if (ElixirXValuePresentation.hasSymbolKeys(getValue()) && key instanceof OtpErlangAtom) {
        String keyStr = ((OtpErlangAtom) key).atomValue();
        if (!keyStr.equals("__struct__"))
            addNamedChild(children, value, keyStr);
    } else {
        addIndexedChild(children, new ElixirMappingXValue(key, value), childIdx);
    }
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 2 with OtpErlangObject

use of com.ericsson.otp.erlang.OtpErlangObject in project intellij-elixir by KronicDeth.

the class ModuleDefinition method name.

public String name() {
    OtpErlangTuple quotedDefmodule = (OtpErlangTuple) defmodule.quote();
    OtpErlangList callArguments = Macro.callArguments(quotedDefmodule);
    // Alias + block
    assert callArguments.arity() == 2;
    OtpErlangObject quotedName = callArguments.elementAt(0);
    // TODO handle other forms for module names
    assert Macro.isAliases(quotedName);
    return Macro.toString(quotedName);
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Example 3 with OtpErlangObject

use of com.ericsson.otp.erlang.OtpErlangObject in project intellij-elixir by KronicDeth.

the class Import method keywordKeyToName.

@Nullable
private static String keywordKeyToName(@NotNull final Quotable keywordKey) {
    OtpErlangObject quotedKeywordKey = keywordKey.quote();
    String name = null;
    if (quotedKeywordKey instanceof OtpErlangAtom) {
        OtpErlangAtom keywordKeyAtom = (OtpErlangAtom) quotedKeywordKey;
        name = keywordKeyAtom.atomValue();
    }
    return name;
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with OtpErlangObject

use of com.ericsson.otp.erlang.OtpErlangObject 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 = ElixirPsiImplUtil.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 5 with OtpErlangObject

use of com.ericsson.otp.erlang.OtpErlangObject in project intellij-elixir by KronicDeth.

the class BreakpointReachedEvent method getBindings.

@NotNull
private static Collection<ElixirVariableBinding> getBindings(@Nullable OtpErlangList bindingsList) {
    if (bindingsList == null)
        return ContainerUtil.emptyList();
    Collection<ElixirVariableBinding> bindings = new ArrayList<>(bindingsList.arity());
    for (OtpErlangObject bindingObject : bindingsList) {
        OtpErlangTuple bindingTuple = getTupleValue(bindingObject);
        String variableName = getAtomText(elementAt(bindingTuple, 0));
        OtpErlangObject variableValue = elementAt(bindingTuple, 1);
        if (variableName == null || variableValue == null)
            return ContainerUtil.emptyList();
        bindings.add(new ElixirVariableBinding(variableName, variableValue));
    }
    return bindings;
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ArrayList(java.util.ArrayList) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)7 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)3 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)3 ArrayList (java.util.ArrayList)3 Nullable (org.jetbrains.annotations.Nullable)3 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)2 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)2 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)2 NotNull (org.jetbrains.annotations.NotNull)2 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)1 Quotable (org.elixir_lang.psi.Quotable)1 QuotableKeywordList (org.elixir_lang.psi.QuotableKeywordList)1 QuotableKeywordPair (org.elixir_lang.psi.QuotableKeywordPair)1