generate gjs documentation, run under gjs
[gnome.introspection-doc-generator] / Introspect / Class.js
1 //<script type="text/javascript">
2 //Gtk = imports.gi.Gtk;
3 const GI      = imports.gi.GIRepository;
4 const GLib    = imports.gi.GLib;
5 //xml     = imports.libxml;
6 const xml     = imports.gi.libxml2;
7 //GObject = imports.gi.GObject;
8  
9  
10 const XObject = imports.XObject.XObject;
11 const console = imports.console.console;
12
13 const NameSpace = imports.Introspect.NameSpace.NameSpace;
14 const Base      = imports.Introspect.Base.Base;
15
16
17
18
19 /**
20  * Class
21  */
22
23
24
25
26 var Class = XObject.define(
27     function(ns, name) {
28         Base.call(this, ns, name);
29         print("Class ctr - parent called");
30         this.loadExtends();
31         this.loadImplements();
32         //console.log("CREATED(Class) " + this.alias);
33     },
34     Base, 
35     {
36         titleType : 'Class',
37         
38         loadExtends : function()
39         {
40             var bi = this.getBI();
41             
42             var pi = GI.object_info_get_parent(bi);
43             this.extendsClasses = [];
44             if (!pi || (pi.get_namespace() == this.ns && pi.get_name() == this.name )) {
45                 return;
46             } 
47             this.parent = NameSpace.factory(
48                 'Class',
49                 pi.get_namespace(),
50                 pi.get_name()
51             );
52             
53             this.extendsClasses = [ this.parent ];
54             
55             
56             this.parent.extendsClasses.map(function(p) {
57                 this.extendsClasses.push(p);
58             },this);
59             
60             if (this.parent) {
61                 this.parent.addChildClass(this.alias);
62             }
63             
64             
65         },
66         
67         addChildClass : function (n) {
68             this.childClasses.push(n);
69             if (this.parent) {
70                 this.parent.addChildClass(n);
71             }
72         },
73         
74         
75         loadImplements : function()
76         {
77             var bb = this.getBI();
78             this.implementInterfaces = [];
79             
80             var iflist = [];
81             for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
82                
83                 var prop = GI.object_info_get_interface(bb,i);
84                  
85                 
86                 var iface = NameSpace.factory(
87                     'Interface', 
88                     prop.get_namespace() , prop.get_name()
89                 );
90                 
91                 
92                 if (iflist.indexOf(iface.alias) < 0) {
93                     //console.log("ADDING IFACE " + iface.alias);
94                     iflist.push(iface.alias);
95                     this.implementInterfaces.push(iface);
96                 }
97             }
98             // ask the first of the parents.. - which will have it loaded already
99             if (this.extendsClasses.length) {
100                 
101                 //this.extendsClasses[0].loadImplements();
102                 
103                 this.extendsClasses[0].implementInterfaces.map( function(si) {
104                     
105                     if (iflist.indexOf(si.alias) < 0) {
106                         //console.log("From extends ("+ si.alias + ") IFACE " + si.alias);
107                         iflist.push(si.alias);
108                         this.implementInterfaces.push(si);
109                     }
110                 },this);
111                 
112             }
113             //console.dump(iflist);
114             if (this.alias == 'Atk.NoOpObject') {
115             //    throw "exut";
116                }
117            // console.dump(this.implementInterfaces);
118         },
119         
120         
121         
122         
123         load : function()
124         {
125             if (this._loaded) {
126                 return; // already loaded..
127             }
128             
129             if (this.parent) { // load up parents first
130                 this.parent.load();
131             }
132             this.implementInterfaces.map(function(iface) {
133                 iface.load();
134             });
135             
136             
137             //console.log("load(Class) " + this.alias);
138             // my props..
139             var props = [];
140             this.genericBuildList('object', 'property', props, 'properties');
141             this.genericBuildList('object', 'field', props, 'properties');
142
143             this.genericExtends(  props, 'properties');    
144             this.genericImplements( props, 'properties');    
145            
146             var signals = [];
147             this.genericBuildList('object', 'signal', signals, 'signals');
148             this.genericExtends(  signals, 'signals');    
149             this.genericImplements( signals, 'signals');    
150             
151             
152             NameSpace.references[this.alias] = NameSpace.references[this.alias] || [];
153             if (this.alias == 'GObject.Object') {
154                 this._loaded = true;
155                 return;
156             }
157             
158             
159             this.constructors.push({
160                 name : '', // not really...
161                 params:   this.properties.length ?  [ { type :  'Object', be_null :  true,  name : 'properties' } ] : [],
162                 returns :  [],
163                 isConstructor : true,
164                 isStatic : false,
165                 memberOf : this.alias,
166                 exceptions : [],
167                 // in theory..
168                 desc : ''
169             });
170             
171             
172             var methods = [];
173             this.genericBuildList('object', 'method', methods, 'methods');
174             // dont inherit functiosn or consturctors...
175             
176             this.genericExtends(  methods, 'methods');    
177             this.genericImplements( methods, 'methods');    
178             
179             
180             
181             //console.log("loaded(Class) " + this.alias);
182               
183             this._loaded  = true;
184         }
185          
186          
187         
188         
189         
190 });