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) |