• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nshkrdotcom / ElixirScope / f6aca62b40bb7398234ae7c2ebcd30112dae0f97

30 May 2025 02:04AM UTC coverage: 57.458% (-0.002%) from 57.46%
f6aca62b40bb7398234ae7c2ebcd30112dae0f97

push

github

NSHkr
refactor project_populator

185 of 249 new or added lines in 11 files covered. (74.3%)

3 existing lines in 2 files now uncovered.

6194 of 10780 relevant lines covered (57.46%)

3134.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.62
/lib/elixir_scope/ast_repository/enhanced/project_populator/ast_extractor.ex
1
defmodule ElixirScope.ASTRepository.Enhanced.ProjectPopulator.ASTExtractor do
2
  @moduledoc """
3
  Extracts information from AST structures.
4

5
  Provides functionality to:
6
  - Extract module names from AST
7
  - Extract functions from modules
8
  - Extract dependencies, exports, and attributes
9
  """
10

11
  @doc """
12
  Extracts module name from AST.
13
  """
14
  def extract_module_name(ast) do
15
    case ast do
397✔
16
      {:defmodule, _, [module_alias, _body]} ->
17
        case module_alias do
397✔
18
          {:__aliases__, _, parts} -> Module.concat(parts)
397✔
NEW
19
          atom when is_atom(atom) -> atom
×
NEW
20
          _ -> nil
×
21
        end
NEW
22
      _ -> nil
×
23
    end
24
  end
25

26
  @doc """
27
  Extracts functions from module AST.
28
  """
29
  def extract_functions_from_module(ast) do
30
    case ast do
397✔
31
      {:defmodule, _, [_module_name, [do: body]]} ->
32
        extract_functions_from_body(body, [])
397✔
NEW
33
      _ -> []
×
34
    end
35
  end
36

37
  @doc """
38
  Extracts module dependencies from AST.
39
  """
40
  def extract_module_dependencies(_ast) do
41
    # Extract alias, import, use, and require statements
42
    dependencies = []
397✔
43

44
    # This would be a more sophisticated implementation
45
    # For now, return empty list
46
    dependencies
397✔
47
  end
48

49
  @doc """
50
  Extracts module exports from AST.
51
  """
52
  def extract_module_exports(_ast) do
53
    # Extract @spec and public function definitions
54
    exports = []
397✔
55

56
    # This would be a more sophisticated implementation
57
    # For now, return empty list
58
    exports
397✔
59
  end
60

61
  @doc """
62
  Extracts module attributes from AST.
63
  """
64
  def extract_module_attributes(_ast) do
65
    # Extract module attributes like @moduledoc, @doc, @spec, etc.
66
    attributes = %{}
397✔
67

68
    # This would be a more sophisticated implementation
69
    # For now, return empty map
70
    attributes
397✔
71
  end
72

73
  # Private functions
74

75
  defp extract_functions_from_body({:__block__, _, statements}, acc) do
76
    Enum.reduce(statements, acc, &extract_function_from_statement/2)
270✔
77
  end
78
  defp extract_functions_from_body(statement, acc) do
79
    extract_function_from_statement(statement, acc)
127✔
80
  end
81

82
  defp extract_function_from_statement({:def, meta, [{:when, _, [{name, _, args}, _guard]}, body]}, acc) do
83
    arity = if is_list(args), do: length(args), else: 0
407✔
84
    [{name, arity, {:def, meta, [{name, [], args || []}, body]}} | acc]
407✔
85
  end
86
  defp extract_function_from_statement({:defp, meta, [{:when, _, [{name, _, args}, _guard]}, body]}, acc) do
87
    arity = if is_list(args), do: length(args), else: 0
400✔
88
    [{name, arity, {:defp, meta, [{name, [], args || []}, body]}} | acc]
400✔
89
  end
90
  defp extract_function_from_statement({:def, meta, [{name, _, args}, body]}, acc) do
91
    arity = if is_list(args), do: length(args), else: 0
534✔
92
    [{name, arity, {:def, meta, [{name, [], args || []}, body]}} | acc]
534✔
93
  end
94
  defp extract_function_from_statement({:defp, meta, [{name, _, args}, body]}, acc) do
95
    arity = if is_list(args), do: length(args), else: 0
419✔
96
    [{name, arity, {:defp, meta, [{name, [], args || []}, body]}} | acc]
419✔
97
  end
98
  defp extract_function_from_statement(_, acc), do: acc
218✔
99
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc