Module: SimpleCov::Formatter::AIFormatter::ASTResolver::NodeClassifier

Extended by:
T::Sig
Defined in:
lib/simplecov-ai/ast_resolver/node_classifier.rb

Overview

Classifies a single AST node into the semantic metadata the resolver threads through traversal: the context to hand child nodes, an optional SemanticNode for the node itself, and whether children sit inside a singleton class (class << self).

Constant Summary collapse

NAMESPACE_SEPARATOR =

Separator used to denote namespace nesting (e.g., Module::Class)

T.let(ReceiverResolver::NAMESPACE_SEPARATOR, String)
INSTANCE_SEPARATOR =

Separator used to denote instance methods (e.g., Class#method)

T.let('#', String)
SINGLETON_SEPARATOR =

Separator used to denote singleton/class methods (e.g., Class.method)

T.let('.', String)
TYPE_INSTANCE_METHOD =

Label applied to nodes representing instance methods

T.let('Instance Method', String)
TYPE_SINGLETON_METHOD =

Label applied to nodes representing singleton methods

T.let('Singleton Method', String)
TOP_LEVEL_INSTANCE_OWNER =

Owner of a method defined at the top level of a file with a plain def: Ruby adds it to Object (as a private method), and SimpleCov's method coverage names it that way too

T.let('Object', String)

Class Method Summary collapse

Class Method Details

.classify(node, context, singleton) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/simplecov-ai/ast_resolver/node_classifier.rb', line 34

def self.classify(node, context, singleton)
  case node.type
  when :class, :module then (node, context)
  when :sclass then (node, context)
  when :def then (node, context, singleton)
  when :defs then (node, context, singleton)
  when :casgn then (node, context, singleton)
  else MetaclassResolver.block?(node) ? (node, context, singleton) : [context, nil, singleton]
  end
end

.constant_assignment_metadata(node, context, singleton) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/simplecov-ai/ast_resolver/node_classifier.rb', line 53

def self.(node, context, singleton)
  kind = MetaclassResolver.builder_kind(node)
  return [context, nil, singleton] unless kind

  name = NodeChildren.symbol_at(node, 1).to_s
  full_name = nest(context, nest(ReceiverResolver.const_name(NodeChildren.node_at(node, 0)), name))
  [full_name, SemanticNode.spanning(node, name: full_name, type: kind), false]
end