Merge branch 'master' into live
[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 JSDOC   = imports['JSDOC.js'].JSDOC;
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     }, 
60     Basic, 
61     {
62         titleType: 'Unknown',
63         name :  '',
64         ns : '',
65        
66         signals : [],
67         methods : [],
68         constructors : [],
69         functions: [],
70        
71         values : [], // for enum
72         constants : [],
73         
74         properties : [],
75         implementInterfaces : [], // obect - which interface it implements.
76         implementedBy : [], // interface - which object uses it.
77         extendsClasses : [], // what it extends...
78         childClasses : [], // what 
79         
80         
81         
82         
83         getBI : function()  {
84             
85             var gi = GI.IRepository.get_default();
86             return gi.find_by_name(this.ns, this.name);
87         },
88          // on, getwhat, simple list (name), variable to add to.
89         genericBuildList : function( onwhat, type, keylist, saveto)
90         {
91             
92             //console.log(this.alias +" - ADDING :" + type);
93             //if (this[saveto].length) {
94             //    Seed.print( "EROROR = it's alreayd loaded why?");
95                 //throw "oops";
96             //   }
97             var bb = this.getBI();
98             var _this = this;
99            //console.log("ADD " + type[0].toUpperCase() + type.substring(1));
100             var cls = Introspect[type[0].toUpperCase() + type.substring(1)]; // ucfirst.
101             if (!cls) {
102                 console.log("COULD NOT FIND Introspect: " + type[0].toUpperCase() + type.substring(1));
103                }
104                 
105             var plural = type + 's';
106             plural = plural == 'propertys' ? 'properties' : plural;
107             
108             
109             for(var i =0; i < GI[onwhat + '_info_get_n_' + plural ](bb); i++) {            
110                 var add= new cls(GI[onwhat + '_info_get_' + type ](bb,i), this, saveto, keylist);
111                 //console.log("CLS :" + this.alias + " EL: " + add.name);
112             }
113              
114             
115         },
116         // loop through and add stuff from extends..
117         genericExtends :  function(  keylist,  saveto)   
118         {
119             // do not overlay gobject props or methods etc.
120             
121             if (!this.extendsClasses.length) {
122                 return;
123             }
124             if (this.extendsClasses[0].alias == 'GObject.Object') {
125                 return;
126             }
127                 
128             
129             var _this = this;
130             
131             this.extendsClasses[0].load();
132             this.extendsClasses[0][saveto].map(function(prop) {
133                 if (keylist.indexOf(prop.name) < 0) {
134                     _this[saveto].push(prop);
135                     keylist.push(prop.name);
136                 }
137             },this);
138             
139         },
140         // loop through and add stuff from implements..
141         genericImplements :  function(  keylist,  saveto)   {
142         
143             var _this = this;
144             this.implementInterfaces.map(function(iface) {
145                 
146                 iface.load();
147                 
148                 iface[saveto].map( function(prop) {
149                     if (keylist.indexOf(prop.name) < 0) {
150                         _this[saveto].push(prop);
151                         keylist.push(prop.name);
152                     }
153                 },this);
154                 
155             }, this);
156             
157         },
158                 
159             
160         
161 });
162
163