Class: BaseType

Inherits:
Object
  • Object
show all
Includes:
RubyToken
Defined in:
lib/kwala/lib/code_analyzer.rb

Direct Known Subclasses

ClassType, DefType, ModuleType

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tokens = Array.new) ⇒ BaseType

Returns a new instance of BaseType.



474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/kwala/lib/code_analyzer.rb', line 474

def initialize(tokens = Array.new)
  @children = Array.new

  # These may be computed by tokens?
  @start_line = 0
  @end_line = 0
  @tokens = tokens
  @rem_tokens = []

  create_child_groupings
  analyse_self
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



472
473
474
# File 'lib/kwala/lib/code_analyzer.rb', line 472

def children
  @children
end

#end_lineObject

Returns the value of attribute end_line.



472
473
474
# File 'lib/kwala/lib/code_analyzer.rb', line 472

def end_line
  @end_line
end

#nameObject

Returns the value of attribute name.



472
473
474
# File 'lib/kwala/lib/code_analyzer.rb', line 472

def name
  @name
end

#start_lineObject

Returns the value of attribute start_line.



472
473
474
# File 'lib/kwala/lib/code_analyzer.rb', line 472

def start_line
  @start_line
end

#tokensObject

Returns the value of attribute tokens.



472
473
474
# File 'lib/kwala/lib/code_analyzer.rb', line 472

def tokens
  @tokens
end

Class Method Details

.create_types_from_tokens(tokens) ⇒ Object



492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
# File 'lib/kwala/lib/code_analyzer.rb', line 492

def self.create_types_from_tokens(tokens)
  groups, idx = group_tokens(tokens, [TkCLASS, TkMODULE, TkDEF])


  remainder_tokens = []
  types = []

  groups.each do |sub_tokens|

      case sub_tokens.first
      when TkCLASS
        types<< ClassType.new(sub_tokens)
      when TkMODULE
        types<< ModuleType.new(sub_tokens)
      when TkDEF
        types<< DefType.new(sub_tokens)
      else
        remainder_tokens<< sub_tokens
      end

  end

  [types, remainder_tokens]
end

Instance Method Details

#sub_typesObject



487
488
489
# File 'lib/kwala/lib/code_analyzer.rb', line 487

def sub_types
  @children.each { |c| yield c }
end