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