class BugInstance

Represent a BugInstance.

Constants

RANK_ERROR_THRESHOLD

Attributes

absolute_path[R]
bug_instance[RW]
relative_path[R]
source_dirs[RW]

Public Class Methods

new(prefix, source_dirs, bug_instance) click to toggle source
# File lib/spotbugs/entity/bug_instance.rb, line 9
def initialize(prefix, source_dirs, bug_instance)
  @source_dirs = source_dirs
  @bug_instance = bug_instance

  source_path = get_source_path(bug_instance)
  @absolute_path = get_absolute_path(source_path)

  prefix += (prefix.end_with?(file_separator) ? '' : file_separator)
  @relative_path = get_relative_path(prefix, @absolute_path)
end

Public Instance Methods

description() click to toggle source
# File lib/spotbugs/entity/bug_instance.rb, line 32
def description
  @description ||= bug_instance.xpath('LongMessage').text
end
line() click to toggle source
# File lib/spotbugs/entity/bug_instance.rb, line 28
def line
  @line ||= get_value_safely(bug_instance.xpath('SourceLine').attribute('start'), 0).to_i
end
rank() click to toggle source
# File lib/spotbugs/entity/bug_instance.rb, line 20
def rank
  @rank ||= bug_instance.attribute('rank').value.to_i
end
type() click to toggle source
# File lib/spotbugs/entity/bug_instance.rb, line 24
def type
  @type ||= rank > RANK_ERROR_THRESHOLD ? :warn : :fail
end

Private Instance Methods

file_separator() click to toggle source
# File lib/spotbugs/entity/bug_instance.rb, line 56
def file_separator
  File::ALT_SEPARATOR || File::SEPARATOR
end
get_absolute_path(source_path) click to toggle source
# File lib/spotbugs/entity/bug_instance.rb, line 42
def get_absolute_path(source_path)
  @source_dirs.map do |source_dir|
    return source_dir if source_dir.end_with?(source_path)
  end
end
get_relative_path(prefix, absolute_path) click to toggle source
# File lib/spotbugs/entity/bug_instance.rb, line 48
def get_relative_path(prefix, absolute_path)
  if absolute_path.start_with?(prefix)
    absolute_path[prefix.length, absolute_path.length - prefix.length]
  else
    absolute_path
  end
end
get_source_path(bug_instance) click to toggle source
# File lib/spotbugs/entity/bug_instance.rb, line 38
def get_source_path(bug_instance)
  get_value_safely(bug_instance.xpath('SourceLine').attribute('sourcepath'), '').to_s
end
get_value_safely(array, default_value) click to toggle source
# File lib/spotbugs/entity/bug_instance.rb, line 60
def get_value_safely(array, default_value)
  array.compact.empty? ? default_value : array.compact.first.value
end