Revert "File.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     var allchildren = [];  
72     
73     
74     for (cls in classes) {
75         var odata = classes[cls];
76         //methods[cls] = {}
77            
78         implementations[odata.alias] = odata.titleType == 'Class' ? odata.childClasses :  odata.implementedBy;  
79         //print(JSON.stringify(odata.methods,null,4));
80         odata.methods.forEach(function(m) {
81            
82             m.params.forEach(function(p) {
83                  
84                 if (!p.type || typeof(classes[p.type]) == 'undefined') {
85                     return;
86                 }
87                 // now add it..
88                 
89                 if (!p.type || typeof(classes[p.type]) == 'undefined') {
90                     return;
91                 }
92                 if (allchildren.indexOf(p.type) < 0) {
93                     allchildren.push(p.type);
94                 }
95                 
96                 if (typeof(methods[cls]) == 'undefined') {
97                     methods[cls] = {}
98                 }
99                 
100                 if (typeof(methods[cls][p.type]) == 'undefined') {
101                     methods[cls][p.type] = [];
102                 }
103                 var fullname = m.memberOf + '.' + m.name;
104                 if (allmethods.indexOf(fullname) < 0) {
105                     allmethods.push(fullname);
106                 }
107                 
108                 if (methods[cls][p.type].indexOf(fullname) > -1) {
109                     return;
110                 }
111                 methods[cls][p.type].push(fullname);
112                  
113                 
114                 
115             });
116             
117         });
118         //for(method in odata.methods) {
119         //    print(method.name);
120         //}
121         
122         
123     }
124     this.methods = methods;
125     this.allmethods = allmethods;
126     this.allchildren = allchildren;
127
128     this.implementations = implementations;
129     
130     //print(JSON.stringify(methods,null,4));
131     //print(JSON.stringify(implementations,null,4));
132     
133 }
134
135
136
137
138
139
140
141
142 // we now have a list of classes / methods that can be used..
143 // we now need a ui to flag stuff as "don't bother with"
144
145