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