Class: PmdTester::Duplication
- Inherits:
-
Object
- Object
- PmdTester::Duplication
- Defined in:
- lib/pmdtester/parsers/cpd_report_document.rb
Overview
Represents a duplication entry in a CPD report
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#codefragment ⇒ Object
readonly
Returns the value of attribute codefragment.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#old_codefragment ⇒ Object
readonly
Returns the value of attribute old_codefragment.
-
#old_files ⇒ Object
readonly
Returns the value of attribute old_files.
-
#old_lines ⇒ Object
readonly
Returns the value of attribute old_lines.
-
#old_tokens ⇒ Object
readonly
Returns the value of attribute old_tokens.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#added? ⇒ Boolean
only makes sense if this is a diff.
-
#changed? ⇒ Boolean
only makes sense if this is a diff.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(lines:, tokens:, files:, codefragment:, branch:) ⇒ Duplication
constructor
A new instance of Duplication.
-
#removed? ⇒ Boolean
only makes sense if this is a diff.
- #try_merge?(other) ⇒ Boolean
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
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
140 141 142 |
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 140 def branch @branch end |
#codefragment ⇒ Object (readonly)
Returns the value of attribute codefragment.
140 141 142 |
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 140 def codefragment @codefragment end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
140 141 142 |
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 140 def files @files end |
#lines ⇒ Object (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_codefragment ⇒ Object (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_files ⇒ Object (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_lines ⇒ Object (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_tokens ⇒ Object (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 |
#tokens ⇒ Object (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
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
190 191 192 |
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 190 def changed? @changed end |
#eql?(other) ⇒ 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 |
#hash ⇒ Object
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
195 196 197 |
# File 'lib/pmdtester/parsers/cpd_report_document.rb', line 195 def removed? branch == BASE end |
#try_merge?(other) ⇒ 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 |