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