OLD | NEW |
| (Empty) |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 from catapult_base.refactor import annotated_symbol | |
6 | |
7 | |
8 class Module(object): | |
9 def __init__(self, file_path): | |
10 self._file_path = file_path | |
11 | |
12 with open(self._file_path, 'r') as f: | |
13 self._snippet = annotated_symbol.Annotate(f) | |
14 | |
15 @property | |
16 def file_path(self): | |
17 return self._file_path | |
18 | |
19 @property | |
20 def modified(self): | |
21 return self._snippet.modified | |
22 | |
23 def FindAll(self, snippet_type): | |
24 return self._snippet.FindAll(snippet_type) | |
25 | |
26 def FindChildren(self, snippet_type): | |
27 return self._snippet.FindChildren(snippet_type) | |
28 | |
29 def Write(self): | |
30 """Write modifications to the file.""" | |
31 if not self.modified: | |
32 return | |
33 | |
34 # Stringify before opening the file for writing. | |
35 # If we fail, we won't truncate the file. | |
36 string = str(self._snippet) | |
37 with open(self._file_path, 'w') as f: | |
38 f.write(string) | |
OLD | NEW |