Class: RBS::Inline::AST::Annotations::ClassDecl

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

Overview

‘@rbs class 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) ⇒ ClassDecl

Returns a new instance of ClassDecl.



750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
# File 'lib/rbs/inline/ast/annotations.rb', line 750

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

  if super_tree = decl_tree.nth_tree(3)
    if type = super_tree.nth_type?(1)
      @super_class = translate_super_class(type)
    end
  end
end

Instance Attribute Details

#nameObject (readonly)

: TypeName?



741
742
743
# File 'lib/rbs/inline/ast/annotations.rb', line 741

def name
  @name
end

#super_classObject (readonly)

: RBS::AST::Declarations::Class::Super?



745
746
747
# File 'lib/rbs/inline/ast/annotations.rb', line 745

def super_class
  @super_class
end

#type_paramsObject (readonly)

: Array



743
744
745
# File 'lib/rbs/inline/ast/annotations.rb', line 743

def type_params
  @type_params
end