Class: RBS::Inline::AST::Annotations::SpecialVarTypeAnnotation

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

Direct Known Subclasses

DoubleSplatParamType, SplatParamType

Instance Attribute Summary collapse

Attributes inherited from Base

#source, #tree

Instance Method Summary collapse

Constructor Details

#initialize(tree, source) ⇒ SpecialVarTypeAnnotation

Returns a new instance of SpecialVarTypeAnnotation.



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/rbs/inline/ast/annotations.rb', line 170

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

  annotation = tree.nth_tree!(1)

  if name = annotation.nth_token?(1)
    @name = name[1].to_sym
  end

  if type = annotation.nth_type?(3)
    @type = type
    @type_source = type.location&.source || raise
  else
    @type = nil
    @type_source = annotation.nth_tree!(3)&.to_s || raise
  end

  if comment = annotation.nth_tree(4)
    @comment = comment.to_s
  end
end

Instance Attribute Details

#commentObject (readonly)

: String?



165
166
167
# File 'lib/rbs/inline/ast/annotations.rb', line 165

def comment
  @comment
end

#nameObject (readonly)

: Symbol?



161
162
163
# File 'lib/rbs/inline/ast/annotations.rb', line 161

def name
  @name
end

#typeObject (readonly)

: Types::t?



163
164
165
# File 'lib/rbs/inline/ast/annotations.rb', line 163

def type
  @type
end

#type_sourceObject (readonly)

: String



167
168
169
# File 'lib/rbs/inline/ast/annotations.rb', line 167

def type_source
  @type_source
end