Class: RBS::Inline::AST::Annotations::ModuleDecl

Inherits:
Base
  • Object
show all
Includes:
Utils
Defined in:
lib/rbs/inline/ast/annotations.rb

Overview

‘@rbs module Foo`

Instance Attribute Summary collapse

Attributes inherited from Base

#source, #tree

Instance Method Summary collapse

Methods included from Utils

#translate_super_class, #translate_type_name, #translate_type_param

Constructor Details

#initialize(tree, comments) ⇒ ModuleDecl

Returns a new instance of ModuleDecl.



695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
# File 'lib/rbs/inline/ast/annotations.rb', line 695

def initialize(tree, comments)
  @tree = tree
  @source = comments

  decl_tree = tree.nth_tree!(1)

  if type_name = translate_type_name(decl_tree.nth_tree!(1))
    if type_name.class?
      @name = type_name
    end
  end

  @type_params = []
  if type_params = decl_tree.nth_tree(2)
    params = type_params.non_trivia_trees
    params.shift
    params.pop
    params.each_slice(2) do |param, _comma|
      raise unless param.is_a?(Tree)
      if type_param = translate_type_param(param)
        @type_params << type_param
      end
    end
  end

  @self_types = []
  if selfs_tree = decl_tree.nth_tree(3)
    self_trees = selfs_tree.non_trivia_trees
    self_trees.shift

    self_trees.each_slice(2) do |type, _comma|
      case type
      when Types::ClassInstance, Types::Interface
        @self_types << RBS::AST::Declarations::Module::Self.new(
          name: type.name,
          args: type.args,
          location: type.location
        )
      end
    end
  end
end

Instance Attribute Details

#nameObject (readonly)

: TypeName?



686
687
688
# File 'lib/rbs/inline/ast/annotations.rb', line 686

def name
  @name
end

#self_typesObject (readonly)

: Array



690
691
692
# File 'lib/rbs/inline/ast/annotations.rb', line 690

def self_types
  @self_types
end

#type_paramsObject (readonly)

: Array



688
689
690
# File 'lib/rbs/inline/ast/annotations.rb', line 688

def type_params
  @type_params
end