DependTree/BuildLists.js
[app.Builder.js] / DependTree / BuildLists.js
1 //<script type="text/javascript">
2
3
4 /**
5  * usage:
6  * 
7  * this.data = new BuildLists();
8  * 
9  * 
10  * 
11  * 
12  * 
13  */
14 // see if we can build the insertion tree for gtk - using introspection
15
16 // it should build the tree of feasible insertions, then we will have to manually prune it..
17
18 // it needs to know
19 // a) what the inherited types are
20 // b) what methods are available for each type, that include a reference to another type..
21
22 // let's start with types.. 
23 GIRepository = imports.gi.GIRepository;
24 GLib        = imports.gi.GLib;
25
26 // we add this in, as it appears to get lost sometimes if we set it using the ENV. variable in builder.sh
27 GIRepository.IRepository.prepend_search_path(GLib.get_home_dir() + '/.Builder/girepository-1.1');
28
29
30 imports.searchPath.push('../gnome.introspection-doc-generator');
31
32 XObject     = imports.XObject.XObject;
33 File        = imports.File.File; 
34  
35 // Introspecion specific..
36 NameSpace   = imports.Introspect.NameSpace.NameSpace; 
37  
38
39
40 function BuildLists () {
41  
42
43     var ns_list = [ 'Gtk' ] ; //NameSpace.namespaces();
44      
45     ns_list = ns_list.sort();
46     // let's try and load them, so we find out early what will fail.
47     print("loading library to make sure it works.");
48
49     var classes = {};
50
51     ns_list.forEach(function(ns_name) {   
52         var  core = imports.gi[ns_name];
53         var ns = NameSpace.ns(ns_name); // fetch all the elements in namespace...
54         ns['objects'].forEach( function(n) {
55             var odata = NameSpace.factory('Class', ns_name, n);
56             classes[odata.alias] = odata;
57             
58         });
59         ns['interfaces'].forEach( function(n) {
60              var odata =NameSpace.factory('Interface', ns_name, n);
61             classes[odata.alias] = odata;
62         });
63     });
64
65
66     print("Looping throught namespaces");
67     var ns_idx = [];
68     var implementations = {};
69     var methods = {};
70     var allmethods = [];  
71     
72     for (cls in classes) {
73         var odata = classes[cls];
74         methods[cls] = {}
75            
76         implementations[odata.alias] = odata.titleType == 'Class' ? odata.childClasses :  odata.implementedBy;  
77         //print(JSON.stringify(odata.methods,null,4));
78         odata.methods.forEach(function(m) {
79            
80             m.params.forEach(function(p) {
81                  
82                 if (!p.type || typeof(classes[p.type]) == 'undefined') {
83                     return;
84                 }
85                 // now add it..
86                 
87                 if (!p.type || typeof(classes[p.type]) == 'undefined') {
88                     return;
89                 }
90                 if (typeof(methods[cls][p.type]) == 'undefined') {
91                     methods[cls][p.type] = [];
92                 }
93                 var fullname = m.memberOf + '.' + m.name;
94                 if (allmethods.indexOf(fullname) < 0) {
95                     allmethods.push(fullname);
96                 }
97                 
98                 if (methods[cls][p.type].indexOf(fullname) > -1) {
99                     return;
100                 }
101                 methods[cls][p.type].push(fullname);
102                  
103                 
104                 
105             });
106             
107         });
108         //for(method in odata.methods) {
109         //    print(method.name);
110         //}
111         
112         
113     }
114     this.methods = methods;
115     this.allmethods = methods;
116     this.implementations = implementations;
117     //print(JSON.stringify(methods,null,4));
118     //print(JSON.stringify(implementations,null,4));
119     
120 }
121
122
123 // we now have a list of classes / methods that can be used..
124 // we now need a ui to flag stuff as "don't bother with"
125
126