Utilities/ClassBrowsers/ClbrBaseClasses.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2005 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing base classes used by the various class browsers.
8 """
9
10 class _ClbrBase(object):
11 """
12 Class implementing the base of all class browser objects.
13 """
14 def __init__(self, module, name, file, lineno):
15 """
16 Constructor
17
18 @param module name of the module containing this class
19 @param name name of this class
20 @param file filename containing this object
21 @param lineno linenumber of the class definition
22 """
23 self.module = module
24 self.name = name
25 self.file = file
26 self.lineno = lineno
27
28 class ClbrBase(_ClbrBase):
29 """
30 Class implementing the base of all complex class browser objects.
31 """
32 def __init__(self, module, name, file, lineno):
33 """
34 Constructor
35
36 @param module name of the module containing this class
37 @param name name of this class
38 @param file filename containing this object
39 @param lineno linenumber of the class definition
40 """
41 _ClbrBase.__init__(self, module, name, file, lineno)
42 self.methods = {}
43 self.attributes = {}
44 self.classes = {}
45 self.globals = {}
46
47 def _addmethod(self, name, function):
48 """
49 Protected method to add information about a method.
50
51 @param name name of method to be added (string)
52 @param function Function object to be added
53 """
54 self.methods[name] = function
55
56 def _getmethod(self, name):
57 """
58 Protected method to retrieve a method by name.
59
60 @param name name of the method (string)
61 @return the named method or None
62 """
63 try:
64 return self.methods[name]
65 except KeyError:
66 return None
67
68 def _addglobal(self, attr):
69 """
70 Protected method to add information about global variables.
71
72 @param attr Attribute object to be added (Attribute)
73 """
74 if not self.globals.has_key(attr.name):
75 self.globals[attr.name] = attr
76
77 def _getglobal(self, name):
78 """
79 Protected method to retrieve a global variable by name.
80
81 @param name name of the global variable (string)
82 @return the named global variable or None
83 """
84 try:
85 return self.globals[name]
86 except KeyError:
87 return None
88
89 def _addattribute(self, attr):
90 """
91 Protected method to add information about attributes.
92
93 @param attr Attribute object to be added (Attribute)
94 """
95 if not self.attributes.has_key(attr.name):
96 self.attributes[attr.name] = attr
97
98 def _getattribute(self, name):
99 """
100 Protected method to retrieve an attribute by name.
101
102 @param name name of the attribute (string)
103 @return the named attribute or None
104 """
105 try:
106 return self.attributes[name]
107 except KeyError:
108 return None
109
110 def _addclass(self, name, _class):
111 """
112 Protected method method to add a nested class to this class.
113
114 @param name name of the class
115 @param _class Class object to be added (Class)
116 """
117 self.classes[name] = _class
118
119 class ClbrVisibilityMixinBase(object):
120 """
121 Class implementing the base class of all visibility mixins.
122 """
123 def isPrivate(self):
124 """
125 Public method to check, if the visibility is Private.
126
127 @return flag indicating Private visibility (boolean)
128 """
129 return self.visibility == 0
130
131 def isProtected(self):
132 """
133 Public method to check, if the visibility is Protected.
134
135 @return flag indicating Protected visibility (boolean)
136 """
137 return self.visibility == 1
138
139 def isPublic(self):
140 """
141 Public method to check, if the visibility is Public.
142
143 @return flag indicating Public visibility (boolean)
144 """
145 return self.visibility == 2
146
147 def setPrivate(self):
148 """
149 Public method to set the visibility to Private.
150 """
151 self.visibility = 0
152
153 def setProtected(self):
154 """
155 Public method to set the visibility to Protected.
156 """
157 self.visibility = 1
158
159 def setPublic(self):
160 """
161 Public method to set the visibility to Public.
162 """
163 self.visibility = 2
164
165 class Attribute(_ClbrBase):
166 """
167 Class to represent an attribute.
168 """
169 def __init__(self, module, name, file, lineno):
170 """
171 Constructor
172
173 @param module name of the module containing this class
174 @param name name of this class
175 @param file filename containing this attribute
176 @param lineno linenumber of the class definition
177 """
178 _ClbrBase.__init__(self, module, name, file, lineno)
179
180 class Class(ClbrBase):
181 """
182 Class to represent a class.
183 """
184 def __init__(self, module, name, super, file, lineno):
185 """
186 Constructor
187
188 @param module name of the module containing this class
189 @param name name of this class
190 @param super list of class names this class is inherited from
191 @param file filename containing this class
192 @param lineno linenumber of the class definition
193 """
194 ClbrBase.__init__(self, module, name, file, lineno)
195 if super is None:
196 super = []
197 self.super = super
198
199 class Module(ClbrBase):
200 """
201 Class to represent a module.
202 """
203 def __init__(self, module, name, file, lineno):
204 """
205 Constructor
206
207 @param module name of the module containing this module
208 @param name name of this module
209 @param file filename containing this module
210 @param lineno linenumber of the module definition
211 """
212 ClbrBase.__init__(self, module, name, file, lineno)
213
214 class Function(ClbrBase):
215 """
216 Class to represent a function or method.
217 """
218 def __init__(self, module, name, file, lineno, signature = '', separator = ','):
219 """
220 Constructor
221
222 @param module name of the module containing this function
223 @param name name of this function
224 @param file filename containing this class
225 @param lineno linenumber of the class definition
226 @param signature parameterlist of the method
227 @param separator string separating the parameters
228 """
229 ClbrBase.__init__(self, module, name, file, lineno)
230 self.parameters = [e.strip() for e in signature.split(separator)]
231
232 class Coding(ClbrBase):
233 """
234 Class to represent a source coding.
235 """
236 def __init__(self, module, file, lineno, coding):
237 """
238 Constructor
239
240 @param module name of the module containing this module
241 @param file filename containing this module
242 @param lineno linenumber of the module definition
243 @param coding character coding of the source file
244 """
245 ClbrBase.__init__(self, module, "Coding", file, lineno)
246 self.coding = coding

eric ide

mercurial