-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTargetMethod.py
More file actions
134 lines (105 loc) · 4.53 KB
/
Copy pathTargetMethod.py
File metadata and controls
134 lines (105 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import re
class TargetMethod(object):
def __init__(self, method_name, class_name=None, package_name=None, parameters=None, affected_commits={},
original_doc=None, final_doc=None, kind=None, repo_path=None, original_calls=[], final_calls=[],
return_type=None):
self.method_name = method_name
self.class_name = class_name
self.package_name = package_name
self.parameters = parameters
self.affected_commits = affected_commits
self.original_doc = original_doc
self.original_calls = original_calls
self.final_doc = final_doc
self.final_calls = final_calls
self.kind = kind
self.repo_path = repo_path
self.return_type = return_type
def method_in_string(self, connected_method, sentence):
if connected_method is not None and sentence is not None:
in_sentence = re.search(r'\b' + connected_method.method_name + '\W', sentence)
if in_sentence:
return True
else:
return False
else:
return False
def clean_params(self):
clean_params = []
if self.parameters is not None:
for param in self.parameters:
param.strip().strip('<>{}[]')
return clean_params
def filename(self):
file_name = self.class_name + '.java'
return file_name
def pseudo_path(self):
package = self.package_name.replace('.', '/')
if '.' in self.class_name:
class_name = self.class_name.split('.')[0] + '.java'
else:
class_name = self.filename()
pseudo_path = package + '/' + class_name
return pseudo_path
def total_parameters(self):
if self.parameters is None:
return 0
else:
return len(self.parameters)
def original_doc_mentions(self, connected_method):
if self.original_doc is not None:
if self.method_in_string(connected_method, self.original_doc):
return True
return False
def final_doc_mentions(self, connected_method):
if self.final_doc is not None:
if self.method_in_string(connected_method, self.final_doc):
return True
return False
def original_calls_contain(self, connected_method):
if self.original_calls is not None:
for call in self.original_calls:
if str(call) == connected_method.method_name:
return True
return False
def final_calls_contain(self, connected_method):
if self.final_calls is not None:
for call in self.final_calls:
if str(call) == connected_method.method_name:
return True
return False
def affected_commits_contain(self, connected_method):
if self.affected_commits is not None:
if id(self) != id(connected_method):
for commit, mods in self.affected_commits.items():
if "Removals" in mods:
for item in mods["Removals"]:
for add, rem in item.items():
if self.method_in_string(connected_method, add) or \
self.method_in_string(connected_method, rem):
return True
return False
def implementation_changed_together(self, connected_method):
if self.affected_commits is not None:
if id(self) != id(connected_method):
for commit, mods in self.affected_commits.items():
if "Changed Implementation" in mods:
if mods["Changed Implementation"]:
if commit in connected_method.affected_commits:
if "Changed Implementation" in connected_method.affected_commits[commit]:
if connected_method.affected_commits[commit]["Changed Implementation"]:
return True
return False
def get_unique_name(self):
if self.repo_path is not None:
unique_name = ""
unique_name += self.repo_path + "_"
unique_name += self.method_name
if self.parameters is not None:
param_string = '; '.join(self.parameters)
else:
param_string = ""
unique_name += "(" + param_string + ")"
else:
return None
return unique_name