| Conditions | 14 |
| Total Lines | 60 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like fused_iutest_files.IutestFused.Translate() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | #!/usr/bin/env python |
||
| 169 | def Translate(self, root, filename, output, output_dir, minimum): |
||
| 170 | output_file = codecs.open(os.path.join(output_dir, output), 'w', 'utf-8-sig') |
||
| 171 | processed_files = set() |
||
| 172 | # fused-min not support gtest switch |
||
| 173 | if minimum: |
||
| 174 | processed_files.add(os.path.normpath(os.path.join(root, "gtest/iutest_switch.hpp"))) |
||
| 175 | |||
| 176 | def ProcessFile(curr, filename, fileset, minimum): |
||
| 177 | path = os.path.join(root, filename) |
||
| 178 | if not os.path.exists(path): |
||
| 179 | path = os.path.join(curr, filename) |
||
| 180 | |||
| 181 | path = os.path.normpath(path) |
||
| 182 | if path in fileset: |
||
| 183 | return |
||
| 184 | |||
| 185 | find_ifdef = False |
||
| 186 | fileset.add(path) |
||
| 187 | for line in codecs.open(path, 'r', 'utf-8-sig'): |
||
| 188 | line = re.sub('/\*.*?\*/', '', line)
|
||
| 189 | m = self.INCLUDE_REGEX.match(line) |
||
| 190 | if m: |
||
| 191 | self.Flush(output_file) |
||
| 192 | include_file = m.group(1) |
||
| 193 | if find_ifdef: |
||
| 194 | s = set(fileset) |
||
| 195 | ProcessFile(os.path.dirname(path), include_file, s, minimum) |
||
| 196 | else: |
||
| 197 | ProcessFile(os.path.dirname(path), include_file, fileset, minimum) |
||
| 198 | else: |
||
| 199 | find_ifdef = bool(self.IFDEF_REGEX.match(line)) |
||
| 200 | if minimum: |
||
| 201 | line = self.Minimze(line) |
||
| 202 | if len(line): |
||
| 203 | if self.PREPRO_REGEX.match(self.store_line): |
||
| 204 | line = line.strip() |
||
| 205 | if line.endswith('\\'):
|
||
| 206 | self.StoreMinimze(line.rstrip(r'\\')) |
||
| 207 | else: |
||
| 208 | self.StoreMinimze(line) |
||
| 209 | self.Flush(output_file) |
||
| 210 | elif self.PREPRO_REGEX.match(line): |
||
| 211 | self.Flush(output_file) |
||
| 212 | if line.strip().endswith('\\'):
|
||
| 213 | self.StoreMinimze(line.strip().rstrip(r'\\')) |
||
| 214 | else: |
||
| 215 | output_file.write(line) |
||
| 216 | else: |
||
| 217 | strip_line = line.strip() |
||
| 218 | self.StoreMinimze(strip_line) |
||
| 219 | #if not re.match('.*[{};\(\)<>]$', strip_line):
|
||
| 220 | # self.Flush(output_file) |
||
| 221 | if re.match('.*(:|IUTEST_CXX_DEFAULT_FUNCTION)$', strip_line):
|
||
| 222 | self.store_line += " " |
||
| 223 | else: |
||
| 224 | output_file.write(line) |
||
| 225 | self.Flush(output_file) |
||
| 226 | |||
| 227 | ProcessFile(root, filename, processed_files, minimum) |
||
| 228 | output_file.close() |
||
| 229 | |||
| 256 |