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