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