8a2bd2689c3bcb85581f34812df9ee341b9eb8fd
[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 imports['Object.js'].load(Object);
9
10 console = imports['console.js'].console;
11
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 = Introspect.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 cls = Introspect[type[0].toUpperCase() + type.substring(1)]; // ucfirst.
110             if (!cls) {
111                 console.log("COULD NOT FIND Introspect: " + type[0].toUpperCase() + type.substring(1));
112                }
113                 
114             var plural = type + 's';
115             plural = plural == 'propertys' ? 'properties' : plural;
116             
117             
118             for(var i =0; i < GI[onwhat + '_info_get_n_' + plural ](bb); i++) {            
119                 var add= new cls(GI[onwhat + '_info_get_' + type ](bb,i), this, saveto, keylist);
120                 //console.log("CLS :" + this.alias + " EL: " + add.name);
121             }
122              
123             
124         },
125         // loop through and add stuff from extends..
126         genericExtends :  function(  keylist,  saveto)   
127         {
128             // do not overlay gobject props or methods etc.
129             
130             if (!this.extendsClasses.length) {
131                 return;
132             }
133             if (this.extendsClasses[0].alias == 'GObject.Object') {
134                 return;
135             }
136                 
137             
138             var _this = this;
139             
140             this.extendsClasses[0].load();
141             this.extendsClasses[0][saveto].map(function(prop) {
142                 if (keylist.indexOf(prop.name) < 0) {
143                     _this[saveto].push(prop);
144                     keylist.push(prop.name);
145                 }
146             },this);
147             
148         },
149         // loop through and add stuff from implements..
150         genericImplements :  function(  keylist,  saveto)   {
151         
152             var _this = this;
153             this.implementInterfaces.map(function(iface) {
154                 
155                 iface.load();
156                 
157                 iface[saveto].map( function(prop) {
158                     if (keylist.indexOf(prop.name) < 0) {
159                         _this[saveto].push(prop);
160                         keylist.push(prop.name);
161                     }
162                 },this);
163                 
164             }, this);
165             
166         },
167                 
168             
169         
170 });
171
172