coalib.results package¶
Subpackages¶
Submodules¶
coalib.results.Diff module¶
-
class
coalib.results.Diff.
Diff
(file_list)¶ Bases:
object
A Diff result represents a difference for one file.
-
add_lines
(line_nr_before, lines)¶ Adds lines after the given line number.
Parameters: - line_nr_before – Line number of the line before the additions. Use 0 for insert lines before everything.
- lines – A list of lines to add.
-
affected_code
(filename)¶ Creates a list of SourceRange objects which point to the related code. Changes on continuous lines will be put into one SourceRange.
Parameters: filename – The filename to associate the SourceRange’s to. Returns: A list of all related SourceRange objects.
-
change_line
(line_nr, original_line, replacement)¶ Changes the given line with the given line number. The replacement will be there instead.
-
delete_line
(line_nr)¶ Mark the given line nr as deleted. The first line is line number 1.
-
classmethod
from_clang_fixit
(fixit, file)¶ Creates a Diff object from a given clang fixit and the file contents.
Parameters: - fixit – A cindex.Fixit object.
- file – A list of lines in the file to apply the fixit to.
Returns: The corresponding Diff object.
-
classmethod
from_string_arrays
(file_array_1, file_array_2)¶ Creates a Diff object from two arrays containing strings.
If this Diff is applied to the original array, the second array will be created.
Parameters: - file_array_1 – Original array
- file_array_2 – Array to compare
-
modified
¶ Calculates the modified file, after applying the Diff to the original.
-
original
¶ Retrieves the original file.
-
range
(filename)¶ Calculates a SourceRange spanning over the whole Diff. If something is added after the 0th line (i.e. before the first line) the first line will be included in the SourceRange.
Parameters: filename – The filename to associate the SourceRange with. Returns: A SourceRange object.
-
split_diff
()¶ Splits this diff into small pieces, such that several continuously altered lines are still together in one diff. All subdiffs will be yielded.
-
unified_diff
¶ Generates a unified diff corresponding to this patch.
Note that the unified diff is not deterministic and thus not suitable for equality comparison.
-
coalib.results.HiddenResult module¶
-
class
coalib.results.HiddenResult.
HiddenResult
(origin, contents)¶ Bases:
coalib.results.Result.Result
This is a result that is not meant to be shown to the user. It can be used to transfer any data from a dependent bear to others.
coalib.results.RESULT_SEVERITY module¶
coalib.results.Result module¶
-
class
coalib.results.Result.
Result
(*args, **kwargs)¶ Bases:
object
A result is anything that has an origin and a message.
Optionally it might affect a file.
-
apply
(*args, **kwargs)¶
-
classmethod
from_values
(*args, **kwargs)¶
-
location_repr
()¶ Retrieves a string, that briefly represents the affected code of the result.
Returns: A string containing all of the affected files seperated by a comma.
-
overlaps
(ranges)¶ Determines if the result overlaps with source ranges provided.
Parameters: ranges – A list SourceRange objects to check for overlap. Returns: True if the ranges overlap with the result.
-
to_string_dict
()¶ Makes a dictionary which has all keys and values as strings and contains all the data that the base Result has.
FIXME: diffs are not serialized ATM. FIXME: Only the first SourceRange of affected_code is serialized. If there are more, this data is currently missing.
Returns: Dictionary with keys and values as string.
-
coalib.results.ResultFilter module¶
-
coalib.results.ResultFilter.
basics_match
(original_result, modified_result)¶ Checks whether the following properties of two results match: * origin * message * severity * debug_msg
Parameters: - original_result – A result of the old files
- modified_result – A result of the new files
Returns: Boolean value whether or not the properties match
-
coalib.results.ResultFilter.
filter_results
(original_file_dict, modified_file_dict, original_results, modified_results)¶ Filters results for such ones that are unique across file changes
Parameters: - original_file_dict – Dict of lists of file contents before changes
- modified_file_dict – Dict of lists of file contents after changes
- original_results – List of results of the old files
- modified_results – List of results of the new files
Returns: List of results from new files that are unique from all those that existed in the old changes
-
coalib.results.ResultFilter.
remove_range
(file_contents, source_range)¶ removes the chars covered by the sourceRange from the file
Parameters: - file_contents – list of lines in the file
- source_range – Source Range
Returns: list of file contents without specified chars removed
-
coalib.results.ResultFilter.
remove_result_ranges_diffs
(result_list, file_dict)¶ Calculates the diffs to all files in file_dict that describe the removal of each respective result’s affected code.
Parameters: - result_list – list of results
- file_dict – dict of file contents
Returns: returnvalue[result][file] is a diff of the changes the removal of this result’s affected code would cause for the file.
-
coalib.results.ResultFilter.
source_ranges_match
(original_file_dict, diff_dict, original_result_diff_dict, modified_result_diff_dict)¶ Checks whether the SourceRanges of two results match
Parameters: - original_file_dict – Dict of lists of file contents before changes
- diff_dict – Dict of diffs describing the changes per file
- original_result_diff_dict – diff for each file for this result
- modified_result_diff_dict – guess
Returns: Boolean value whether the SourceRanges match
coalib.results.SourcePosition module¶
-
class
coalib.results.SourcePosition.
SourcePosition
(*args, **kwargs)¶ Bases:
coalib.results.TextPosition.TextPosition
-
file
¶
-
coalib.results.SourceRange module¶
-
class
coalib.results.SourceRange.
SourceRange
(*args, **kwargs)¶ Bases:
coalib.results.TextRange.TextRange
-
expand
(file_contents)¶ Passes a new SourceRange that covers the same area of a file as this one would. All values of None get replaced with absolute values.
values of None will be interpreted as follows: self.start.line is None: -> 1 self.start.column is None: -> 1 self.end.line is None: -> last line of file self.end.column is None: -> last column of self.end.line
Parameters: file_contents – File contents of the applicable file Returns: TextRange with absolute values
-
file
¶
-
classmethod
from_clang_range
(range)¶ Creates a SourceRange from a clang SourceRange object.
Parameters: range – A cindex.SourceRange object.
-
classmethod
from_values
(file, start_line=None, start_column=None, end_line=None, end_column=None)¶
-
coalib.results.TextPosition module¶
coalib.results.TextRange module¶
-
class
coalib.results.TextRange.
TextRange
(*args, **kwargs)¶ Bases:
object
-
end
¶
-
expand
(text_lines)¶ Passes a new TextRange that covers the same area of a file as this one would. All values of None get replaced with absolute values.
values of None will be interpreted as follows: self.start.line is None: -> 1 self.start.column is None: -> 1 self.end.line is None: -> last line of file self.end.column is None: -> last column of self.end.line
Parameters: text_lines – File contents of the applicable file Returns: TextRange with absolute values
-
classmethod
from_values
(start_line=None, start_column=None, end_line=None, end_column=None)¶ Creates a new TextRange.
Parameters: - start_line – The line number of the start position. The first line is 1.
- start_column – The column number of the start position. The first column is 1.
- end_line – The line number of the end position. If this parameter is None, then the end position is set the same like start position and end_column gets ignored.
- end_column – The column number of the end position.
Returns: A TextRange.
-
classmethod
join
(a, b)¶ Creates a new TextRange that covers the area of two overlapping ones
Parameters: - a – TextRange (needs to overlap b)
- b – TextRange (needs to overlap a)
Returns: A new TextRange covering the union of the Area of a and b
-
overlaps
(other)¶
-
start
¶
-