JSDOC/Introspect/Base.js
[gnome.introspection-doc-generator] / JSDOC / Introspect / Base.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 XObject = imports.XObject.XObject;
9 console = imports.console.console;
10
11 NameSpace = imports.NameSpace.NameSpace;
12 Introspect = imports['JSDOC/Introspect.js'].Introspect;
13 Basic = imports['JSDOC/Introspect/Basic.js'].Basic;
14
15
16
17
18 /**
19  * Base  types methods/interfaces/structs/unions etc.
20  */
21
22
23
24  
25 Base = Object.define(
26    function(ns, name) {
27         // fake should not happen?
28         
29         
30         if (typeof(name) == 'undefined') {
31             var ar = ns.split('.');
32             ns = ar[0];
33             name = ar[1];
34         }
35         this.ns = ns;
36         this.name = name;
37         this.alias = ns + '.' + name;
38         //console.log("CREATE(Base) " + this.alias);
39         this._loaded = false;
40         
41         
42         // reset all of these..
43         this.signals = [];
44         this.methods = [];
45         this.constructors = [];
46         this.functions= [];
47        
48         this.values = []; // for enum;g;
49         this.constants = [];
50         
51         this.properties = [];
52         this.implementInterfaces = []; // obect - which interface it implements.
53         this.implementedBy = []; // interface - which object uses it.
54         this.extendsClasses = []; // what it extends...
55         this.childClasses = []; // what 
56          this.desc = NameSpace.doc(this.alias );
57         
58         
59         var gi = GI.IRepository.get_default();
60         var ver = gi.get_version(ns);
61         var pth = GI.IRepository.get_search_path ();
62         var gir_path = pth[0].replace(/lib\/girepository-1.0/, 'share\/gir-1.0');
63        //console.log(fn);
64         this.gir_file = gir_path + '/'+ ns + '-' + ver + '.gir';
65         this.gir_filename = ns + '-' + ver + '.gir';
66         
67         
68     }, 
69     Basic, 
70     {
71         titleType: 'Unknown',
72         name :  '',
73         ns : '',
74        
75         signals : [],
76         methods : [],
77         constructors : [],
78         functions: [],
79        
80         values : [], // for enum
81         constants : [],
82         
83         properties : [],
84         implementInterfaces : [], // obect - which interface it implements.
85         implementedBy : [], // interface - which object uses it.
86         extendsClasses : [], // what it extends...
87         childClasses : [], // what 
88         
89         
90         
91         
92         getBI : function()  {
93             
94             var gi = GI.IRepository.get_default();
95             return gi.find_by_name(this.ns, this.name);
96         },
97          // on, getwhat, simple list (name), variable to add to.
98         genericBuildList : function( onwhat, type, keylist, saveto)
99         {
100             
101             //console.log(this.alias +" - ADDING :" + type);
102             //if (this[saveto].length) {
103             //    Seed.print( "EROROR = it's alreayd loaded why?");
104                 //throw "oops";
105             //   }
106             var bb = this.getBI();
107             var _this = this;
108            //console.log("ADD " + type[0].toUpperCase() + type.substring(1));
109             var clname = type[0].toUpperCase() + type.substring(1);
110             var cls = imports[clname][clname];
111             if (!cls) {
112                 console.log("COULD NOT FIND Introspect: " + type[0].toUpperCase() + type.substring(1));
113                }
114                 
115             var plural = type + 's';
116             plural = plural == 'propertys' ? 'properties' : plural;
117             
118             
119             for(var i =0; i < GI[onwhat + '_info_get_n_' + plural ](bb); i++) {            
120                 var add= new cls(GI[onwhat + '_info_get_' + type ](bb,i), this, saveto, keylist);
121                 //console.log("CLS :" + this.alias + " EL: " + add.name);
122             }
123              
124             
125         },
126         // loop through and add stuff from extends..
127         genericExtends :  function(  keylist,  saveto)   
128         {
129             // do not overlay gobject props or methods etc.
130             
131             if (!this.extendsClasses.length) {
132                 return;
133             }
134             if (this.extendsClasses[0].alias == 'GObject.Object') {
135                 return;
136             }
137                 
138             
139             var _this = this;
140             
141             this.extendsClasses[0].load();
142             this.extendsClasses[0][saveto].map(function(prop) {
143                 if (keylist.indexOf(prop.name) < 0) {
144                     _this[saveto].push(prop);
145                     keylist.push(prop.name);
146                 }
147             },this);
148             
149         },
150         // loop through and add stuff from implements..
151         genericImplements :  function(  keylist,  saveto)   {
152         
153             var _this = this;
154             this.implementInterfaces.map(function(iface) {
155                 
156                 iface.load();
157                 
158                 iface[saveto].map( function(prop) {
159                     if (keylist.indexOf(prop.name) < 0) {
160                         _this[saveto].push(prop);
161                         keylist.push(prop.name);
162                     }
163                 },this);
164                 
165             }, this);
166             
167         },
168                 
169             
170         
171 });
172
173