JSDOC/ScopeParser.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.IRepository.get_default();
59         var ver = gi.get_version(ns);
60         var pth = GI.IRepository.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     }, 
68     Basic, 
69     {
70         titleType: 'Unknown',
71         name :  '',
72         ns : '',
73        
74         signals : [],
75         methods : [],
76         constructors : [],
77         functions: [],
78        
79         values : [], // for enum
80         constants : [],
81         
82         properties : [],
83         implementInterfaces : [], // obect - which interface it implements.
84         implementedBy : [], // interface - which object uses it.
85         extendsClasses : [], // what it extends...
86         childClasses : [], // what 
87         
88         
89         
90         
91         getBI : function()  {
92             
93             var gi = GI.IRepository.get_default();
94             return gi.find_by_name(this.ns, this.name);
95         },
96          // on, getwhat, simple list (name), variable to add to.
97         genericBuildList : function( onwhat, type, keylist, saveto)
98         {
99             
100             //console.log(this.alias +" - ADDING :" + type);
101             //if (this[saveto].length) {
102             //    Seed.print( "EROROR = it's alreayd loaded why?");
103                 //throw "oops";
104             //   }
105             var bb = this.getBI();
106             var _this = this;
107            //console.log("ADD " + type[0].toUpperCase() + type.substring(1));
108             var clname = type[0].toUpperCase() + type.substring(1);
109             var cls = imports[clname][clname];
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