@@ -42,9 +42,9 @@ def initialize(type:, member:, defined_in:, implemented_in:, overload_annotation
4242 @member = member
4343 @defined_in = defined_in
4444 @implemented_in = implemented_in
45- @member_annotations = member . annotations
46- @overload_annotations = overload_annotations
47- @annotations = member . annotations + overload_annotations
45+ @member_annotations = [ ]
46+ @overload_annotations = [ ]
47+ @annotations = [ ]
4848 end
4949
5050 def ==( other )
@@ -66,7 +66,10 @@ def comment
6666 end
6767
6868 def update ( type : self . type , member : self . member , defined_in : self . defined_in , implemented_in : self . implemented_in )
69- TypeDef . new ( type : type , member : member , defined_in : defined_in , implemented_in : implemented_in , overload_annotations : overload_annotations )
69+ TypeDef . new ( type : type , member : member , defined_in : defined_in , implemented_in : implemented_in ) . tap do |type_def |
70+ type_def . overload_annotations . replace ( self . overload_annotations )
71+ type_def . member_annotations . replace ( self . member_annotations )
72+ end
7073 end
7174
7275 def overload?
@@ -77,20 +80,33 @@ def overload?
7780 false
7881 end
7982 end
83+
84+ def each_annotation ( &block )
85+ if block
86+ member_annotations . each ( &block )
87+ overload_annotations . each ( &block )
88+ else
89+ enum_for :each_annotation
90+ end
91+ end
8092 end
8193
8294 attr_reader :super_method
8395 attr_reader :defs
8496 attr_reader :accessibility
8597 attr_reader :extra_annotations
98+ attr_reader :annotations
8699 attr_reader :alias_of
100+ attr_reader :alias_member
87101
88- def initialize ( super_method :, defs :, accessibility :, annotations : [ ] , alias_of :)
102+ def initialize ( super_method :, defs :, accessibility :, annotations : [ ] , alias_of :, alias_member : nil )
89103 @super_method = super_method
90104 @defs = defs
91105 @accessibility = accessibility
92106 @extra_annotations = [ ]
107+ @annotations = [ ]
93108 @alias_of = alias_of
109+ @alias_member = alias_member
94110 end
95111
96112 def ==( other )
@@ -99,7 +115,8 @@ def ==(other)
99115 other . defs == defs &&
100116 other . accessibility == accessibility &&
101117 other . annotations == annotations &&
102- other . alias_of == alias_of
118+ other . alias_of == alias_of &&
119+ other . alias_member == alias_member
103120 end
104121
105122 alias eql? ==
@@ -130,10 +147,6 @@ def comments
130147 @comments ||= defs . map ( &:comment ) . compact . uniq
131148 end
132149
133- def annotations
134- @annotations ||= defs . flat_map { |d | d . member_annotations }
135- end
136-
137150 def members
138151 @members ||= defs . map ( &:member ) . uniq
139152 end
@@ -149,49 +162,42 @@ def private?
149162 def sub ( s )
150163 return self if s . empty?
151164
152- self . class . new (
165+ update (
153166 super_method : super_method &.sub ( s ) ,
154- defs : defs . map { |defn | defn . update ( type : defn . type . sub ( s ) ) } ,
155- accessibility : @accessibility ,
156- alias_of : alias_of
167+ defs : defs . map { |defn | defn . update ( type : defn . type . sub ( s ) ) }
157168 )
158169 end
159170
160171 def map_type ( &block )
161- self . class . new (
172+ update (
162173 super_method : super_method &.map_type ( &block ) ,
163- defs : defs . map { |defn | defn . update ( type : defn . type . map_type ( &block ) ) } ,
164- accessibility : @accessibility ,
165- alias_of : alias_of
174+ defs : defs . map { |defn | defn . update ( type : defn . type . map_type ( &block ) ) }
166175 )
167176 end
168177
169178 def map_type_bound ( &block )
170- self . class . new (
179+ update (
171180 super_method : super_method &.map_type_bound ( &block ) ,
172- defs : defs . map { |defn | defn . update ( type : defn . type . map_type_bound ( &block ) ) } ,
173- accessibility : @accessibility ,
174- alias_of : alias_of
181+ defs : defs . map { |defn | defn . update ( type : defn . type . map_type_bound ( &block ) ) }
175182 )
176183 end
177184
178185 def map_method_type ( &block )
179- self . class . new (
180- super_method : super_method ,
186+ update (
181187 defs : defs . map { |defn | defn . update ( type : yield ( defn . type ) ) } ,
182- accessibility : @accessibility ,
183- alias_of : alias_of
184188 )
185189 end
186190
187- def update ( super_method : self . super_method , defs : self . defs , accessibility : self . accessibility , alias_of : self . alias_of , annotations : self . annotations )
191+ def update ( super_method : self . super_method , defs : self . defs , accessibility : self . accessibility , alias_of : self . alias_of , annotations : self . annotations , alias_member : self . alias_member )
188192 self . class . new (
189193 super_method : super_method ,
190194 defs : defs ,
191195 accessibility : accessibility ,
192196 alias_of : alias_of ,
193- annotations : annotations
194- )
197+ alias_member : alias_member
198+ ) . tap do |method |
199+ method . annotations . replace ( annotations )
200+ end
195201 end
196202 end
197203
0 commit comments