Class: AdLint::Location

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/adlint/location.rb

Overview

DESCRIPTION

Location identifier of tokens.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fpath = nil, line_no = nil, column_no = nil, appearance_column_no = column_no) ⇒ Location

Constructs a location identifier.

Param

fpath (Pathname) Path name of the file contains the token.

Param

line_no (Integer) Line-no where the token appears.

Param

column_no (Integer) Column-no where the token appears.



44
45
46
47
48
# File 'lib/adlint/location.rb', line 44

def initialize(fpath = nil, line_no = nil, column_no = nil,
               appearance_column_no = column_no)
  @fpath, @line_no, @column_no = fpath, line_no, column_no
  @appearance_column_no = appearance_column_no
end

Instance Attribute Details

#appearance_column_noObject (readonly)

Returns the value of attribute appearance_column_no.



62
63
64
# File 'lib/adlint/location.rb', line 62

def appearance_column_no
  @appearance_column_no
end

#column_noObject (readonly)

VALUE

Integer – Column-no where this token appears.



60
61
62
# File 'lib/adlint/location.rb', line 60

def column_no
  @column_no
end

#fpathObject (readonly)

VALUE

Pathname – Path name of the file contains this token.



52
53
54
# File 'lib/adlint/location.rb', line 52

def fpath
  @fpath
end

#line_noObject (readonly)

VALUE

Integer – Line-no where this token appears.



56
57
58
# File 'lib/adlint/location.rb', line 56

def line_no
  @line_no
end

Instance Method Details

#<=>(rhs) ⇒ Object



81
82
83
# File 'lib/adlint/location.rb', line 81

def <=>(rhs)
  self.to_a <=> rhs.to_a
end

#eql?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/adlint/location.rb', line 85

def eql?(rhs)
  self == rhs
end

#hashObject



89
90
91
# File 'lib/adlint/location.rb', line 89

def hash
  to_a.hash
end

#in_analysis_target?(traits) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
73
# File 'lib/adlint/location.rb', line 64

def in_analysis_target?(traits)
  if @fpath
    under_inclusion_paths?(@fpath, traits) &&
      !under_exclusion_paths?(@fpath, traits) and
    !@fpath.identical?(traits.of_project.initial_header) &&
      !@fpath.identical?(traits.of_compiler.initial_header)
  else
    false
  end
end

#inspectObject

DESCRIPTION

Converts this location to debugging dump representation.

RETURN VALUE

String – String representation of this location identifier.



116
117
118
119
# File 'lib/adlint/location.rb', line 116

def inspect
  "#{@fpath ? @fpath : 'nil'}:" +
    "#{@line_no ? @line_no : 'nil'}:#{@column_no ? @column_no : 'nil'}"
end

#to_aObject

DESCRIPTION

Converts this location identifier to an array representation.

RETURN VALUE

Array< Object > – Array representation of this location identifier.



98
99
100
# File 'lib/adlint/location.rb', line 98

def to_a
  [@fpath, @line_no, @column_no]
end

#to_sObject

DESCRIPTION

Converts this location to a human readable string representation.

RETURN VALUE

String – String representation of this location identifier.



107
108
109
# File 'lib/adlint/location.rb', line 107

def to_s
  "#{@fpath}:#{@line_no}:#{@column_no}"
end