Metastatic.Analysis.Duplication.Types (Metastatic v0.10.4)

View Source

Clone type definitions for code duplication detection.

Defines four standard types of code clones based on academic research:

  • Type I: Exact clones (identical code, ignoring whitespace/comments)
  • Type II: Renamed clones (identical structure, different identifiers/literals)
  • Type III: Near-miss clones (similar structure with minor modifications)
  • Type IV: Semantic clones (different syntax, same behavior)

References

  • Chanchal K. Roy and James R. Cordy. "A Survey on Software Clone Detection Research" (2007)
  • Ira Baxter et al. "Clone Detection Using Abstract Syntax Trees" (1998)

Examples

iex> Metastatic.Analysis.Duplication.Types.type_i()
:type_i

iex> Metastatic.Analysis.Duplication.Types.all_types()
[:type_i, :type_ii, :type_iii, :type_iv]

Summary

Types

Clone type classification.

Functions

Returns all clone types.

Returns human-readable description of a clone type.

Returns the Type I clone type atom.

Returns the Type II clone type atom.

Returns the Type III clone type atom.

Returns the Type IV clone type atom.

Checks if a clone type is valid.

Types

clone_type()

@type clone_type() :: :type_i | :type_ii | :type_iii | :type_iv

Clone type classification.

  • :type_i - Exact clones (identical AST)
  • :type_ii - Renamed clones (identical structure, different names)
  • :type_iii - Near-miss clones (similar with modifications)
  • :type_iv - Semantic clones (different syntax, same semantics)

Functions

all_types()

@spec all_types() :: [clone_type()]

Returns all clone types.

Examples

iex> Metastatic.Analysis.Duplication.Types.all_types()
[:type_i, :type_ii, :type_iii, :type_iv]

describe(atom)

@spec describe(clone_type()) :: String.t()

Returns human-readable description of a clone type.

Examples

iex> Metastatic.Analysis.Duplication.Types.describe(:type_i)
"Exact clone (identical code)"

iex> Metastatic.Analysis.Duplication.Types.describe(:type_ii)
"Renamed clone (identical structure, different identifiers)"

iex> Metastatic.Analysis.Duplication.Types.describe(:type_iii)
"Near-miss clone (similar structure with modifications)"

iex> Metastatic.Analysis.Duplication.Types.describe(:type_iv)
"Semantic clone (different syntax, same behavior)"

type_i()

@spec type_i() :: :type_i

Returns the Type I clone type atom.

Type I clones are exact copies with identical AST structure. Only whitespace and comments may differ.

Examples

iex> Metastatic.Analysis.Duplication.Types.type_i()
:type_i

type_ii()

@spec type_ii() :: :type_ii

Returns the Type II clone type atom.

Type II clones have identical structure but different variable names, literal values, or function names.

Examples

iex> Metastatic.Analysis.Duplication.Types.type_ii()
:type_ii

type_iii()

@spec type_iii() :: :type_iii

Returns the Type III clone type atom.

Type III clones are near-miss clones with similar structure but some statements added, removed, or modified.

Examples

iex> Metastatic.Analysis.Duplication.Types.type_iii()
:type_iii

type_iv()

@spec type_iv() :: :type_iv

Returns the Type IV clone type atom.

Type IV clones are semantic clones with different syntax but identical functionality or behavior.

Examples

iex> Metastatic.Analysis.Duplication.Types.type_iv()
:type_iv

valid?(type)

@spec valid?(atom()) :: boolean()

Checks if a clone type is valid.

Examples

iex> Metastatic.Analysis.Duplication.Types.valid?(:type_i)
true

iex> Metastatic.Analysis.Duplication.Types.valid?(:invalid)
false