Search in sources :

Example 16 with TreeElement

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

the class Exception method getChildren.

/**
     * Returns the list of children of the tree element.
     *
     * @return the list of children.
     */
@NotNull
@Override
public TreeElement[] getChildren() {
    List<TreeElement> childList = new ArrayList<TreeElement>();
    childList.add(new Structure(modular, navigationItem));
    if (callbacks != null) {
        childList.addAll(callbacks);
    }
    return childList.toArray(new TreeElement[childList.size()]);
}
Also used : ArrayList(java.util.ArrayList) Structure(org.elixir_lang.structure_view.element.structure.Structure) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with TreeElement

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

the class Used method provideNodesFromChild.

public static Collection<TreeElement> provideNodesFromChild(@NotNull TreeElement child) {
    Collection<TreeElement> nodes = null;
    if (child instanceof Use) {
        Use use = (Use) child;
        PsiElement[] finalArguments = ElixirPsiImplUtil.finalArguments(use.call());
        assert finalArguments != null;
        if (finalArguments.length > 0) {
            PsiElement firstFinalArgument = finalArguments[0];
            if (firstFinalArgument instanceof ElixirAccessExpression) {
                PsiElement accessExpressionChild = stripAccessExpression(firstFinalArgument);
                if (accessExpressionChild instanceof QualifiableAlias) {
                    PsiReference reference = accessExpressionChild.getReference();
                    if (reference != null) {
                        PsiElement ancestor = reference.resolve();
                        while (ancestor != null && !(ancestor instanceof PsiFile)) {
                            if (ancestor instanceof Call) {
                                Call call = (Call) ancestor;
                                if (Module.is(call)) {
                                    Module module = new Module(call);
                                    Call[] childCalls = ElixirPsiImplUtil.macroChildCalls(call);
                                    if (childCalls != null) {
                                        Map<Pair<String, Integer>, CallDefinition> macroByNameArity = new HashMap<Pair<String, Integer>, CallDefinition>(childCalls.length);
                                        for (Call childCall : childCalls) {
                                            /* portion of {@link org.elixir_lang.structure_view.element.enclosingModular.Module#childCallTreeElements}
                                                       dealing with macros, restricted to __using__/1 */
                                            if (CallDefinitionClause.isMacro(childCall)) {
                                                Pair<String, IntRange> nameArityRange = CallDefinitionClause.nameArityRange(childCall);
                                                if (nameArityRange != null) {
                                                    String name = nameArityRange.first;
                                                    IntRange arityRange = nameArityRange.second;
                                                    if (name.equals(USING) && arityRange.containsInteger(1)) {
                                                        addClausesToCallDefinition(childCall, name, arityRange, macroByNameArity, module, Timed.Time.COMPILE, new Inserter<CallDefinition>() {

                                                            @Override
                                                            public void insert(CallDefinition element) {
                                                            }
                                                        });
                                                    }
                                                }
                                            }
                                        }
                                        if (macroByNameArity.size() > 0) {
                                            PsiElement[] usingArguments;
                                            CallDefinition macro;
                                            CallDefinitionClause matchingClause = null;
                                            if (finalArguments.length > 1) {
                                                usingArguments = Arrays.copyOfRange(finalArguments, 1, finalArguments.length);
                                                Pair<String, Integer> nameArity = pair(USING, usingArguments.length);
                                                macro = macroByNameArity.get(nameArity);
                                                if (macro != null) {
                                                    matchingClause = macro.matchingClause(usingArguments);
                                                }
                                            } else {
                                                /* `use <ALIAS>` will calls `__using__/1` even though there is
                                                           no additional argument, but it obviously can't select a clause. */
                                                Pair<String, Integer> nameArity = pair(USING, 1);
                                                macro = macroByNameArity.get(nameArity);
                                                List<CallDefinitionClause> macroClauseList = macro.clauseList();
                                                if (macroClauseList.size() == 1) {
                                                    matchingClause = macroClauseList.get(0);
                                                } else {
                                                // TODO match default argument clause/head to non-default argument clause that would be executed.
                                                }
                                            }
                                            if (matchingClause != null) {
                                                TreeElement[] callDefinitionClauseChildren = matchingClause.getChildren();
                                                int length = callDefinitionClauseChildren.length;
                                                if (length > 0) {
                                                    TreeElement lastCallDefinitionClauseChild = callDefinitionClauseChildren[length - 1];
                                                    if (lastCallDefinitionClauseChild instanceof Quote) {
                                                        Quote quote = (Quote) lastCallDefinitionClauseChild;
                                                        Quote injectedQuote = quote.used(use);
                                                        TreeElement[] injectedQuoteChildren = injectedQuote.getChildren();
                                                        nodes = new ArrayList<TreeElement>(injectedQuoteChildren.length);
                                                        for (TreeElement injectedQuoteChild : injectedQuoteChildren) {
                                                            if (!(injectedQuoteChild instanceof Overridable)) {
                                                                nodes.add(injectedQuoteChild);
                                                            }
                                                        }
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    break;
                                }
                            }
                            ancestor = ancestor.getParent();
                        }
                    }
                }
            }
        }
    }
    if (nodes == null) {
        nodes = Collections.emptyList();
    }
    return nodes;
}
Also used : Module.addClausesToCallDefinition(org.elixir_lang.structure_view.element.modular.Module.addClausesToCallDefinition) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair) Call(org.elixir_lang.psi.call.Call) QualifiableAlias(org.elixir_lang.psi.QualifiableAlias) ElixirAccessExpression(org.elixir_lang.psi.ElixirAccessExpression) IntRange(org.apache.commons.lang.math.IntRange) PsiReference(com.intellij.psi.PsiReference) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) Module(org.elixir_lang.structure_view.element.modular.Module)

Example 18 with TreeElement

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

the class Used method provideNodesFromChildren.

public static Collection<TreeElement> provideNodesFromChildren(@NotNull Collection<TreeElement> children) {
    Collection<TreeElement> nodes = new ArrayList<TreeElement>();
    for (TreeElement child : children) {
        Collection<TreeElement> nodesFromChild = provideNodesFromChild(child);
        nodes.addAll(nodesFromChild);
    }
    return nodes;
}
Also used : TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement)

Example 19 with TreeElement

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

the class Used method functionByNameArity.

public static Map<Pair<String, Integer>, CallDefinition> functionByNameArity(@NotNull Collection<TreeElement> children) {
    Map<Pair<String, Integer>, CallDefinition> functionByNameArity = new HashMap<Pair<String, Integer>, CallDefinition>(children.size());
    for (TreeElement child : children) {
        if (child instanceof CallDefinition) {
            CallDefinition callDefinition = (CallDefinition) child;
            if (callDefinition.time() == Timed.Time.RUN) {
                Pair<String, Integer> nameArity = pair(callDefinition.name(), callDefinition.arity());
                functionByNameArity.put(nameArity, callDefinition);
            }
        }
    }
    return functionByNameArity;
}
Also used : Module.addClausesToCallDefinition(org.elixir_lang.structure_view.element.modular.Module.addClausesToCallDefinition) Pair(com.intellij.openapi.util.Pair) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement)

Example 20 with TreeElement

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

the class Used method filterOverridden.

/*
     * Static Methods
     */
public static Collection<TreeElement> filterOverridden(@NotNull Collection<TreeElement> nodesFromChildren, @NotNull Collection<TreeElement> children) {
    Map<Pair<String, Integer>, CallDefinition> childFunctionByNameArity = functionByNameArity(children);
    Collection<TreeElement> filtered = new ArrayList<TreeElement>(nodesFromChildren.size());
    for (TreeElement nodeFromChildren : nodesFromChildren) {
        if (nodeFromChildren instanceof CallDefinition) {
            CallDefinition callDefinition = (CallDefinition) nodeFromChildren;
            // only functions work with defoverridable
            if (callDefinition.time() == Timed.Time.RUN) {
                Pair<String, Integer> nameArity = pair(callDefinition.name(), callDefinition.arity());
                if (childFunctionByNameArity.containsKey(nameArity)) {
                    continue;
                }
            }
        }
        filtered.add(nodeFromChildren);
    }
    return filtered;
}
Also used : Module.addClausesToCallDefinition(org.elixir_lang.structure_view.element.modular.Module.addClausesToCallDefinition) Pair(com.intellij.openapi.util.Pair) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement)

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