Class: Steep::AST::Annotation::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/ast/annotation/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(annotations:) ⇒ Collection

Returns a new instance of Collection.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/steep/ast/annotation/collection.rb', line 19

def initialize(annotations:)
  @var_types = {}
  @method_types = {}
  @const_types = {}
  @ivar_types = {}
  @dynamics = {}
  @break_type = nil

  annotations.each do |annotation|
    case annotation
    when VarType
      var_types[annotation.name] = annotation
    when MethodType
      method_types[annotation.name] = annotation
    when BlockType
      @block_type = annotation.type
    when ReturnType
      @return_type = annotation.type
    when SelfType
      @self_type = annotation.type
    when ConstType
      @const_types[annotation.name] = annotation.type
    when InstanceType
      @instance_type = annotation.type
    when ModuleType
      @module_type = annotation.type
    when Implements
      @implement_module = annotation
    when IvarType
      ivar_types[annotation.name] = annotation.type
    when Dynamic
      annotation.names.each do |name|
        dynamics[name.name] = name
      end
    when BreakType
      @break_type = annotation.type
    else
      raise "Unexpected annotation: #{annotation.inspect}"
    end
  end

  @annotations = annotations
end

Instance Attribute Details

#annotationsObject (readonly)

Returns the value of attribute annotations.



7
8
9
# File 'lib/steep/ast/annotation/collection.rb', line 7

def annotations
  @annotations
end

#block_typeObject (readonly)

Returns the value of attribute block_type.



8
9
10
# File 'lib/steep/ast/annotation/collection.rb', line 8

def block_type
  @block_type
end

#break_typeObject (readonly)

Returns the value of attribute break_type.



17
18
19
# File 'lib/steep/ast/annotation/collection.rb', line 17

def break_type
  @break_type
end

#const_typesObject (readonly)

Returns the value of attribute const_types.



11
12
13
# File 'lib/steep/ast/annotation/collection.rb', line 11

def const_types
  @const_types
end

#dynamicsObject (readonly)

Returns the value of attribute dynamics.



16
17
18
# File 'lib/steep/ast/annotation/collection.rb', line 16

def dynamics
  @dynamics
end

#implement_moduleObject (readonly)

Returns the value of attribute implement_module.



14
15
16
# File 'lib/steep/ast/annotation/collection.rb', line 14

def implement_module
  @implement_module
end

#instance_typeObject (readonly)

Returns the value of attribute instance_type.



12
13
14
# File 'lib/steep/ast/annotation/collection.rb', line 12

def instance_type
  @instance_type
end

#ivar_typesObject (readonly)

Returns the value of attribute ivar_types.



15
16
17
# File 'lib/steep/ast/annotation/collection.rb', line 15

def ivar_types
  @ivar_types
end

#method_typesObject (readonly)

Returns the value of attribute method_types.



6
7
8
# File 'lib/steep/ast/annotation/collection.rb', line 6

def method_types
  @method_types
end

#module_typeObject (readonly)

Returns the value of attribute module_type.



13
14
15
# File 'lib/steep/ast/annotation/collection.rb', line 13

def module_type
  @module_type
end

#return_typeObject (readonly)

Returns the value of attribute return_type.



9
10
11
# File 'lib/steep/ast/annotation/collection.rb', line 9

def return_type
  @return_type
end

#self_typeObject (readonly)

Returns the value of attribute self_type.



10
11
12
# File 'lib/steep/ast/annotation/collection.rb', line 10

def self_type
  @self_type
end

#var_typesObject (readonly)

Returns the value of attribute var_types.



5
6
7
# File 'lib/steep/ast/annotation/collection.rb', line 5

def var_types
  @var_types
end

Instance Method Details

#+(other) ⇒ Object



75
76
77
# File 'lib/steep/ast/annotation/collection.rb', line 75

def +(other)
  self.class.new(annotations: annotations.reject {|a| a.is_a?(BlockType) } + other.annotations)
end

#any?(&block) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/steep/ast/annotation/collection.rb', line 79

def any?(&block)
  annotations.any?(&block)
end

#include?(obj) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/steep/ast/annotation/collection.rb', line 87

def include?(obj)
  annotations.include?(obj)
end

#lookup_const_type(node) ⇒ Object



71
72
73
# File 'lib/steep/ast/annotation/collection.rb', line 71

def lookup_const_type(node)
  const_types[node]
end

#lookup_method_type(name) ⇒ Object



67
68
69
# File 'lib/steep/ast/annotation/collection.rb', line 67

def lookup_method_type(name)
  method_types[name]&.type
end

#lookup_var_type(name) ⇒ Object



63
64
65
# File 'lib/steep/ast/annotation/collection.rb', line 63

def lookup_var_type(name)
  var_types[name]&.type
end

#sizeObject



83
84
85
# File 'lib/steep/ast/annotation/collection.rb', line 83

def size
  annotations.size
end