class RBS::Location - rbs: Ruby Standard Library Documentation

# class RBS::Location

### Constants

WithChildren

### Public Class Methods

new(buffer_ = nil, start_pos_ = nil, end_pos_ = nil, buffer: nil, start_pos: nil, end_pos: nil) click to toggle source
Calls superclass method

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 16
    def self.new(buffer_ = nil, start_pos_ = nil, end_pos_ = nil, buffer: nil, start_pos: nil, end_pos: nil)
      __skip__ =
        begin
          if buffer && start_pos && end_pos
            super(buffer, start_pos, end_pos)
          else
            super(buffer_, start_pos_, end_pos_)
          end
        end
    end

to_string(location, default: "*:*:*...*:*") click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 94
    def self.to_string(location, default: "*:*:*...*:*")
      location&.to_s || default
    end

### Public Instance Methods

==(other) click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 71
    def ==(other)
      other.is_a?(Location) &&
        other.buffer == buffer &&
        other.start_pos == start_pos &&
        other.end_pos == end_pos
    end

add_optional_child(name, range) click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 102
    def add_optional_child(name, range)
      if range
        _add_optional_child(name, range.begin, range.end)
      else
        _add_optional_no_child(name);
      end
    end

add_required_child(name, range) click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 98
    def add_required_child(name, range)
      _add_required_child(name, range.begin, range.end)
    end

each_optional_key(&block) click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 110
    def each_optional_key(&block)
      if block
        _optional_keys.uniq.each(&block)
      else
        enum_for(:each_optional_key)
      end
    end

each_required_key(&block) click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 118
    def each_required_key(&block)
      if block
        _required_keys.uniq.each(&block)
      else
        enum_for(:each_required_key)
      end
    end

end_column() click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 47
    def end_column
      end_loc[1]
    end

end_line() click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 43
    def end_line
      end_loc[0]
    end

end_loc() click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 55
    def end_loc
      @end_loc ||= buffer.pos_to_loc(end_pos)
    end

inspect() click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 5
    def inspect
      rks = each_required_key.to_a
      ops = each_optional_key.to_a.map {|x| "?#{x}" }
      src = if source.length <= 1
        source.inspect
      else
        source.each_line.first&.chomp&.inspect
      end
      "#<#{self.class}:#{self.__id__} buffer=#{buffer.name}, start=#{start_line}:#{start_column}, pos=#{start_pos}...#{end_pos}, children=#{(rks + ops).join(",")} source=#{src}>"
    end

key?(name) click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 126
    def key?(name)
      optional_key?(name) || required_key?(name)
    end

name() click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 31
    def name
      buffer.name
    end

optional_key?(name) click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 130
    def optional_key?(name)
      _optional_keys.include?(name)
    end

range() click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 59
    def range
      @range ||= start_pos...end_pos
    end

required_key?(name) click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 134
    def required_key?(name)
      _required_keys.include?(name)
    end

source() click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 63
    def source
      @source ||= (buffer.content[range] || raise)
    end

start_column() click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 39
    def start_column
      start_loc[1]
    end

start_line() click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 35
    def start_line
      start_loc[0]
    end

start_loc() click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 51
    def start_loc
      @start_loc ||= buffer.pos_to_loc(start_pos)
    end

to_json(state = _ = nil) click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 78
    def to_json(state = _ = nil)
      {
        start: {
          line: start_line,
          column: start_column
        },
        end: {
          line: end_line,
          column: end_column
        },
        buffer: {
          name: name&.to_s
        }
      }.to_json(state)
    end

to_s() click to toggle source

    # File rbs-3.8.0/lib/rbs/location_aux.rb, line 67
    def to_s
      "#{name || "-"}:#{start_line}:#{start_column}...#{end_line}:#{end_column}"
    end