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             this.parent.childClasses.push(this.alias);
60             
61             
62         },
63         loadImplements : function()
64         {
65             var bb = this.getBI();
66             this.implementInterfaces = [];
67             
68             var iflist = [];
69             for(var i =0; i < GI.object_info_get_n_interfaces(bb); i++) {
70                
71                 var prop = GI.object_info_get_interface(bb,i);
72                  
73                 
74                 var iface = NameSpace.factory(
75                     'Interface', 
76                     prop.get_namespace() , prop.get_name()
77                 );
78                 
79                 
80                 if (iflist.indexOf(iface.alias) < 0) {
81                     //console.log("ADDING IFACE " + iface.alias);
82                     iflist.push(iface.alias);
83                     this.implementInterfaces.push(iface);
84                 }
85             }
86             // ask the first of the parents.. - which will have it loaded already
87             if (this.extendsClasses.length) {
88                 
89                 //this.extendsClasses[0].loadImplements();
90                 
91                 this.extendsClasses[0].implementInterfaces.map( function(si) {
92                     
93                     if (iflist.indexOf(si.alias) < 0) {
94                         //console.log("From extends ("+ si.alias + ") IFACE " + si.alias);
95                         iflist.push(si.alias);
96                         this.implementInterfaces.push(si);
97                     }
98                 },this);
99                 
100             }
101             //console.dump(iflist);
102             if (this.alias == 'Atk.NoOpObject') {
103             //    throw "exut";
104                }
105            // console.dump(this.implementInterfaces);
106         },
107         
108         
109         
110         
111         load : function()
112         {
113             if (this._loaded) {
114                 return; // already loaded..
115             }
116             
117             if (this.parent) { // load up parents first
118                 this.parent.load();
119             }
120             this.implementInterfaces.map(function(iface) {
121                 iface.load();
122             });
123             
124             
125             //console.log("load(Class) " + this.alias);
126             // my props..
127             var props = [];
128             this.genericBuildList('object', 'property', props, 'properties');
129             this.genericBuildList('object', 'field', props, 'properties');
130
131             this.genericExtends(  props, 'properties');    
132             this.genericImplements( props, 'properties');    
133            
134             var signals = [];
135             this.genericBuildList('object', 'signal', signals, 'signals');
136             this.genericExtends(  signals, 'signals');    
137             this.genericImplements( signals, 'signals');    
138             
139             
140             NameSpace.references[this.alias] = NameSpace.references[this.alias] || [];
141             if (this.alias == 'GObject.Object') {
142                 this._loaded = true;
143                 return;
144             }
145             
146             
147             this.constructors.push({
148                 name : '', // not really...
149                 params:   this.properties.length ?  [ { type :  'Object', be_null :  true,  name : 'properties' } ] : [],
150                 returns :  [],
151                 isConstructor : true,
152                 isStatic : false,
153                 memberOf : this.alias,
154                 exceptions : [],
155                 // in theory..
156                 desc : ''
157             });
158             
159             
160             var methods = [];
161             this.genericBuildList('object', 'method', methods, 'methods');
162             // dont inherit functiosn or consturctors...
163             
164             this.genericExtends(  methods, 'methods');    
165             this.genericImplements( methods, 'methods');    
166             
167             
168             
169             //console.log("loaded(Class) " + this.alias);
170               
171             this._loaded  = true;
172         }
173          
174          
175         
176         
177         
178 });