Class: PmdTester::Duplication

Inherits:
Object
  • Object
show all
Defined in:
lib/pmdtester/parsers/cpd_report_document.rb

Overview

Represents a duplication entry in a CPD report

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines:, tokens:, files:, codefragment:, branch:) ⇒ Duplication

Returns a new instance of Duplication.



142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 142

def initialize(lines:, tokens:, files:, codefragment:, branch:)
  @lines = lines
  @tokens = tokens
  @files = files
  @codefragment = codefragment
  @branch = branch

  @changed = false
  @old_lines = nil
  @old_tokens = nil
  @old_files = nil
  @old_codefragment = nil
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



140
141
142
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 140

def branch
  @branch
end

#codefragmentObject (readonly)

Returns the value of attribute codefragment.



140
141
142
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 140

def codefragment
  @codefragment
end

#filesObject (readonly)

Returns the value of attribute files.



140
141
142
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 140

def files
  @files
end

#linesObject (readonly)

Returns the value of attribute lines.



140
141
142
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 140

def lines
  @lines
end

#old_codefragmentObject (readonly)

Returns the value of attribute old_codefragment.



140
141
142
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 140

def old_codefragment
  @old_codefragment
end

#old_filesObject (readonly)

Returns the value of attribute old_files.



140
141
142
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 140

def old_files
  @old_files
end

#old_linesObject (readonly)

Returns the value of attribute old_lines.



140
141
142
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 140

def old_lines
  @old_lines
end

#old_tokensObject (readonly)

Returns the value of attribute old_tokens.



140
141
142
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 140

def old_tokens
  @old_tokens
end

#tokensObject (readonly)

Returns the value of attribute tokens.



140
141
142
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 140

def tokens
  @tokens
end

Instance Method Details

#added?Boolean

only makes sense if this is a diff

Returns:

  • (Boolean)


185
186
187
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 185

def added?
  branch != BASE && !changed?
end

#changed?Boolean

only makes sense if this is a diff

Returns:

  • (Boolean)


190
191
192
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 190

def changed?
  @changed
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


156
157
158
159
160
161
162
163
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 156

def eql?(other)
  return false unless other.is_a?(Duplication)

  lines == other.lines &&
    tokens == other.tokens &&
    files.eql?(other.files) &&
    codefragment == other.codefragment
end

#hashObject



165
166
167
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 165

def hash
  [lines, tokens, files, codefragment].hash
end

#removed?Boolean

only makes sense if this is a diff

Returns:

  • (Boolean)


195
196
197
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 195

def removed?
  branch == BASE
end

#try_merge?(other) ⇒ Boolean

Returns:

  • (Boolean)


169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 169

def try_merge?(other)
  if branch != BASE && branch != other.branch &&
     !changed? && # not already changed
     same_or_similar_locations?(other.files)
    @changed = true
    @old_lines = other.lines
    @old_tokens = other.tokens
    @old_files = other.files
    @old_codefragment = other.codefragment
    true
  else
    false
  end
end