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