Search in sources :

Example 6 with Modular

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

the class EnclosingModularByCall method putNew.

/**
     * Generates a {@link Modular} for the given {@code call} if it does not exist.
     *
     * @param call
     * @return {@code null} if {@code call} is top-level and has no enclosing modular.
     */
@Nullable
public Modular putNew(@NotNull Call call) {
    Modular modular;
    if (containsKey(call)) {
        modular = get(call);
    } else {
        modular = CallDefinitionClause.enclosingModular(call);
        put(call, modular);
    }
    return modular;
}
Also used : Modular(org.elixir_lang.structure_view.element.modular.Modular) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with Modular

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

the class GotoSymbolContributor method getItemsFromImplementation.

private void getItemsFromImplementation(@NotNull String name, @NotNull List<NavigationItem> items, @NotNull EnclosingModularByCall enclosingModularByCall, @NotNull Call call) {
    Modular modular = enclosingModularByCall.putNew(call);
    Collection<String> forNameCollection = Implementation.forNameCollection(modular, call);
    if (forNameCollection != null) {
        for (String forName : forNameCollection) {
            Implementation forNameOverriddenImplementation = new Implementation(modular, call, forName);
            String implementationName = forNameOverriddenImplementation.getName();
            if (implementationName != null && implementationName.contains(name)) {
                items.add(forNameOverriddenImplementation);
            }
        }
    }
    if (forNameCollection == null || forNameCollection.size() < 2) {
        Implementation implementation = new Implementation(modular, call);
        items.add(implementation);
    }
}
Also used : Modular(org.elixir_lang.structure_view.element.modular.Modular) Implementation(org.elixir_lang.structure_view.element.modular.Implementation)

Example 8 with Modular

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

the class GotoSymbolContributor method getItemsFromCallDefinitionClause.

private void getItemsFromCallDefinitionClause(@NotNull List<NavigationItem> items, @NotNull EnclosingModularByCall enclosingModularByCall, @NotNull Map<CallDefinition.Tuple, CallDefinition> callDefinitionByTuple, @NotNull Call call) {
    Pair<String, IntRange> nameArityRange = CallDefinitionClause.nameArityRange(call);
    if (nameArityRange != null) {
        String callName = nameArityRange.first;
        IntRange arityRange = nameArityRange.second;
        Timed.Time time = CallDefinitionClause.time(call);
        Modular modular = enclosingModularByCall.putNew(call);
        if (modular == null) {
            // don't throw an error if really EEX, but has wrong extension
            if (!call.getText().contains("<%=")) {
                error("Cannot find enclosing Modular", call);
            }
        } else {
            for (int arity = arityRange.getMinimumInteger(); arity <= arityRange.getMaximumInteger(); arity++) {
                CallDefinition.Tuple tuple = new CallDefinition.Tuple(modular, time, callName, arity);
                CallDefinition callDefinition = callDefinitionByTuple.get(tuple);
                if (callDefinition == null) {
                    callDefinition = new CallDefinition(tuple.modular, tuple.time, tuple.name, tuple.arity);
                    items.add(callDefinition);
                    callDefinitionByTuple.put(tuple, callDefinition);
                }
                CallDefinitionClause callDefinitionClause = callDefinition.clause(call);
                items.add(callDefinitionClause);
            }
        }
    }
}
Also used : IntRange(org.apache.commons.lang.math.IntRange) Modular(org.elixir_lang.structure_view.element.modular.Modular)

Example 9 with Modular

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

the class GotoSymbolContributor method getItemsFromCallDefinitionHead.

private void getItemsFromCallDefinitionHead(@NotNull List<NavigationItem> items, @NotNull EnclosingModularByCall enclosingModularByCall, @NotNull Map<CallDefinition.Tuple, CallDefinition> callDefinitionByTuple, @NotNull Call call) {
    Call delegationCall = CallDefinitionHead.enclosingDelegationCall(call);
    if (delegationCall != null) {
        Modular modular = enclosingModularByCall.putNew(delegationCall);
        if (modular != null) {
            String callDefinitionName = call.functionName();
            if (callDefinitionName != null) {
                int callDefinitionArity = call.resolvedFinalArity();
                CallDefinition.Tuple tuple = new CallDefinition.Tuple(modular, // Delegation can't delegate macros
                Timed.Time.RUN, callDefinitionName, callDefinitionArity);
                CallDefinition callDefinition = callDefinitionByTuple.get(tuple);
                if (callDefinition == null) {
                    callDefinition = new CallDefinition(tuple.modular, tuple.time, tuple.name, tuple.arity);
                    items.add(callDefinition);
                    callDefinitionByTuple.put(tuple, callDefinition);
                }
                // Delegation is always public as import should be used for private
                Visible.Visibility visibility = Visible.Visibility.PUBLIC;
                //noinspection ConstantConditions
                CallDefinitionHead callDefinitionHead = new CallDefinitionHead(callDefinition, visibility, call);
                items.add(callDefinitionHead);
            } else {
                error("Call for CallDefinitionHead does not have function name", call);
            }
        } else {
            error("Cannot find enclosing Modular for Delegation call", delegationCall);
        }
    } else {
        error("Cannot find enclosing delegation call for CallDefinitionHead", call);
    }
}
Also used : Call(org.elixir_lang.psi.call.Call) AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) Modular(org.elixir_lang.structure_view.element.modular.Modular)

Example 10 with Modular

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

the class GotoSymbolContributor method getItemsFromProtocol.

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

Aggregations

Modular (org.elixir_lang.structure_view.element.modular.Modular)11 Nullable (org.jetbrains.annotations.Nullable)3 IntRange (org.apache.commons.lang.math.IntRange)2 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)1 AtUnqualifiedNoParenthesesCall (org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall)1 Call (org.elixir_lang.psi.call.Call)1 Implementation (org.elixir_lang.structure_view.element.modular.Implementation)1 Module (org.elixir_lang.structure_view.element.modular.Module)1 Protocol (org.elixir_lang.structure_view.element.modular.Protocol)1 NotNull (org.jetbrains.annotations.NotNull)1