1cef7893435aa41160dd1255c43cb8498279738ccChris Craik# Copyright 2015 The Chromium Authors. All rights reserved.
2cef7893435aa41160dd1255c43cb8498279738ccChris Craik# Use of this source code is governed by a BSD-style license that can be
3cef7893435aa41160dd1255c43cb8498279738ccChris Craik# found in the LICENSE file.
4cef7893435aa41160dd1255c43cb8498279738ccChris Craik
5cef7893435aa41160dd1255c43cb8498279738ccChris Craikimport symbol
6cef7893435aa41160dd1255c43cb8498279738ccChris Craik
77332cdb42368a904cbf7418de329868989e592daChris Craikfrom py_utils.refactor.annotated_symbol import base_symbol
8cef7893435aa41160dd1255c43cb8498279738ccChris Craik
9cef7893435aa41160dd1255c43cb8498279738ccChris Craik
10cef7893435aa41160dd1255c43cb8498279738ccChris Craik__all__ = [
11cef7893435aa41160dd1255c43cb8498279738ccChris Craik    'Function',
12cef7893435aa41160dd1255c43cb8498279738ccChris Craik]
13cef7893435aa41160dd1255c43cb8498279738ccChris Craik
14cef7893435aa41160dd1255c43cb8498279738ccChris Craik
15cef7893435aa41160dd1255c43cb8498279738ccChris Craikclass Function(base_symbol.AnnotatedSymbol):
16cef7893435aa41160dd1255c43cb8498279738ccChris Craik  # pylint: disable=abstract-class-not-used
17cef7893435aa41160dd1255c43cb8498279738ccChris Craik
18cef7893435aa41160dd1255c43cb8498279738ccChris Craik  @classmethod
19cef7893435aa41160dd1255c43cb8498279738ccChris Craik  def Annotate(cls, symbol_type, children):
20cef7893435aa41160dd1255c43cb8498279738ccChris Craik    if symbol_type != symbol.stmt:
21cef7893435aa41160dd1255c43cb8498279738ccChris Craik      return None
22cef7893435aa41160dd1255c43cb8498279738ccChris Craik
23cef7893435aa41160dd1255c43cb8498279738ccChris Craik    compound_statement = children[0]
24cef7893435aa41160dd1255c43cb8498279738ccChris Craik    if compound_statement.type != symbol.compound_stmt:
25cef7893435aa41160dd1255c43cb8498279738ccChris Craik      return None
26cef7893435aa41160dd1255c43cb8498279738ccChris Craik
27cef7893435aa41160dd1255c43cb8498279738ccChris Craik    statement = compound_statement.children[0]
28cef7893435aa41160dd1255c43cb8498279738ccChris Craik    if statement.type == symbol.funcdef:
29cef7893435aa41160dd1255c43cb8498279738ccChris Craik      return cls(statement.type, statement.children)
30cef7893435aa41160dd1255c43cb8498279738ccChris Craik    elif (statement.type == symbol.decorated and
31cef7893435aa41160dd1255c43cb8498279738ccChris Craik          statement.children[-1].type == symbol.funcdef):
32cef7893435aa41160dd1255c43cb8498279738ccChris Craik      return cls(statement.type, statement.children)
33cef7893435aa41160dd1255c43cb8498279738ccChris Craik    else:
34cef7893435aa41160dd1255c43cb8498279738ccChris Craik      return None
35cef7893435aa41160dd1255c43cb8498279738ccChris Craik
36cef7893435aa41160dd1255c43cb8498279738ccChris Craik  @property
37cef7893435aa41160dd1255c43cb8498279738ccChris Craik  def suite(self):
38cef7893435aa41160dd1255c43cb8498279738ccChris Craik    # TODO: Complete.
39cef7893435aa41160dd1255c43cb8498279738ccChris Craik    raise NotImplementedError()
40cef7893435aa41160dd1255c43cb8498279738ccChris Craik
41cef7893435aa41160dd1255c43cb8498279738ccChris Craik  def FindChild(self, snippet_type, **kwargs):
42cef7893435aa41160dd1255c43cb8498279738ccChris Craik    return self.suite.FindChild(snippet_type, **kwargs)
43cef7893435aa41160dd1255c43cb8498279738ccChris Craik
44cef7893435aa41160dd1255c43cb8498279738ccChris Craik  def FindChildren(self, snippet_type):
45cef7893435aa41160dd1255c43cb8498279738ccChris Craik    return self.suite.FindChildren(snippet_type)
46cef7893435aa41160dd1255c43cb8498279738ccChris Craik
47cef7893435aa41160dd1255c43cb8498279738ccChris Craik  def Cut(self, child):
48cef7893435aa41160dd1255c43cb8498279738ccChris Craik    self.suite.Cut(child)
49cef7893435aa41160dd1255c43cb8498279738ccChris Craik
50cef7893435aa41160dd1255c43cb8498279738ccChris Craik  def Paste(self, child):
51cef7893435aa41160dd1255c43cb8498279738ccChris Craik    self.suite.Paste(child)
52