Index: tools/telemetry/catapult_base/refactor/annotated_symbol/class_definition.py |
diff --git a/tools/telemetry/catapult_base/refactor/annotated_symbol/class_definition.py b/tools/telemetry/catapult_base/refactor/annotated_symbol/class_definition.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8254aad9368de0d8f8db8fbd86c61c5fbdb5673c |
--- /dev/null |
+++ b/tools/telemetry/catapult_base/refactor/annotated_symbol/class_definition.py |
@@ -0,0 +1,48 @@ |
+# Copyright 2015 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import symbol |
+ |
+from catapult_base.refactor.annotated_symbol import base_symbol |
+ |
+ |
+__all__ = [ |
+ 'Class', |
+] |
+ |
+ |
+class Class(base_symbol.AnnotatedSymbol): |
+ @classmethod |
+ def Annotate(cls, symbol_type, children): |
+ if symbol_type != symbol.stmt: |
+ return None |
+ |
+ compound_statement = children[0] |
+ if compound_statement.type != symbol.compound_stmt: |
+ return None |
+ |
+ statement = compound_statement.children[0] |
+ if statement.type == symbol.classdef: |
+ return cls(statement.type, statement.children) |
+ elif (statement.type == symbol.decorated and |
+ statement.children[-1].type == symbol.classdef): |
+ return cls(statement.type, statement.children) |
+ else: |
+ return None |
+ |
+ @property |
+ def suite(self): |
+ raise NotImplementedError() |
+ |
+ def FindChild(self, snippet_type, **kwargs): |
+ return self.suite.FindChild(snippet_type, **kwargs) |
+ |
+ def FindChildren(self, snippet_type): |
+ return self.suite.FindChildren(snippet_type) |
+ |
+ def Cut(self, child): |
+ self.suite.Cut(child) |
+ |
+ def Paste(self, child): |
+ self.suite.Paste(child) |