@@ -203,7 +203,14 @@ def location_for(iseq)
203
203
end
204
204
205
205
def find_constant_path ( insns , index )
206
- index -= 1 while index >= 0 && ( insns [ index ] . is_a? ( Integer ) || ( insns [ index ] . is_a? ( Array ) && %i[ swap topn ] . include? ( insns [ index ] [ 0 ] ) ) )
206
+ index -= 1 while index >= 0 &&
207
+ (
208
+ insns [ index ] . is_a? ( Integer ) ||
209
+ (
210
+ insns [ index ] . is_a? ( Array ) &&
211
+ %i[ swap topn ] . include? ( insns [ index ] [ 0 ] )
212
+ )
213
+ )
207
214
insn = insns [ index ]
208
215
209
216
if insn . is_a? ( Array ) && insn [ 0 ] == :opt_getconstant_path
@@ -252,7 +259,12 @@ def method_definition(nesting, name, location, file_comments)
252
259
comments = EntryComments . new ( file_comments , location )
253
260
254
261
if nesting . last == [ :singletonclass ]
255
- SingletonMethodDefinition . new ( nesting [ 0 ...-1 ] , name , location , comments )
262
+ SingletonMethodDefinition . new (
263
+ nesting [ 0 ...-1 ] ,
264
+ name ,
265
+ location ,
266
+ comments
267
+ )
256
268
else
257
269
MethodDefinition . new ( nesting , name , location , comments )
258
270
end
@@ -341,7 +353,12 @@ def index_iseq(iseq, file_comments)
341
353
queue << [ class_iseq , next_nesting ]
342
354
when :definemethod
343
355
location = location_for ( insn [ 2 ] )
344
- results << method_definition ( current_nesting , insn [ 1 ] , location , file_comments )
356
+ results << method_definition (
357
+ current_nesting ,
358
+ insn [ 1 ] ,
359
+ location ,
360
+ file_comments
361
+ )
345
362
when :definesmethod
346
363
if insns [ index - 1 ] != [ :putself ]
347
364
warn ( "singleton method with non-self receiver" )
@@ -378,19 +395,35 @@ def index_iseq(iseq, file_comments)
378
395
location = Location . new ( line , :unknown )
379
396
names . each do |name |
380
397
if insn [ 1 ] [ :mid ] != :attr_writer
381
- results << method_definition ( current_nesting , name , location , file_comments )
398
+ results << method_definition (
399
+ current_nesting ,
400
+ name ,
401
+ location ,
402
+ file_comments
403
+ )
382
404
end
383
405
384
406
if insn [ 1 ] [ :mid ] != :attr_reader
385
- results << method_definition ( current_nesting , :"#{ name } =" , location , file_comments )
407
+ results << method_definition (
408
+ current_nesting ,
409
+ :"#{ name } =" ,
410
+ location ,
411
+ file_comments
412
+ )
386
413
end
387
414
end
388
415
when :"core#set_method_alias"
389
416
# Now we have to validate that the alias is happening with a
390
417
# non-interpolated value. To do this we'll match the specific
391
418
# pattern we're expecting.
392
- values = insns [ ( index - 4 ) ...index ] . map { |insn | insn . is_a? ( Array ) ? insn [ 0 ] : insn }
393
- next if values != %i[ putspecialobject putspecialobject putobject putobject ]
419
+ values =
420
+ insns [ ( index - 4 ) ...index ] . map do |insn |
421
+ insn . is_a? ( Array ) ? insn [ 0 ] : insn
422
+ end
423
+ if values !=
424
+ %i[ putspecialobject putspecialobject putobject putobject ]
425
+ next
426
+ end
394
427
395
428
# Now that we know it's in the structure we want it, we can use
396
429
# the values of the putobject to determine the alias.
@@ -441,7 +474,10 @@ def initialize
441
474
def visit_alias ( node )
442
475
if node . left . is_a? ( SymbolLiteral ) && node . right . is_a? ( SymbolLiteral )
443
476
location =
444
- Location . new ( node . location . start_line , node . location . start_column )
477
+ Location . new (
478
+ node . location . start_line ,
479
+ node . location . start_column
480
+ )
445
481
446
482
results << AliasMethodDefinition . new (
447
483
nesting . dup ,
@@ -457,7 +493,10 @@ def visit_alias(node)
457
493
def visit_assign ( node )
458
494
if node . target . is_a? ( VarField ) && node . target . value . is_a? ( Const )
459
495
location =
460
- Location . new ( node . location . start_line , node . location . start_column )
496
+ Location . new (
497
+ node . location . start_line ,
498
+ node . location . start_column
499
+ )
461
500
462
501
results << ConstantDefinition . new (
463
502
nesting . dup ,
@@ -507,18 +546,31 @@ def visit_command(node)
507
546
when "attr_reader" , "attr_writer" , "attr_accessor"
508
547
comments = comments_for ( node )
509
548
location =
510
- Location . new ( node . location . start_line , node . location . start_column )
549
+ Location . new (
550
+ node . location . start_line ,
551
+ node . location . start_column
552
+ )
511
553
512
554
node . arguments . parts . each do |argument |
513
555
next unless argument . is_a? ( SymbolLiteral )
514
556
name = argument . value . value . to_sym
515
557
516
558
if node . message . value != "attr_writer"
517
- results << MethodDefinition . new ( nesting . dup , name , location , comments )
559
+ results << MethodDefinition . new (
560
+ nesting . dup ,
561
+ name ,
562
+ location ,
563
+ comments
564
+ )
518
565
end
519
566
520
567
if node . message . value != "attr_reader"
521
- results << MethodDefinition . new ( nesting . dup , :"#{ name } =" , location , comments )
568
+ results << MethodDefinition . new (
569
+ nesting . dup ,
570
+ :"#{ name } =" ,
571
+ location ,
572
+ comments
573
+ )
522
574
end
523
575
end
524
576
end
0 commit comments