JSDOC/Walker2.js
[gnome.introspection-doc-generator] / Introspect / Method.js
1 //<script type="text/javascript">
2
3 GI      = imports.gi.GIRepository;
4
5
6 XObject     = imports.XObject.XObject;
7 console     = imports.console.console;
8 NameSpace   = imports.NameSpace.NameSpace;
9
10 Basic        = imports.Basic.Basic;
11
12   
13 /**
14  * Methods, functions or consturctors
15  */
16
17
18
19
20 Method = XObject.define(
21     function(m, memberOf, saveto, keylist) {
22         this.propertyType  = 'Method';
23         
24         var flags = GI.function_info_get_flags (m);
25         var n = GI.base_info_get_name(m);
26         var n_original = n + '';
27         // posibly add: sink, 
28         if (n.match(/_(ref|unref)$/) || n.match(/^(ref|unref|weakref|weakunref)$/)) {
29             return false; // skip these!
30         }
31         
32         if (n == 'new') {
33             n = 'c_new';
34         }
35
36         
37         var retval = [ { 
38                 name : 0, 
39                 type :  this.typeToName(GI.callable_info_get_return_type(m)),
40                 desc : NameSpace.doc(memberOf.alias + '.' + n_original + '.return-value')
41         } ];
42         
43         
44         
45         var args = this.argsToArrays(m, retval);
46         
47         
48         if ((n == 'c_new') && !args.length && memberOf.constructors.length) {
49             
50             memberOf.constructors[0].doc = NameSpace.doc(memberOf.alias + '.' + n_original);
51             
52             return false; // skip.
53         }
54         
55
56         
57         
58         
59         //console.log(GI.base_info_get_name(m));
60        // console.dump(GI.base_info_get_attribute(m, 'doc') );
61        
62          // this is a bit messy, as we probably loose the doc's on new..
63        
64         
65         XObject.extend(this, {
66             name : n,
67             params: args,
68             returns :  retval,
69             isConstructor : flags & GI.IFunctionInfoFlags.IS_CONSTRUCTOR,
70             isStatic : !(flags & GI.IFunctionInfoFlags.IS_METHOD),
71             memberOf : memberOf.alias,
72             exceptions : [],
73             desc : NameSpace.doc(memberOf.alias + '.' + n_original)
74         });
75         // add descriptions to the arguments..
76         this.params.map(function(p) {
77             
78             
79             p.desc = NameSpace.doc(memberOf.alias + '.' + n_original + '.' + p.name);
80             //Seed.print(memberOf.alias + '.' + n_original + '.' + p.name + ':' +  p.desc);
81             
82         });
83         
84         
85             // collect references...
86         var addedto = [ memberOf.alias ]; // do not add to self...
87        
88          for(var i =0; i < args.length;i++) {
89             var ty = args[i].type;
90             if (typeof(ty) != 'string' || ty.indexOf('.') < 0) {
91                 continue;
92             }
93             if (addedto.indexOf(ty) > -1) {
94                 continue;
95             }
96             
97             
98             
99             NameSpace.references[ty] = NameSpace.references[ty] || [];
100             NameSpace.references[ty].push(this);
101             addedto.push(ty);
102         }
103         
104         
105          // decide what to add to...
106          
107         if (this.isConstructor) {
108             
109             if (this.name.match(/^new_/)) {
110                 this.name = this.name.substring(4);
111             }
112             
113             
114             memberOf.constructors.push(this);
115             return;
116         }
117         // return values  = only applicable to non-constructors..
118         for(var i =0; i < retval.length;i++) {
119             var ty = retval[i].type;
120             if (typeof(ty) != 'string' || ty.indexOf('.') < 0) {
121                 continue;
122             }
123             if (addedto.indexOf(ty) > -1) {
124                 continue;
125             }
126             
127             
128             
129             NameSpace.references[ty] = NameSpace.references[ty] || [];
130             NameSpace.references[ty].push(this);
131             addedto.push(ty);
132         }
133         
134         
135         if (this.isStatic) {
136             
137             memberOf.functions.push(this);
138             return;
139         }
140             
141             
142         memberOf.methods.push(this);
143         keylist.push(this.name);
144             
145         
146             
147     },
148     Basic, 
149     { }
150 );