Class: RBS::Inline::AST::Declarations::ClassDecl

Inherits:
ModuleOrClass show all
Includes:
ConstantUtil
Defined in:
lib/rbs/inline/ast/declarations.rb

Overview

Prism::ClassNode

Instance Attribute Summary collapse

Attributes inherited from ModuleOrClass

#comments, #members, #node

Instance Method Summary collapse

Methods included from ConstantUtil

#type_name, #value_node

Methods inherited from ModuleOrClass

#start_line, #type_params

Constructor Details

#initialize(node, comments, super_app) ⇒ ClassDecl

Returns a new instance of ClassDecl.



103
104
105
106
107
# File 'lib/rbs/inline/ast/declarations.rb', line 103

def initialize(node, comments, super_app)
  super(node, comments)

  @super_app = super_app
end

Instance Attribute Details

#super_appObject (readonly)

Type application for super class



97
98
99
# File 'lib/rbs/inline/ast/declarations.rb', line 97

def super_app
  @super_app
end

Instance Method Details

#class_nameObject



110
111
112
# File 'lib/rbs/inline/ast/declarations.rb', line 110

def class_name #: TypeName?
  type_name(node.constant_path)
end

#super_classObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/rbs/inline/ast/declarations.rb', line 115

def super_class #: RBS::AST::Declarations::Class::Super?
  if comments
    if inherits = comments.each_annotation.find {|a| a.is_a?(Annotations::Inherits) } #: Annotations::Inherits?
      super_name = inherits.super_name
      super_args = inherits.args

      if super_name && super_args
        return RBS::AST::Declarations::Class::Super.new(
          name: super_name,
          args: super_args,
          location: nil
        )
      end
    end
  end

  if node.superclass
    super_name = nil #: TypeName?
    super_args = nil #: Array[Types::t]?

    if super_app
      super_args = super_app.types
    end

    super_name = type_name(node.superclass)

    if super_name
      return RBS::AST::Declarations::Class::Super.new(
        name: super_name,
        args: super_args || [],
        location: nil
      )
    end
  end
end