Search in sources :

Example 1 with CallDefinition

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

the class CallDefinitionByTuple method putNew.

/**
     * Generates a {@link CallDefinition} for the given
     * {@link org.elixir_lang.structure_view.element.CallDefinition.Tuple} if it does not exist.
     */
@NotNull
public CallDefinition putNew(@NotNull CallDefinition.Tuple tuple) {
    CallDefinition callDefinition = get(tuple);
    if (callDefinition == null) {
        callDefinition = new CallDefinition(tuple.modular, tuple.time, tuple.name, tuple.arity);
        put(tuple, callDefinition);
    }
    return callDefinition;
}
Also used : CallDefinition(org.elixir_lang.structure_view.element.CallDefinition) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CallDefinition

use of org.elixir_lang.structure_view.element.CallDefinition 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 3 with CallDefinition

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

the class TreeElementList method putNew.

/**
     * Generates a {@link CallDefinition} for the given {@code nameArity} if it does not exist.
     * <p/>
     * The {@link CallDefinition} is
     *
     * @param nameArity
     * @return pre-existing {@link CallDefinition} or new {@link CallDefinition} add to the {@code List<TreeElement>}
     */
@NotNull
@Override
public CallDefinition putNew(@NotNull Pair<String, Integer> nameArity) {
    CallDefinition callDefinition = super.get(nameArity);
    if (callDefinition == null) {
        callDefinition = new CallDefinition(modular, time, nameArity.first, nameArity.second);
        put(nameArity, callDefinition);
        addToTreeElementList(callDefinition);
    }
    return callDefinition;
}
Also used : CallDefinition(org.elixir_lang.structure_view.element.CallDefinition) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with CallDefinition

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

the class Module method addClausesToCallDefinition.

public static void addClausesToCallDefinition(@NotNull Call call, @NotNull String name, @NotNull IntRange arityRange, @NotNull Map<Pair<String, Integer>, CallDefinition> callDefinitionByNameArity, @NotNull Modular modular, @NotNull Timed.Time time, @NotNull Inserter<CallDefinition> callDefinitionInserter) {
    for (int arity = arityRange.getMinimumInteger(); arity <= arityRange.getMaximumInteger(); arity++) {
        Pair<String, Integer> nameArity = pair(name, arity);
        CallDefinition callDefinition = callDefinitionByNameArity.get(nameArity);
        if (callDefinition == null) {
            callDefinition = new CallDefinition(modular, time, name, arity);
            callDefinitionByNameArity.put(nameArity, callDefinition);
            callDefinitionInserter.insert(callDefinition);
        }
        callDefinition.clause(call);
    }
}
Also used : CallDefinition(org.elixir_lang.structure_view.element.CallDefinition)

Example 5 with CallDefinition

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

the class GotoSymbolContributorTest method testIssue472.

/*
     * Tests
     */
public void testIssue472() {
    myFixture.configureByFile("issue_472.ex");
    ChooseByNameContributor[] symbolModelContributors = ChooseByNameRegistry.getInstance().getSymbolModelContributors();
    GotoSymbolContributor gotoSymbolContributor = null;
    for (ChooseByNameContributor symbolModelContributor : symbolModelContributors) {
        if (symbolModelContributor instanceof GotoSymbolContributor) {
            gotoSymbolContributor = (GotoSymbolContributor) symbolModelContributor;
        }
    }
    assertNotNull(gotoSymbolContributor);
    NavigationItem[] itemsByName = gotoSymbolContributor.getItemsByName("decode_auth_type", "decode_a", myFixture.getProject(), false);
    assertEquals(2, itemsByName.length);
    assertInstanceOf(itemsByName[0], CallDefinition.class);
    CallDefinition callDefinition = (CallDefinition) itemsByName[0];
    assertEquals("decode_auth_type", callDefinition.name());
    assertInstanceOf(itemsByName[1], CallDefinitionClause.class);
    CallDefinitionClause callDefinitionClause = (CallDefinitionClause) itemsByName[1];
    assertEquals("decode_auth_type", callDefinitionClause.getName());
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) CallDefinition(org.elixir_lang.structure_view.element.CallDefinition) ChooseByNameContributor(com.intellij.navigation.ChooseByNameContributor) CallDefinitionClause(org.elixir_lang.structure_view.element.CallDefinitionClause)

Aggregations

CallDefinition (org.elixir_lang.structure_view.element.CallDefinition)6 NotNull (org.jetbrains.annotations.NotNull)2 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)1 ChooseByNameContributor (com.intellij.navigation.ChooseByNameContributor)1 NavigationItem (com.intellij.navigation.NavigationItem)1 Pair (com.intellij.openapi.util.Pair)1 Call (org.elixir_lang.psi.call.Call)1 ElixirPsiImplUtil.enclosingMacroCall (org.elixir_lang.psi.impl.ElixirPsiImplUtil.enclosingMacroCall)1 org.elixir_lang.structure_view.element (org.elixir_lang.structure_view.element)1 CallDefinitionClause (org.elixir_lang.structure_view.element.CallDefinitionClause)1 Exception (org.elixir_lang.structure_view.element.Exception)1 Overridable (org.elixir_lang.structure_view.element.Overridable)1 Quote (org.elixir_lang.structure_view.element.Quote)1 FunctionByNameArity (org.elixir_lang.structure_view.element.call_definition_by_name_arity.FunctionByNameArity)1 MacroByNameArity (org.elixir_lang.structure_view.element.call_definition_by_name_arity.MacroByNameArity)1 Structure (org.elixir_lang.structure_view.element.structure.Structure)1 Contract (org.jetbrains.annotations.Contract)1 Nullable (org.jetbrains.annotations.Nullable)1