Class: Steep::AST::Annotation::Collection
- Inherits:
-
Object
- Object
- Steep::AST::Annotation::Collection
- Defined in:
- lib/steep/ast/annotation/collection.rb
Instance Attribute Summary collapse
-
#annotations ⇒ Object
readonly
Returns the value of attribute annotations.
-
#block_type_annotation ⇒ Object
readonly
Returns the value of attribute block_type_annotation.
-
#break_type_annotation ⇒ Object
readonly
Returns the value of attribute break_type_annotation.
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#const_type_annotations ⇒ Object
readonly
Returns the value of attribute const_type_annotations.
-
#current_module ⇒ Object
readonly
Returns the value of attribute current_module.
-
#dynamic_annotations ⇒ Object
readonly
Returns the value of attribute dynamic_annotations.
-
#implement_module_annotation ⇒ Object
readonly
Returns the value of attribute implement_module_annotation.
-
#instance_type_annotation ⇒ Object
readonly
Returns the value of attribute instance_type_annotation.
-
#ivar_type_annotations ⇒ Object
readonly
Returns the value of attribute ivar_type_annotations.
-
#method_type_annotations ⇒ Object
readonly
Returns the value of attribute method_type_annotations.
-
#module_type_annotation ⇒ Object
readonly
Returns the value of attribute module_type_annotation.
-
#return_type_annotation ⇒ Object
readonly
Returns the value of attribute return_type_annotation.
-
#self_type_annotation ⇒ Object
readonly
Returns the value of attribute self_type_annotation.
-
#var_type_annotations ⇒ Object
readonly
Returns the value of attribute var_type_annotations.
Instance Method Summary collapse
- #absolute_type(type) ⇒ Object
- #any?(&block) ⇒ Boolean
- #block_type ⇒ Object
- #break_type ⇒ Object
- #const_types ⇒ Object
- #include?(obj) ⇒ Boolean
-
#initialize(annotations:, builder:, current_module:) ⇒ Collection
constructor
A new instance of Collection.
- #instance_dynamics ⇒ Object
- #instance_type ⇒ Object
- #ivar_types ⇒ Object
- #lvar_types ⇒ Object
- #merge_block_annotations(annotations) ⇒ Object
- #method_type(name) ⇒ Object
- #module_dynamics ⇒ Object
- #module_type ⇒ Object
- #return_type ⇒ Object
- #self_type ⇒ Object
- #size ⇒ Object
- #var_type(lvar: nil, ivar: nil, const: nil) ⇒ Object
Constructor Details
#initialize(annotations:, builder:, current_module:) ⇒ Collection
Returns a new instance of Collection.
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 62 63 |
# File 'lib/steep/ast/annotation/collection.rb', line 22 def initialize(annotations:, builder:, current_module:) @annotations = annotations @builder = builder @current_module = current_module @var_type_annotations = {} @method_type_annotations = {} @const_type_annotations = {} @ivar_type_annotations = {} @dynamic_annotations = [] annotations.each do |annotation| case annotation when VarType var_type_annotations[annotation.name] = annotation when MethodType method_type_annotations[annotation.name] = annotation when BlockType @block_type_annotation = annotation when ReturnType @return_type_annotation = annotation when SelfType @self_type_annotation = annotation when ConstType @const_type_annotations[annotation.name] = annotation when InstanceType @instance_type_annotation = annotation when ModuleType @module_type_annotation = annotation when Implements @implement_module_annotation = annotation when IvarType @ivar_type_annotations[annotation.name] = annotation when Dynamic @dynamic_annotations << annotation when BreakType @break_type_annotation = annotation else raise "Unexpected annotation: #{annotation.inspect}" end end end |
Instance Attribute Details
#annotations ⇒ Object (readonly)
Returns the value of attribute annotations.
5 6 7 |
# File 'lib/steep/ast/annotation/collection.rb', line 5 def annotations @annotations end |
#block_type_annotation ⇒ Object (readonly)
Returns the value of attribute block_type_annotation.
13 14 15 |
# File 'lib/steep/ast/annotation/collection.rb', line 13 def block_type_annotation @block_type_annotation end |
#break_type_annotation ⇒ Object (readonly)
Returns the value of attribute break_type_annotation.
20 21 22 |
# File 'lib/steep/ast/annotation/collection.rb', line 20 def break_type_annotation @break_type_annotation end |
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
6 7 8 |
# File 'lib/steep/ast/annotation/collection.rb', line 6 def builder @builder end |
#const_type_annotations ⇒ Object (readonly)
Returns the value of attribute const_type_annotations.
10 11 12 |
# File 'lib/steep/ast/annotation/collection.rb', line 10 def const_type_annotations @const_type_annotations end |
#current_module ⇒ Object (readonly)
Returns the value of attribute current_module.
7 8 9 |
# File 'lib/steep/ast/annotation/collection.rb', line 7 def current_module @current_module end |
#dynamic_annotations ⇒ Object (readonly)
Returns the value of attribute dynamic_annotations.
19 20 21 |
# File 'lib/steep/ast/annotation/collection.rb', line 19 def dynamic_annotations @dynamic_annotations end |
#implement_module_annotation ⇒ Object (readonly)
Returns the value of attribute implement_module_annotation.
18 19 20 |
# File 'lib/steep/ast/annotation/collection.rb', line 18 def implement_module_annotation @implement_module_annotation end |
#instance_type_annotation ⇒ Object (readonly)
Returns the value of attribute instance_type_annotation.
16 17 18 |
# File 'lib/steep/ast/annotation/collection.rb', line 16 def instance_type_annotation @instance_type_annotation end |
#ivar_type_annotations ⇒ Object (readonly)
Returns the value of attribute ivar_type_annotations.
11 12 13 |
# File 'lib/steep/ast/annotation/collection.rb', line 11 def ivar_type_annotations @ivar_type_annotations end |
#method_type_annotations ⇒ Object (readonly)
Returns the value of attribute method_type_annotations.
12 13 14 |
# File 'lib/steep/ast/annotation/collection.rb', line 12 def method_type_annotations @method_type_annotations end |
#module_type_annotation ⇒ Object (readonly)
Returns the value of attribute module_type_annotation.
17 18 19 |
# File 'lib/steep/ast/annotation/collection.rb', line 17 def module_type_annotation @module_type_annotation end |
#return_type_annotation ⇒ Object (readonly)
Returns the value of attribute return_type_annotation.
14 15 16 |
# File 'lib/steep/ast/annotation/collection.rb', line 14 def return_type_annotation @return_type_annotation end |
#self_type_annotation ⇒ Object (readonly)
Returns the value of attribute self_type_annotation.
15 16 17 |
# File 'lib/steep/ast/annotation/collection.rb', line 15 def self_type_annotation @self_type_annotation end |
#var_type_annotations ⇒ Object (readonly)
Returns the value of attribute var_type_annotations.
9 10 11 |
# File 'lib/steep/ast/annotation/collection.rb', line 9 def var_type_annotations @var_type_annotations end |
Instance Method Details
#absolute_type(type) ⇒ Object
65 66 67 68 69 |
# File 'lib/steep/ast/annotation/collection.rb', line 65 def absolute_type(type) if type builder.absolute_type(type, current: current_module) end end |
#any?(&block) ⇒ Boolean
156 157 158 |
# File 'lib/steep/ast/annotation/collection.rb', line 156 def any?(&block) annotations.any?(&block) end |
#block_type ⇒ Object
88 89 90 |
# File 'lib/steep/ast/annotation/collection.rb', line 88 def block_type absolute_type(block_type_annotation&.type) end |
#break_type ⇒ Object
108 109 110 |
# File 'lib/steep/ast/annotation/collection.rb', line 108 def break_type absolute_type(break_type_annotation&.type) end |
#const_types ⇒ Object
124 125 126 127 128 |
# File 'lib/steep/ast/annotation/collection.rb', line 124 def const_types const_type_annotations.each_key.with_object({}) do |name, hash| hash[name] = var_type(const: name) end end |
#include?(obj) ⇒ Boolean
164 165 166 |
# File 'lib/steep/ast/annotation/collection.rb', line 164 def include?(obj) annotations.include?(obj) end |
#instance_dynamics ⇒ Object
130 131 132 133 134 |
# File 'lib/steep/ast/annotation/collection.rb', line 130 def instance_dynamics dynamic_annotations.flat_map do |annot| annot.names.select(&:instance_method?).map(&:name) end end |
#instance_type ⇒ Object
100 101 102 |
# File 'lib/steep/ast/annotation/collection.rb', line 100 def instance_type absolute_type(instance_type_annotation&.type) end |
#ivar_types ⇒ Object
118 119 120 121 122 |
# File 'lib/steep/ast/annotation/collection.rb', line 118 def ivar_types ivar_type_annotations.each_key.with_object({}) do |name, hash| hash[name] = var_type(ivar: name) end end |
#lvar_types ⇒ Object
112 113 114 115 116 |
# File 'lib/steep/ast/annotation/collection.rb', line 112 def lvar_types var_type_annotations.each_key.with_object({}) do |name, hash| hash[name] = var_type(lvar: name) end end |
#merge_block_annotations(annotations) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/steep/ast/annotation/collection.rb', line 142 def merge_block_annotations(annotations) if annotations.current_module != current_module || annotations.builder != builder raise "Cannot merge another annotation: self=#{self}, other=#{annotations}" end retained_annotations = self.annotations.reject do |annotation| annotation.is_a?(BlockType) || annotation.is_a?(BreakType) end self.class.new(annotations: retained_annotations + annotations.annotations, builder: builder, current_module: current_module) end |
#method_type(name) ⇒ Object
82 83 84 85 86 |
# File 'lib/steep/ast/annotation/collection.rb', line 82 def method_type(name) if (a = method_type_annotations[name]) builder.method_type_to_method_type(a.type, current: current_module) end end |
#module_dynamics ⇒ Object
136 137 138 139 140 |
# File 'lib/steep/ast/annotation/collection.rb', line 136 def module_dynamics dynamic_annotations.flat_map do |annot| annot.names.select(&:module_method?).map(&:name) end end |
#module_type ⇒ Object
104 105 106 |
# File 'lib/steep/ast/annotation/collection.rb', line 104 def module_type absolute_type(module_type_annotation&.type) end |
#return_type ⇒ Object
92 93 94 |
# File 'lib/steep/ast/annotation/collection.rb', line 92 def return_type absolute_type(return_type_annotation&.type) end |
#self_type ⇒ Object
96 97 98 |
# File 'lib/steep/ast/annotation/collection.rb', line 96 def self_type absolute_type(self_type_annotation&.type) end |
#size ⇒ Object
160 161 162 |
# File 'lib/steep/ast/annotation/collection.rb', line 160 def size annotations.size end |
#var_type(lvar: nil, ivar: nil, const: nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/steep/ast/annotation/collection.rb', line 71 def var_type(lvar: nil, ivar: nil, const: nil) case when lvar absolute_type(var_type_annotations[lvar]&.type) when ivar absolute_type(ivar_type_annotations[ivar]&.type) when const absolute_type(const_type_annotations[const]&.type) end end |