ExDNA.Refactor.Suggestion (ExDNA v1.5.2)

Copy Markdown View Source

Generates refactoring suggestions from detected clones.

Uses anti-unification to find the common structure between clone fragments, then proposes an extracted function whose parameters are the "holes" — the positions where the fragments diverge.

Summary

Functions

Generate a refactoring suggestion for a clone group.

Types

kind()

@type kind() :: :extract_function | :extract_macro

t()

@type t() :: %ExDNA.Refactor.Suggestion{
  body: String.t(),
  call_sites: [%{file: String.t(), line: pos_integer(), call: String.t()}],
  kind: kind(),
  name: String.t(),
  occurrence_count: non_neg_integer() | nil,
  params: [atom()]
}

Functions

suggest(clone)

@spec suggest(ExDNA.Detection.Clone.t()) :: t() | nil

Generate a refactoring suggestion for a clone group.

Takes the first two fragments, anti-unifies them, and builds a function extraction suggestion. When there are zero holes the suggestion is a simple extract; when there are holes they become function parameters.