Search in sources :

Example 1 with TreeElement

use of com.intellij.ide.util.treeView.smartTree.TreeElement in project intellij-elixir by KronicDeth.

the class Module method childCallTreeElements.

/*
     * Private Static Methods
     */
@Contract(pure = true)
@Nullable
private static TreeElement[] childCallTreeElements(@NotNull Modular modular, Call[] childCalls) {
    TreeElement[] treeElements = null;
    if (childCalls != null) {
        int length = childCalls.length;
        final List<TreeElement> treeElementList = new ArrayList<TreeElement>(length);
        FunctionByNameArity functionByNameArity = new FunctionByNameArity(length, treeElementList, modular);
        MacroByNameArity macroByNameArity = new MacroByNameArity(length, treeElementList, modular);
        Set<Overridable> overridableSet = new HashSet<Overridable>();
        Set<org.elixir_lang.structure_view.element.Use> useSet = new HashSet<org.elixir_lang.structure_view.element.Use>();
        for (Call childCall : childCalls) {
            if (Callback.is(childCall)) {
                treeElementList.add(new Callback(modular, childCall));
            } else if (Delegation.is(childCall)) {
                functionByNameArity.addDelegationToTreeElementList(childCall);
            } else if (Exception.is(childCall)) {
                functionByNameArity.setException(new Exception(modular, childCall));
            } else if (CallDefinitionClause.isFunction(childCall)) {
                functionByNameArity.addClausesToCallDefinition(childCall);
            } else if (CallDefinitionSpecification.is(childCall)) {
                functionByNameArity.addSpecificationToCallDefinition(childCall);
            } else if (Implementation.is(childCall)) {
                treeElementList.add(new Implementation(modular, childCall));
            } else if (CallDefinitionClause.isMacro(childCall)) {
                macroByNameArity.addClausesToCallDefinition(childCall);
            } else if (Module.is(childCall)) {
                treeElementList.add(new Module(modular, childCall));
            } else if (Overridable.is(childCall)) {
                Overridable overridable = new Overridable(modular, childCall);
                overridableSet.add(overridable);
                treeElementList.add(overridable);
            } else if (Protocol.is(childCall)) {
                treeElementList.add(new Protocol(modular, childCall));
            } else if (org.elixir_lang.structure_view.element.Quote.is(childCall)) {
                treeElementList.add(new Quote(modular, childCall));
            } else if (Structure.is(childCall)) {
                treeElementList.add(new Structure(modular, childCall));
            } else if (Type.is(childCall)) {
                treeElementList.add(Type.fromCall(modular, childCall));
            } else if (org.elixir_lang.structure_view.element.Use.is(childCall)) {
                org.elixir_lang.structure_view.element.Use use = new org.elixir_lang.structure_view.element.Use(modular, childCall);
                useSet.add(use);
                treeElementList.add(use);
            } else if (Unknown.is(childCall)) {
                // Should always be last since it will match all macro calls
                treeElementList.add(new Unknown(modular, childCall));
            }
        }
        for (Overridable overridable : overridableSet) {
            for (TreeElement treeElement : overridable.getChildren()) {
                CallReference callReference = (CallReference) treeElement;
                Integer arity = callReference.arity();
                if (arity != null) {
                    String name = callReference.name();
                    CallDefinition function = functionByNameArity.get(pair(name, arity));
                    if (function != null) {
                        function.setOverridable(true);
                    }
                }
            }
        }
        Collection<TreeElement> useCollection = new HashSet<TreeElement>(useSet.size());
        useCollection.addAll(useSet);
        Collection<TreeElement> nodesFromUses = Used.provideNodesFromChildren(useCollection);
        Map<Pair<String, Integer>, CallDefinition> useFunctionByNameArity = Used.functionByNameArity(nodesFromUses);
        for (Map.Entry<Pair<String, Integer>, CallDefinition> useNameArityFunction : useFunctionByNameArity.entrySet()) {
            CallDefinition useFunction = useNameArityFunction.getValue();
            if (useFunction.isOverridable()) {
                Pair<String, Integer> useNameArity = useNameArityFunction.getKey();
                CallDefinition function = functionByNameArity.get(useNameArity);
                if (function != null) {
                    function.setOverride(true);
                }
            }
        }
        treeElements = treeElementList.toArray(new TreeElement[treeElementList.size()]);
    }
    return treeElements;
}
Also used : MacroByNameArity(org.elixir_lang.structure_view.element.call_definition_by_name_arity.MacroByNameArity) CallDefinition(org.elixir_lang.structure_view.element.CallDefinition) FunctionByNameArity(org.elixir_lang.structure_view.element.call_definition_by_name_arity.FunctionByNameArity) Structure(org.elixir_lang.structure_view.element.structure.Structure) org.elixir_lang.structure_view.element(org.elixir_lang.structure_view.element) Pair(com.intellij.openapi.util.Pair) Call(org.elixir_lang.psi.call.Call) ElixirPsiImplUtil.enclosingMacroCall(org.elixir_lang.psi.impl.ElixirPsiImplUtil.enclosingMacroCall) Overridable(org.elixir_lang.structure_view.element.Overridable) Exception(org.elixir_lang.structure_view.element.Exception) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) Quote(org.elixir_lang.structure_view.element.Quote) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with TreeElement

use of com.intellij.ide.util.treeView.smartTree.TreeElement in project intellij-elixir by KronicDeth.

the class Quote method getChildren.

/**
     * Returns the list of children of the tree element.
     *
     * @return the list of children.
     */
@NotNull
@Override
public TreeElement[] getChildren() {
    Modular modular = modular();
    TreeElement[] children;
    if (modular != null) {
        children = Module.callChildren(modular, navigationItem);
    } else {
        children = new TreeElement[0];
    }
    return children;
}
Also used : Modular(org.elixir_lang.structure_view.element.modular.Modular) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with TreeElement

use of com.intellij.ide.util.treeView.smartTree.TreeElement in project intellij-elixir by KronicDeth.

the class Structure method getChildren.

/*
     * Instance Methods
     */
/**
     * Returns the list of children of the tree element.
     *
     * @return the list of children.
     */
@NotNull
@Override
public TreeElement[] getChildren() {
    PsiElement[] finalArguments = ElixirPsiImplUtil.finalArguments(navigationItem);
    List<TreeElement> childList = new ArrayList<TreeElement>();
    assert finalArguments != null;
    assert finalArguments.length == 1;
    PsiElement finalArgument = finalArguments[0];
    if (finalArgument instanceof QuotableKeywordList) {
        addDefaultValueByField(childList, (QuotableKeywordList) finalArgument);
    } else if (finalArgument instanceof ElixirAccessExpression) {
        PsiElement accessExpressionChild = stripAccessExpression(finalArgument);
        if (accessExpressionChild instanceof ElixirList) {
            ElixirList list = (ElixirList) accessExpressionChild;
            PsiElement[] listChildren = list.getChildren();
            for (PsiElement listChild : listChildren) {
                if (listChild instanceof QuotableKeywordList) {
                    addDefaultValueByField(childList, (QuotableKeywordList) listChild);
                } else if (listChild instanceof ElixirAccessExpression) {
                    PsiElement listChildAccessExpressionChild = stripAccessExpression(listChild);
                    if (listChildAccessExpressionChild instanceof ElixirAtom) {
                        childList.add(new Field(this, (ElixirAtom) listChildAccessExpressionChild));
                    }
                }
            }
        }
    } else {
    // TODO handle metaprogramming like {@code defstruct keys}
    }
    return childList.toArray(new TreeElement[childList.size()]);
}
Also used : ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with TreeElement

use of com.intellij.ide.util.treeView.smartTree.TreeElement in project intellij-elixir by KronicDeth.

the class Used method provideNodes.

@NotNull
@Override
public Collection<TreeElement> provideNodes(@NotNull TreeElement node) {
    Collection<TreeElement> nodes = new ArrayList<TreeElement>();
    if (node instanceof Module) {
        Module module = (Module) node;
        TreeElement[] children = module.getChildren();
        Collection<TreeElement> childCollection = Arrays.asList(children);
        nodes = provideNodesFromChildren(childCollection);
        nodes = filterOverridden(nodes, childCollection);
    }
    return nodes;
}
Also used : Module(org.elixir_lang.structure_view.element.modular.Module) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with TreeElement

use of com.intellij.ide.util.treeView.smartTree.TreeElement in project intellij-elixir by KronicDeth.

the class CallDefinitionClause method childCallTreeElements.

@Contract(pure = true)
@Nullable
private TreeElement[] childCallTreeElements(@Nullable Call[] childCalls) {
    TreeElement[] treeElements = null;
    if (childCalls != null) {
        List<TreeElement> treeElementList = new ArrayList<TreeElement>(childCalls.length);
        for (Call childCall : childCalls) {
            addChildCall(treeElementList, childCall);
        }
        treeElements = treeElementList.toArray(new TreeElement[treeElementList.size()]);
    }
    return treeElements;
}
Also used : Call(org.elixir_lang.psi.call.Call) ElixirPsiImplUtil.enclosingMacroCall(org.elixir_lang.psi.impl.ElixirPsiImplUtil.enclosingMacroCall) ArrayList(java.util.ArrayList) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)24 NotNull (org.jetbrains.annotations.NotNull)10 ArrayList (java.util.ArrayList)7 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)5 Pair (com.intellij.openapi.util.Pair)4 PsiElement (com.intellij.psi.PsiElement)4 Call (org.elixir_lang.psi.call.Call)4 Module (org.elixir_lang.structure_view.element.modular.Module)3 Module.addClausesToCallDefinition (org.elixir_lang.structure_view.element.modular.Module.addClausesToCallDefinition)3 Nullable (org.jetbrains.annotations.Nullable)3 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)2 StructureViewModel (com.intellij.ide.structureView.StructureViewModel)2 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)2 LanguageStructureViewBuilder (com.intellij.lang.LanguageStructureViewBuilder)2 IProperty (com.intellij.lang.properties.IProperty)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 ElixirPsiImplUtil.enclosingMacroCall (org.elixir_lang.psi.impl.ElixirPsiImplUtil.enclosingMacroCall)2 Contract (org.jetbrains.annotations.Contract)2 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1