Changeset 1187:d913cc7d0d8f
- Timestamp:
- 06/18/08 09:47:45 (6 months ago)
- Author:
- Ali Afshar <aafshar@…>
- Message:
-
Python plugin: Added support for decorators, classmethods and staticmethods
- Location:
- pida-plugins/python
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r1186
|
r1187
|
|
| 172 | 172 | #Column('ctype_markup', use_markup=True), |
| 173 | 173 | #Column('nodename_markup', use_markup=True), |
| | 174 | Column('type_markup', use_markup=True), |
| 174 | 175 | Column('rendered', use_markup=True, expand=True), |
| 175 | 176 | Column('sort_hack', visible=False), |
-
|
r1186
|
r1187
|
|
| 38 | 38 | return markup_grey_italic(s) |
| 39 | 39 | |
| | 40 | def markup_fixed(text): |
| | 41 | return '<tt>%s</tt>' % text |
| | 42 | |
| 40 | 43 | def markup_name(name): |
| 41 | | return markup_bold(name) |
| | 44 | return markup_bold(markup_fixed(name)) |
| 42 | 45 | |
| 43 | 46 | class TreeOptions(object): |
| … |
… |
|
| 54 | 57 | return '' |
| 55 | 58 | |
| | 59 | def get_pre_markup(self): |
| | 60 | return '' |
| | 61 | |
| 56 | 62 | |
| 57 | 63 | class FunctionOptions(TreeOptions): |
| … |
… |
|
| 61 | 67 | position = 2 |
| 62 | 68 | |
| | 69 | def get_pre_markup(self): |
| | 70 | decs = ', '.join(['@' + d.id for d in |
| | 71 | self.item.object.decorators]) |
| | 72 | if decs: |
| | 73 | decs = decs + '\n' |
| | 74 | return markup_fixed(markup_italic(decs)) |
| | 75 | |
| | 76 | |
| 63 | 77 | def get_extra_markup(self): |
| 64 | | return markup_bold_bracketted( |
| | 78 | attrs = markup_bold_bracketted( |
| 65 | 79 | ', '.join(self.item.object.get_param_names()) |
| 66 | 80 | ) |
| | 81 | return attrs |
| | 82 | |
| | 83 | |
| | 84 | class EvaluatedOptions(TreeOptions): |
| | 85 | |
| | 86 | type_name = 'p' |
| | 87 | type_color = '#900090' |
| 67 | 88 | |
| 68 | 89 | |
| … |
… |
|
| 76 | 97 | type_name = '(m)' |
| 77 | 98 | position = 6 |
| | 99 | |
| | 100 | class ClassMethodOptions(MethodOptions): |
| | 101 | |
| | 102 | type_name = 'cm' |
| | 103 | position = 3 |
| | 104 | |
| | 105 | class StaticMethodOptions(MethodOptions): |
| | 106 | |
| | 107 | type_name = 'sm' |
| | 108 | position = 4 |
| 78 | 109 | |
| 79 | 110 | |
| … |
… |
|
| 117 | 148 | elif isinstance(item.node, pynames.DefinedName): |
| 118 | 149 | if isinstance(item.object, pyobjects.PyFunction): |
| 119 | | if item.object.get_kind() == 'method': |
| | 150 | kind = item.object.get_kind() |
| | 151 | if kind == 'method': |
| 120 | 152 | if item.name in item.parent.object.get_scope().get_defined_names(): |
| 121 | 153 | return MethodOptions(item) |
| 122 | 154 | else: |
| 123 | 155 | return SuperMethodOptions(item) |
| | 156 | elif kind == 'classmethod': |
| | 157 | return ClassMethodOptions(item) |
| | 158 | elif kind == 'staticmethod': |
| | 159 | return StaticMethodOptions(item) |
| 124 | 160 | else: |
| | 161 | print item.object.get_kind(), item.name |
| 125 | 162 | return FunctionOptions(item) |
| 126 | 163 | else: |
| … |
… |
|
| 130 | 167 | elif isinstance(item.node, builtins.BuiltinName): |
| 131 | 168 | return BuiltinOptions(item) |
| | 169 | elif isinstance(item.node, pynames.EvaluatedName): |
| | 170 | return EvaluatedOptions(item) |
| 132 | 171 | else: |
| 133 | | print 'boo', item, item.node |
| | 172 | print 'boo', item, item.node, item.name, item.object |
| 134 | 173 | |
| 135 | 174 | |
| … |
… |
|
| 164 | 203 | self.rendered = self.render() |
| 165 | 204 | |
| | 205 | self.type_markup = markup_type(self.options.type_name, |
| | 206 | self.options.type_color) |
| | 207 | |
| 166 | 208 | def render(self): |
| 167 | | return '%s %s%s %s' % ( |
| 168 | | markup_type(self.options.type_name, |
| 169 | | self.options.type_color), |
| | 209 | return '%s%s%s %s' % ( |
| | 210 | self.options.get_pre_markup(), |
| 170 | 211 | markup_name(self.name), |
| 171 | 212 | self.options.get_extra_markup(), |