Search in sources :

Example 1 with Module

use of org.elixir_lang.structure_view.element.modular.Module 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 2 with Module

use of org.elixir_lang.structure_view.element.modular.Module in project intellij-elixir by KronicDeth.

the class File method getChildren.

/*
     * Public Instance Methods
     */
@NotNull
@Override
public TreeElement[] getChildren() {
    Call[] calls = PsiTreeUtil.getChildrenOfType(navigationItem, Call.class);
    TreeElement[] children;
    if (calls != null) {
        List<TreeElement> treeElementList = new ArrayList<TreeElement>(calls.length);
        for (Call call : calls) {
            if (Implementation.is(call)) {
                treeElementList.add(new Implementation(call));
            } else if (Module.is(call)) {
                treeElementList.add(new Module(call));
            } else if (Protocol.is(call)) {
                treeElementList.add(new Protocol(call));
            } else if (Quote.is(call)) {
                treeElementList.add(new Quote(call));
            } else if (Unknown.is(call)) {
                // should always be last because it will match all macro calls
                treeElementList.add(new Unknown(call));
            }
        }
        children = treeElementList.toArray(new TreeElement[treeElementList.size()]);
    } else {
        children = new TreeElement[0];
    }
    return children;
}
Also used : Call(org.elixir_lang.psi.call.Call) Unknown(org.elixir_lang.structure_view.element.modular.Unknown) ArrayList(java.util.ArrayList) Module(org.elixir_lang.structure_view.element.modular.Module) Protocol(org.elixir_lang.structure_view.element.modular.Protocol) Implementation(org.elixir_lang.structure_view.element.modular.Implementation) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Module

use of org.elixir_lang.structure_view.element.modular.Module in project intellij-elixir by KronicDeth.

the class GotoSymbolContributor method getItemsFromModule.

private void getItemsFromModule(@NotNull List<NavigationItem> items, @NotNull EnclosingModularByCall enclosingModularByCall, @NotNull Call call) {
    Modular modular = enclosingModularByCall.putNew(call);
    Module module = new Module(modular, call);
    items.add(module);
}
Also used : Modular(org.elixir_lang.structure_view.element.modular.Modular) Module(org.elixir_lang.structure_view.element.modular.Module)

Example 4 with Module

use of org.elixir_lang.structure_view.element.modular.Module 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)

Aggregations

Module (org.elixir_lang.structure_view.element.modular.Module)4 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)3 Call (org.elixir_lang.psi.call.Call)2 NotNull (org.jetbrains.annotations.NotNull)2 Pair (com.intellij.openapi.util.Pair)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 PsiReference (com.intellij.psi.PsiReference)1 ArrayList (java.util.ArrayList)1 IntRange (org.apache.commons.lang.math.IntRange)1 ElixirAccessExpression (org.elixir_lang.psi.ElixirAccessExpression)1 QualifiableAlias (org.elixir_lang.psi.QualifiableAlias)1 Implementation (org.elixir_lang.structure_view.element.modular.Implementation)1 Modular (org.elixir_lang.structure_view.element.modular.Modular)1 Module.addClausesToCallDefinition (org.elixir_lang.structure_view.element.modular.Module.addClausesToCallDefinition)1 Protocol (org.elixir_lang.structure_view.element.modular.Protocol)1 Unknown (org.elixir_lang.structure_view.element.modular.Unknown)1