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 import symbol | |
6 | |
7 from catapult_base.refactor.annotated_symbol import base_symbol | |
8 | |
9 | |
10 __all__ = [ | |
11 'Function', | |
12 ] | |
13 | |
14 | |
15 class Function(base_symbol.AnnotatedSymbol): | |
16 @classmethod | |
17 def Annotate(cls, symbol_type, children): | |
18 if symbol_type != symbol.stmt: | |
19 return None | |
20 | |
21 compound_statement = children[0] | |
22 if compound_statement.type != symbol.compound_stmt: | |
23 return None | |
24 | |
25 statement = compound_statement.children[0] | |
26 if statement.type == symbol.funcdef: | |
27 return cls(statement.type, statement.children) | |
28 elif (statement.type == symbol.decorated and | |
29 statement.children[-1].type == symbol.funcdef): | |
30 return cls(statement.type, statement.children) | |
31 else: | |
32 return None | |
33 | |
34 @property | |
35 def suite(self): | |
36 raise NotImplementedError() | |
37 | |
38 def FindChild(self, snippet_type, **kwargs): | |
39 return self.suite.FindChild(snippet_type, **kwargs) | |
40 | |
41 def FindChildren(self, snippet_type): | |
42 return self.suite.FindChildren(snippet_type) | |
43 | |
44 def Cut(self, child): | |
45 self.suite.Cut(child) | |
46 | |
47 def Paste(self, child): | |
48 self.suite.Paste(child) | |
OLD | NEW |