Juggernaut.Mutator.Calls (Juggernaut v0.4.0)

Copy Markdown View Source

Resolves a call site to {module, function, arguments} and rebuilds it in the form it was written.

Three forms are recognised: a remote call (Enum.sort(xs), :math.pi(), an aliased module), a local call (min(a, b), resolved to the module's own function, then Kernel, then a module it imports) and a pipe (xs |> Enum.sort(), resolved as the call it is sugar for, with the piped value as the first argument). The call on the right of a pipe is not resolved on its own: the |> node stands for it, so a family never sees a call one argument short.

Summary

Functions

Whether fun/arity is a function or macro of Kernel.

The call rebuilt with another function name and arguments, in its written form: a pipe stays a pipe (its first argument is the piped value).

Resolves node to a call, or :error when it is not one.

The module of a remote call's target: an alias, __MODULE__ or an Erlang atom.

Whether argument index (0-based, piped value included) of call is a timeout.

Types

call()

@type call() :: %{
  module: module() | nil,
  fun: atom(),
  args: [Macro.t()],
  arity: arity(),
  form: :remote | :local | :pipe,
  node: Macro.t()
}

Functions

kernel?(fun, arity)

@spec kernel?(atom(), arity()) :: boolean()

Whether fun/arity is a function or macro of Kernel.

rebuild(map, fun, args)

@spec rebuild(call(), atom(), [Macro.t()]) :: Macro.t()

The call rebuilt with another function name and arguments, in its written form: a pipe stays a pipe (its first argument is the piped value).

resolve(node, ctx)

@spec resolve(Macro.t(), Juggernaut.Mutator.Context.t()) :: {:ok, call()} | :error

Resolves node to a call, or :error when it is not one.

target_module(target, ctx)

@spec target_module(Macro.t(), Juggernaut.Mutator.Context.t()) ::
  {:ok, module()} | :error

The module of a remote call's target: an alias, __MODULE__ or an Erlang atom.

timeout_arg?(map, index)

@spec timeout_arg?(call(), non_neg_integer()) :: boolean()

Whether argument index (0-based, piped value included) of call is a timeout.