Class: Steep::Index::RBSIndex::TypeEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/index/rbs_index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_name:) ⇒ TypeEntry

Returns a new instance of TypeEntry.



9
10
11
12
13
# File 'lib/steep/index/rbs_index.rb', line 9

def initialize(type_name:)
  @type_name = type_name
  @declarations = Set[]
  @references = Set[]
end

Instance Attribute Details

#declarationsObject (readonly)

Returns the value of attribute declarations.



6
7
8
# File 'lib/steep/index/rbs_index.rb', line 6

def declarations
  @declarations
end

#referencesObject (readonly)

Returns the value of attribute references.



7
8
9
# File 'lib/steep/index/rbs_index.rb', line 7

def references
  @references
end

#type_nameObject (readonly)

Returns the value of attribute type_name.



5
6
7
# File 'lib/steep/index/rbs_index.rb', line 5

def type_name
  @type_name
end

Instance Method Details

#add_declaration(decl) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/steep/index/rbs_index.rb', line 15

def add_declaration(decl)
  case decl
  when RBS::AST::Declarations::Class, RBS::AST::Declarations::Module
    declarations << decl
  when RBS::AST::Declarations::Interface
    declarations << decl
  when RBS::AST::Declarations::TypeAlias
    declarations << decl
  when RBS::AST::Declarations::ClassAlias, RBS::AST::Declarations::ModuleAlias
    declarations << decl
  when RBS::AST::Ruby::Declarations::ClassDecl
    declarations << decl
  when RBS::AST::Ruby::Declarations::ModuleDecl
    declarations << decl
  when RBS::AST::Ruby::Declarations::ClassModuleAliasDecl
    declarations << decl
  else
    raise "Unexpected type declaration: #{decl}"
  end

  self
end

#add_reference(ref) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/steep/index/rbs_index.rb', line 38

def add_reference(ref)
  case ref
  when RBS::AST::Members::MethodDefinition
    references << ref
  when RBS::AST::Members::AttrAccessor, RBS::AST::Members::AttrReader, RBS::AST::Members::AttrWriter
    references << ref
  when RBS::AST::Members::InstanceVariable, RBS::AST::Members::ClassInstanceVariable, RBS::AST::Members::ClassVariable
    references << ref
  when RBS::AST::Members::Include, RBS::AST::Members::Extend
    references << ref
  when RBS::AST::Declarations::Module, RBS::AST::Declarations::Class
    references << ref
  when RBS::AST::Declarations::Constant, RBS::AST::Declarations::Global
    references << ref
  when RBS::AST::Declarations::TypeAlias
    references << ref
  when RBS::AST::Declarations::ClassAlias, RBS::AST::Declarations::ModuleAlias
    references << ref
  when RBS::AST::Ruby::Declarations::ClassModuleAliasDecl
    references << ref
  else
    raise "Unexpected type reference: #{ref}"
  end

  self
end