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