src/eric7/Utilities/ClassBrowsers/ClbrBaseClasses.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9653
e67609152c5e
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
10 10
11 class _ClbrBase: 11 class _ClbrBase:
12 """ 12 """
13 Class implementing the base of all class browser objects. 13 Class implementing the base of all class browser objects.
14 """ 14 """
15 def __init__(self, module, name, file, lineno): 15
16 """ 16 def __init__(self, module, name, file, lineno):
17 Constructor 17 """
18 18 Constructor
19
19 @param module name of the module containing this object 20 @param module name of the module containing this object
20 @type str 21 @type str
21 @param name name of this object 22 @param name name of this object
22 @type str 23 @type str
23 @param file filename containing this object 24 @param file filename containing this object
27 """ 28 """
28 self.module = module 29 self.module = module
29 self.name = name 30 self.name = name
30 self.file = file 31 self.file = file
31 self.lineno = lineno 32 self.lineno = lineno
32 self.endlineno = -1 # marker for "not set" 33 self.endlineno = -1 # marker for "not set"
33 34
34 def setEndLine(self, endLineNo): 35 def setEndLine(self, endLineNo):
35 """ 36 """
36 Public method to set the ending line number. 37 Public method to set the ending line number.
37 38
38 @param endLineNo number of the last line 39 @param endLineNo number of the last line
39 @type int 40 @type int
40 """ 41 """
41 self.endlineno = endLineNo 42 self.endlineno = endLineNo
42 43
43 44
44 class ClbrBase(_ClbrBase): 45 class ClbrBase(_ClbrBase):
45 """ 46 """
46 Class implementing the base of all complex class browser objects. 47 Class implementing the base of all complex class browser objects.
47 """ 48 """
48 def __init__(self, module, name, file, lineno): 49
49 """ 50 def __init__(self, module, name, file, lineno):
50 Constructor 51 """
51 52 Constructor
53
52 @param module name of the module containing this object 54 @param module name of the module containing this object
53 @type str 55 @type str
54 @param name name of this object 56 @param name name of this object
55 @type str 57 @type str
56 @param file filename containing this object 58 @param file filename containing this object
61 _ClbrBase.__init__(self, module, name, file, lineno) 63 _ClbrBase.__init__(self, module, name, file, lineno)
62 self.methods = {} 64 self.methods = {}
63 self.attributes = {} 65 self.attributes = {}
64 self.classes = {} 66 self.classes = {}
65 self.globals = {} 67 self.globals = {}
66 68
67 def _addmethod(self, name, function): 69 def _addmethod(self, name, function):
68 """ 70 """
69 Protected method to add information about a method. 71 Protected method to add information about a method.
70 72
71 @param name name of method to be added 73 @param name name of method to be added
72 @type str 74 @type str
73 @param function Function object to be added 75 @param function Function object to be added
74 @type Function 76 @type Function
75 """ 77 """
76 self.methods[name] = function 78 self.methods[name] = function
77 79
78 def _getmethod(self, name): 80 def _getmethod(self, name):
79 """ 81 """
80 Protected method to retrieve a method by name. 82 Protected method to retrieve a method by name.
81 83
82 @param name name of the method (string) 84 @param name name of the method (string)
83 @type str 85 @type str
84 @return the named method 86 @return the named method
85 @rtype Function or None 87 @rtype Function or None
86 """ 88 """
87 try: 89 try:
88 return self.methods[name] 90 return self.methods[name]
89 except KeyError: 91 except KeyError:
90 return None 92 return None
91 93
92 def _addglobal(self, attr): 94 def _addglobal(self, attr):
93 """ 95 """
94 Protected method to add information about global variables. 96 Protected method to add information about global variables.
95 97
96 @param attr Attribute object to be added 98 @param attr Attribute object to be added
97 @type Attribute 99 @type Attribute
98 """ 100 """
99 if attr.name not in self.globals: 101 if attr.name not in self.globals:
100 self.globals[attr.name] = attr 102 self.globals[attr.name] = attr
101 else: 103 else:
102 self.globals[attr.name].addAssignment(attr.lineno) 104 self.globals[attr.name].addAssignment(attr.lineno)
103 105
104 def _getglobal(self, name): 106 def _getglobal(self, name):
105 """ 107 """
106 Protected method to retrieve a global variable by name. 108 Protected method to retrieve a global variable by name.
107 109
108 @param name name of the global variable 110 @param name name of the global variable
109 @type str 111 @type str
110 @return the named global variable 112 @return the named global variable
111 @rtype Attribute or None 113 @rtype Attribute or None
112 """ 114 """
113 try: 115 try:
114 return self.globals[name] 116 return self.globals[name]
115 except KeyError: 117 except KeyError:
116 return None 118 return None
117 119
118 def _addattribute(self, attr): 120 def _addattribute(self, attr):
119 """ 121 """
120 Protected method to add information about attributes. 122 Protected method to add information about attributes.
121 123
122 @param attr Attribute object to be added 124 @param attr Attribute object to be added
123 @type Attribute 125 @type Attribute
124 """ 126 """
125 if attr.name not in self.attributes: 127 if attr.name not in self.attributes:
126 self.attributes[attr.name] = attr 128 self.attributes[attr.name] = attr
127 else: 129 else:
128 self.attributes[attr.name].addAssignment(attr.lineno) 130 self.attributes[attr.name].addAssignment(attr.lineno)
129 131
130 def _getattribute(self, name): 132 def _getattribute(self, name):
131 """ 133 """
132 Protected method to retrieve an attribute by name. 134 Protected method to retrieve an attribute by name.
133 135
134 @param name name of the attribute 136 @param name name of the attribute
135 @type str 137 @type str
136 @return the named attribute 138 @return the named attribute
137 @rtype Attribute or None 139 @rtype Attribute or None
138 """ 140 """
139 try: 141 try:
140 return self.attributes[name] 142 return self.attributes[name]
141 except KeyError: 143 except KeyError:
142 return None 144 return None
143 145
144 def _addclass(self, name, _class): 146 def _addclass(self, name, _class):
145 """ 147 """
146 Protected method method to add a nested class to this class. 148 Protected method method to add a nested class to this class.
147 149
148 @param name name of the class 150 @param name name of the class
149 @type str 151 @type str
150 @param _class Class object to be added 152 @param _class Class object to be added
151 @type Class 153 @type Class
152 """ 154 """
155 157
156 class ClbrVisibilityMixinBase: 158 class ClbrVisibilityMixinBase:
157 """ 159 """
158 Class implementing the base class of all visibility mixins. 160 Class implementing the base class of all visibility mixins.
159 """ 161 """
162
160 def isPrivate(self): 163 def isPrivate(self):
161 """ 164 """
162 Public method to check, if the visibility is Private. 165 Public method to check, if the visibility is Private.
163 166
164 @return flag indicating Private visibility 167 @return flag indicating Private visibility
165 @rtype bool 168 @rtype bool
166 """ 169 """
167 return self.visibility == 0 170 return self.visibility == 0
168 171
169 def isProtected(self): 172 def isProtected(self):
170 """ 173 """
171 Public method to check, if the visibility is Protected. 174 Public method to check, if the visibility is Protected.
172 175
173 @return flag indicating Protected visibility 176 @return flag indicating Protected visibility
174 @rtype bool 177 @rtype bool
175 """ 178 """
176 return self.visibility == 1 179 return self.visibility == 1
177 180
178 def isPublic(self): 181 def isPublic(self):
179 """ 182 """
180 Public method to check, if the visibility is Public. 183 Public method to check, if the visibility is Public.
181 184
182 @return flag indicating Public visibility 185 @return flag indicating Public visibility
183 @rtype bool 186 @rtype bool
184 """ 187 """
185 return self.visibility == 2 188 return self.visibility == 2
186 189
187 def setPrivate(self): 190 def setPrivate(self):
188 """ 191 """
189 Public method to set the visibility to Private. 192 Public method to set the visibility to Private.
190 """ 193 """
191 self.visibility = 0 194 self.visibility = 0
192 195
193 def setProtected(self): 196 def setProtected(self):
194 """ 197 """
195 Public method to set the visibility to Protected. 198 Public method to set the visibility to Protected.
196 """ 199 """
197 self.visibility = 1 200 self.visibility = 1
198 201
199 def setPublic(self): 202 def setPublic(self):
200 """ 203 """
201 Public method to set the visibility to Public. 204 Public method to set the visibility to Public.
202 """ 205 """
203 self.visibility = 2 206 self.visibility = 2
205 208
206 class Attribute(_ClbrBase): 209 class Attribute(_ClbrBase):
207 """ 210 """
208 Class to represent an attribute. 211 Class to represent an attribute.
209 """ 212 """
210 def __init__(self, module, name, file, lineno): 213
211 """ 214 def __init__(self, module, name, file, lineno):
212 Constructor 215 """
213 216 Constructor
217
214 @param module name of the module containing this attribute 218 @param module name of the module containing this attribute
215 @type str 219 @type str
216 @param name name of this attribute 220 @param name name of this attribute
217 @type str 221 @type str
218 @param file filename containing this attribute 222 @param file filename containing this attribute
219 @type str 223 @type str
220 @param lineno line number of the attribute definition 224 @param lineno line number of the attribute definition
221 @type int 225 @type int
222 """ 226 """
223 _ClbrBase.__init__(self, module, name, file, lineno) 227 _ClbrBase.__init__(self, module, name, file, lineno)
224 228
225 self.linenos = [lineno] 229 self.linenos = [lineno]
226 230
227 def addAssignment(self, lineno): 231 def addAssignment(self, lineno):
228 """ 232 """
229 Public method to add another assignment line number. 233 Public method to add another assignment line number.
230 234
231 @param lineno line number of the additional attribute assignment 235 @param lineno line number of the additional attribute assignment
232 @type int 236 @type int
233 """ 237 """
234 if lineno not in self.linenos: 238 if lineno not in self.linenos:
235 self.linenos.append(lineno) 239 self.linenos.append(lineno)
237 241
238 class Class(ClbrBase): 242 class Class(ClbrBase):
239 """ 243 """
240 Class to represent a class. 244 Class to represent a class.
241 """ 245 """
246
242 def __init__(self, module, name, superClasses, file, lineno): 247 def __init__(self, module, name, superClasses, file, lineno):
243 """ 248 """
244 Constructor 249 Constructor
245 250
246 @param module name of the module containing this class 251 @param module name of the module containing this class
247 @type str 252 @type str
248 @param name name of this class 253 @param name name of this class
249 @type str 254 @type str
250 @param superClasses list of class names this class is inherited from 255 @param superClasses list of class names this class is inherited from
262 267
263 class Module(ClbrBase): 268 class Module(ClbrBase):
264 """ 269 """
265 Class to represent a module. 270 Class to represent a module.
266 """ 271 """
267 def __init__(self, module, name, file, lineno): 272
268 """ 273 def __init__(self, module, name, file, lineno):
269 Constructor 274 """
270 275 Constructor
276
271 @param module name of the module containing this module 277 @param module name of the module containing this module
272 @type str 278 @type str
273 @param name name of this module 279 @param name name of this module
274 @type str 280 @type str
275 @param file filename containing this module 281 @param file filename containing this module
282 288
283 class Function(ClbrBase): 289 class Function(ClbrBase):
284 """ 290 """
285 Class to represent a function or method. 291 Class to represent a function or method.
286 """ 292 """
293
287 General = 0 294 General = 0
288 Static = 1 295 Static = 1
289 Class = 2 296 Class = 2
290 297
291 def __init__(self, module, name, file, lineno, signature='', separator=',', 298 def __init__(
292 modifierType=General, annotation=""): 299 self,
293 """ 300 module,
294 Constructor 301 name,
295 302 file,
303 lineno,
304 signature="",
305 separator=",",
306 modifierType=General,
307 annotation="",
308 ):
309 """
310 Constructor
311
296 @param module name of the module containing this function 312 @param module name of the module containing this function
297 @type str 313 @type str
298 @param name name of this function 314 @param name name of this function
299 @type str 315 @type str
300 @param file filename containing this function 316 @param file filename containing this function
318 334
319 class Coding(ClbrBase): 335 class Coding(ClbrBase):
320 """ 336 """
321 Class to represent a source coding. 337 Class to represent a source coding.
322 """ 338 """
339
323 def __init__(self, module, file, lineno, coding): 340 def __init__(self, module, file, lineno, coding):
324 """ 341 """
325 Constructor 342 Constructor
326 343
327 @param module name of the module containing this coding statement 344 @param module name of the module containing this coding statement
328 @type str 345 @type str
329 @param file filename containing this coding statement 346 @param file filename containing this coding statement
330 @type str 347 @type str
331 @param lineno line number of the coding definition 348 @param lineno line number of the coding definition
340 357
341 class Enum(ClbrBase): 358 class Enum(ClbrBase):
342 """ 359 """
343 Class to represent an enum definition. 360 Class to represent an enum definition.
344 """ 361 """
345 def __init__(self, module, name, file, lineno): 362
346 """ 363 def __init__(self, module, name, file, lineno):
347 Constructor 364 """
348 365 Constructor
366
349 @param module name of the module containing this enum 367 @param module name of the module containing this enum
350 @type str 368 @type str
351 @param name name of this enum 369 @param name name of this enum
352 @type str 370 @type str
353 @param file filename containing this enum 371 @param file filename containing this enum

eric ide

mercurial