root/trunk/idldoc/src/tree/doctreeroutine__define.pro @ 214

Revision 214, 12.4 KB (checked in by mgalloy, 6 years ago)

Displaying get/set/init for properties.

Line 
1; docformat = 'rst'
2
3;+
4; :Properties:
5;    `file` : get, type=object
6;       file tree object
7;    `name` : set, get, type=string
8;       name of the routine
9;    `is_function` : get, set, type=boolean
10;       1 if a function, 0 if not
11;    `is_method` : get, set, type=boolean
12;       1 if a method, 0 if not
13;    `parameters` : get, type=object
14;       list object of positional parameter objects for routine
15;    `keywords` : get, type=object
16;       list object of keyword objects for routine
17;-
18
19;+
20; Get properties.
21;-
22pro doctreeroutine::getProperty, file=file, name=name, is_function=isFunction, $
23                                 is_method=isMethod, parameters=parameters, $
24                                 keywords=keywords
25  compile_opt strictarr
26 
27  if (arg_present(file)) then file = self.file
28  if (arg_present(name)) then name = self.name
29  if (arg_present(isFunction)) then isFunction = self.isFunction
30  if (arg_present(isMethod)) then isMethod = self.isMethod
31  if (arg_present(parameters)) then parameters = self.parameters
32  if (arg_present(keywords)) then keywords = self.keywords
33end
34
35
36;+
37; Set properties.
38;-
39pro doctreeroutine::setProperty, name=name, $
40                                 is_Function=isFunction, $
41                                 is_method=isMethod, $
42                                 is_obsolete=isObsolete, $
43                                 is_abstract=isAbstract, $
44                                 is_hidden=isHidden, $
45                                 is_private=isPrivate, $
46                                 comments=comments, $
47                                 returns=returns, $
48                                 examples=examples, $
49                                 bugs=bugs, pre=pre, post=post, $
50                                 customer_id=customerId, $
51                                 author=author, copyright=copyright, $
52                                 history=history, $
53                                 version=version, $
54                                 todo=todo, $
55                                 restrictions=restrictions
56  compile_opt strictarr
57 
58  if (n_elements(name) gt 0) then self.name = name
59 
60  if (n_elements(isFunction) gt 0) then self.isFunction = isFunction
61  if (n_elements(isMethod) gt 0) then self.isMethod = isMethod 
62  if (n_elements(isHidden) gt 0) then self.isHidden = isHidden
63  if (n_elements(isPrivate) gt 0) then self.isPrivate = isPrivate
64  if (n_elements(isObsolete) gt 0) then self.isObsolete = isObsolete
65  if (n_elements(isAbstract) gt 0) then self.isAbstract = isAbstract
66 
67  if (n_elements(comments) gt 0) then self.comments = comments
68  if (n_elements(returns) gt 0) then self.returns = returns 
69  if (n_elements(examples) gt 0) then self.examples = examples
70 
71  ; "author info" attributes
72  if (n_elements(author) gt 0) then begin
73    self.hasAuthorInfo = 1B
74    self.author = author
75  endif
76
77  if (n_elements(copyright) gt 0) then begin
78    self.hasAuthorInfo = 1B
79    self.copyright = copyright
80  endif
81 
82  if (n_elements(history) gt 0) then begin
83    self.hasAuthorInfo = 1B
84    self.history = history
85  endif
86
87  if (n_elements(version) gt 0) then begin
88    self.hasAuthorInfo = 1B
89    self.version = version
90  endif
91   
92  ; "other" attributes 
93  if (n_elements(bugs) gt 0) then begin
94    self.hasOthers = 1B
95    self.bugs = bugs
96  endif 
97 
98  if (n_elements(pre) gt 0) then begin
99    self.hasOthers = 1B
100    self.pre = pre
101  endif
102 
103  if (n_elements(post) gt 0) then begin
104    self.hasOthers = 1B
105    self.post = post
106  endif     
107 
108  if (n_elements(customerId) gt 0) then begin
109    self.hasOthers = 1B
110    self.customerId = customerId
111  endif
112 
113  if (n_elements(todo) gt 0) then begin
114    self.hasOthers = 1B
115    self.todo = todo
116  endif
117 
118  if (n_elements(restrictions) gt 0) then begin
119    self.hasOthers = 1B
120    self.restrictions = restrictions
121  endif       
122end
123
124
125;+
126; Get variables for use with templates.
127;
128; :Returns: variable
129; :Params:
130;    `name` : in, required, type=string
131;       name of variable
132;
133; :Keywords:
134;    `found` : out, optional, type=boolean
135;       set to a named variable, returns if variable name was found
136;-
137function doctreeroutine::getVariable, name, found=found
138  compile_opt strictarr
139 
140  found = 1B
141  case strlowcase(name) of
142    'name': return, self.name
143
144    'is_function': return, self.isFunction
145    'is_private': return, self.isPrivate
146    'is_abstract': return, self.isAbstract     
147    'is_obsolete': return, self.isObsolete
148   
149    'has_comments': return, obj_valid(self.comments)
150    'comments': return, self.system->processComments(self.comments)
151    'comments_first_line': begin
152        if (~obj_valid(self.comments)) then return, ''
153       
154        comments = self.system->processComments(self.comments)
155       
156        nLines = n_elements(comments)
157        line = 0
158        while (line lt nLines) do begin
159          pos = stregex(comments[line], '\.( |$)')
160          if (pos ne -1) then break
161          line++
162        endwhile 
163       
164        if (pos eq -1) then return, comments[0:line-1]
165        if (line eq 0) then return, strmid(comments[line], 0, pos + 1)
166       
167        return, [comments[0:line-1], strmid(comments[line], 0, pos + 1)]
168      end
169     
170    'has_returns': return, obj_valid(self.returns)
171    'returns': return, self.system->processComments(self.returns)
172
173    'has_examples': return, obj_valid(self.examples)
174    'examples': return, self.system->processComments(self.examples)
175   
176    'has_author_info': return, self.hasAuthorInfo
177   
178    'has_author': return, obj_valid(self.author)
179    'author': return, self.system->processComments(self.author)
180
181    'has_copyright': return, obj_valid(self.copyright)
182    'copyright': return, self.system->processComments(self.copyright)
183   
184    'has_history': return, obj_valid(self.history)
185    'history': return, self.system->processComments(self.history)
186
187    'has_version': return, obj_valid(self.version)
188    'version': return, self.system->processComments(self.version)
189       
190    'has_others': return, self.hasOthers
191   
192    'has_bugs': return, obj_valid(self.bugs)
193    'bugs': return, self.system->processComments(self.bugs)
194
195    'has_pre': return, obj_valid(self.pre)
196    'pre': return, self.system->processComments(self.pre)
197   
198    'has_post': return, obj_valid(self.post)
199    'post': return, self.system->processComments(self.post)
200     
201    'has_customer_id': return, obj_valid(self.customerId)
202    'customer_id': return, self.system->processComments(self.customerId)
203
204    'has_todo': return, obj_valid(self.todo)
205    'todo': return, self.system->processComments(self.todo)
206
207    'has_restrictions': return, obj_valid(self.restrictions)
208    'restrictions': return, self.system->processComments(self.restrictions)
209                       
210    'n_parameters': return, self.parameters->count()
211    'parameters': return, self.parameters->get(/all)
212    'n_keywords': return, self.keywords->count()
213    'keywords': return, self.keywords->get(/all)
214    else: begin
215        ; search in the system object if the variable is not found here
216        var = self.file->getVariable(name, found=found)
217        if (found) then return, var
218       
219        found = 0B
220        return, -1L
221      end
222  endcase
223end
224
225
226;+
227; Uses file hidden/private attributes, system wide user/developer level, and
228; the status of the containing file to determine if this routine should be
229; visible.
230;
231; :Returns: boolean
232;-
233function doctreeroutine::isVisible
234  compile_opt strictarr
235
236  ; each routine in a not-visible file is not visible
237  if (~self.file->isVisible()) then return, 0B
238 
239  if (self.hidden) then return, 0B
240 
241  ; if creating user-level docs and private then not visible
242  self.system->getProperty, user=user
243  if (self.private && user) then return, 0B
244 
245  return, 1B
246end
247
248
249;+
250; Add a parameter to the list of parameters for this routine.
251;
252; :Params:
253;    `param` : in, required, type=object
254;       argument tree object
255;-
256pro doctreeroutine::addParameter, param
257  compile_opt strictarr
258 
259  self.parameters->add, param
260end
261
262
263function doctreeroutine::getParameter, name, found=found
264  compile_opt strictarr
265 
266  found = 1B
267  for i = 0L, self.parameters->count() - 1L do begin
268    p = self.parameters->get(position=i)
269    p->getProperty, name=n
270    if (strlowcase(name) eq strlowcase(n)) then return, p
271  endfor
272  found = 0B
273  return, -1L
274end
275
276
277;+
278; Add a keyword to the list of keywords for this routine.
279;
280; :Params:
281;    `keyword` : in, required, type=object
282;       argument tree object
283;-
284pro doctreeroutine::addKeyword, keyword
285  compile_opt strictarr
286 
287  self.keywords->add, keyword
288
289  ; special for properties
290  self.file->getProperty, is_class=isClass, class=class
291  if (self.isMethod && isClass) then begin
292 
293    keyword->getProperty, name=propertyName
294    if (strlowcase(propertyName) eq '_extra' or strlowcase(propertyName) eq '_ref_extra') then return
295    case 1 of
296      strlowcase(strmid(self.name, 10, /reverse_offset)) eq 'getproperty': begin
297          property = class->addProperty(propertyName)
298          property->setProperty, is_get=1B
299        end
300      strlowcase(strmid(self.name, 10, /reverse_offset)) eq 'setproperty': begin
301          property = class->addProperty(propertyName)
302          property->setProperty, is_set=1B
303        end
304      strlowcase(strmid(self.name, 3, /reverse_offset)) eq 'init': begin
305          property = class->addProperty(propertyName)
306          property->setProperty, is_init=1B
307        end
308      else:   ; just a normal keyword
309    endcase
310  endif 
311end
312
313
314function doctreeroutine::getKeyword, name, found=found
315  compile_opt strictarr
316
317  found = 1B
318  for i = 0L, self.keywords->count() - 1L do begin
319    k = self.keywords->get(position=i)
320    k->getProperty, name=n
321    if (strlowcase(name) eq strlowcase(n)) then return, k
322  endfor
323  found = 0B
324  return, -1L
325end
326
327
328;+
329; Mark first and last arguments of a routine. Needs to be called after parsing
330; the routine, but before the output is started.
331;-
332pro doctreeroutine::markArguments
333  compile_opt strictarr
334 
335  nArgs = self.parameters->count() + self.keywords->count()
336  if (nArgs le 0) then return
337 
338  arguments = objarr(nArgs)
339 
340  if (self.parameters->count() gt 0) then begin
341    arguments[0] = self.parameters->get(/all)
342  endif
343 
344  if (self.keywords->count() gt 0) then begin
345    arguments[self.parameters->count()] = self.keywords->get(/all)
346  endif
347
348  arguments[0]->setProperty, is_first=1B
349  arguments[n_elements(arguments) - 1L]->setProperty, is_last=1B
350end
351
352
353;+
354; Free resources.
355;-
356pro doctreeroutine::cleanup
357  compile_opt strictarr
358 
359  obj_destroy, [self.parameters, self.keywords, self.comments]
360  obj_destroy, [self.returns, self.bugs]
361  obj_destroy, [self.author, self.copyright, self.history, self.todo]
362  obj_destroy, [self.restrictions]
363end
364
365
366;+
367; Create a routine object.
368;
369; :Returns:
370;    1 for success, 0 for failure
371;
372; :Params:
373;    `file` : in, required, type=object
374;       file tree object
375;-
376function doctreeroutine::init, file, system=system
377  compile_opt strictarr
378 
379  self.file = file
380  self.system = system
381 
382  self.parameters = obj_new('MGcoArrayList', type=11)
383  self.keywords = obj_new('MGcoArrayList', type=11)
384 
385  return, 1B
386end
387
388
389;+
390; Define instance variables for routine class.
391;
392; :Fields:
393;    `file` file object containing this routine
394;    `name` string name of this routine
395;    `isFunction` true if this routine is a function
396;    `isMethod` true if this routine is a method of a class
397;    `parameters` list of parameter objects
398;    `keywords` list of keyword objects
399;    `comments` tree node hierarchy
400;-
401pro doctreeroutine__define
402  compile_opt strictarr
403 
404  define = { DOCtreeRoutine, $
405             system: obj_new(), $
406             file: obj_new(), $
407             
408             name: '', $
409             isFunction: 0B, $
410             isMethod: 0B, $
411             isAbstract: 0B, $
412             isObsolete: 0B, $
413             isHidden: 0B, $
414             isPrivate: 0B, $
415             
416             parameters: obj_new(), $
417             keywords: obj_new(), $
418             
419             comments: obj_new(), $
420             returns: obj_new(), $
421
422             examples: obj_new(), $
423             
424             hasAuthorInfo: 0B, $
425             author: obj_new(), $
426             copyright: obj_new(), $
427             history: obj_new(), $
428             version: obj_new(), $
429                         
430             hasOthers: 0B, $
431             bugs: obj_new(), $
432             pre: obj_new(), $
433             post: obj_new(), $             
434             customerId: obj_new(), $
435             todo: obj_new(), $
436             restrictions: obj_new() $             
437           }
438end
Note: See TracBrowser for help on using the browser.