7 public class Introspect.El : Object
21 public class Gtk : Palete {
32 // various loader methods..
36 //this.comments = { };
44 if (!FileUtils.test ("/usr/share/appBuilder/GtkUsage.txt", FileTest.EXISTS)) {
45 throw new Error.MISSING_FILE("/usr/share/appBuilder/GtkUsage.txt not found");
49 FileUtils.get_contents("/usr/share/appBuilder/GtkUsage.txt", out raw);
51 var data = raw.split("\n");
53 var cfg = new GLib.List<Usage>();
54 var left = new GLib.List<string>();
55 var right = new GLib.List<string>();
57 for (var i = 0; i < data.length; i++) {
62 Regex.match_simple ("^\\s+$", d)
64 Regex.match_simple ("^\\s*/", d)
69 if (Regex.match_simple ("^left:", d)) {
71 if (left.length() > 0 ){
73 cfg.append(new Usage( left, right));
75 left = new GLib.List<string>();
76 right = new GLib.List<string>();
79 if (Regex.match_simple ("^right:", d)) {
84 left.append(d.strip());
87 right.append(d.strip());
91 if (left.length() > 0 ){
92 cfg.append(new Usage( left, right));
94 this.map = cfg.copy();
98 public string doc(string what) {
99 var ns = what.split(".")[0];
100 var gir = Gir.factory(ns);
101 return gir.doc(what);
103 //return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
106 // does not handle implements...
108 public Gee.HashMap<string,GirObject>? getPropertiesFor(string ename, string type)
110 //print("Loading for " + ename);
114 // if (typeof(this.proplist[ename]) != 'undefined') {
115 //print("using cache");
116 // return this.proplist[ename][type];
118 // use introspection to get lists..
120 var es = ename.split(".");
121 var gir = Gir.factory(es[0]);
123 var cls = gir.classes.get(es[1]);
125 throw new Error.INVALID_VALUE( "Could not find class: " + ename);
130 //cls.parseSignals(); // ?? needed for add handler..
131 //cls.parseMethods(); // ?? needed for ??..
132 //cls.parseConstructors(); // ?? needed for ??..
150 //cls.overlayInterfaces(gir);
157 genParams: function(sig, meth)
161 meth.ret_type = this.typeToName(GIRepository.callable_info_get_return_type(sig));
162 // might be a numbeR??
164 for(var a_i =0; a_i < GIRepository.callable_info_get_n_args(sig); a_i++) {
165 var arg = GIRepository.callable_info_get_arg(sig, a_i);
168 name : arg.get_name(),
169 type : this.typeToName(arg.get_type(), true)
177 genSkel: function(sig) // should really use genParams...
181 var ret_type = this.typeToName(GIRepository.callable_info_get_return_type(sig));
182 // might be a numbeR??
183 if (ret_type == 'boolean') {
184 ret = " return false;\n";
186 for(var a_i =0; a_i < GIRepository.callable_info_get_n_args(sig); a_i++) {
187 var arg = GIRepository.callable_info_get_arg(sig, a_i);
189 args.push(arg.get_name());
191 return 'function (' + args.join(', ') + ") {\n" + ret + "}";
196 typeToName : function (type_info, allow_iface) // find type for properties or arguments.
198 var ty = GIRepository.type_tag_to_string( GIRepository.type_info_get_tag(type_info));
200 if ((ty == 'void') && GIRepository.type_info_is_pointer(type_info)) {
204 return false; // unspported
206 if (ty != 'interface') {
209 // we can accept enum types here..
210 var interface_info = GIRepository.type_info_get_interface(type_info);
211 var interface_type = interface_info.get_type();
213 if (!allow_iface && interface_type != GIRepository.InfoType.ENUM) {
216 return interface_info.get_namespace() + '.' + interface_info.get_name();
220 * merge two proprety arrays' ignoring what's overrriden.
225 overrides : function (top, bottom)
229 return !top.every(function(t) {
230 if (t.name == b.name) {
236 bottom.forEach(function(e) {
248 findType : function (data, prop, value)
251 if ((prop == '|xns') || (prop == 'xtype')) {
255 var qname = this.guessName(data);
256 if (prop[0] == '|') {
257 prop= prop.substring(1);
260 var prs = this.getPropertiesFor(qname, 'props');
262 prs.forEach(function(e) {
266 if (e.name == prop) {
272 return Base.prototype.findType(data, prop,value);
279 findOptions : function(ename)
282 var es = ename.split('.');
284 return Base.prototype.findOptions(ename);
286 var gi = GIRepository.Repository.get_default();
287 var bi = gi.find_by_name(es[0], es[1]);
288 var etype = GIRepository.object_info_get_type(bi);
289 if (etype != GIRepository.InfoType.ENUM) {
290 console.log("Options not handled yet!!!");
294 // got an enum.. let's return the values..
295 for(var i =0; i < bi.get_n_values(); i++) {
297 var prop = bi.get_value(i);
300 ret.push( ename + '.' + prop.get_name().toUpperCase() )
305 * determine the packing types..
307 getDefaultPack: function(pname, cname) {
308 var list = this.getPackingList(pname,cname);
309 // console.dump(list);
312 if (!list.every(function(e) { return e.name != 'add'; })) {
313 return 'add'; // add is in our list..?? what about args..?!?
317 e.params.forEach(function(p,i) {
318 if (ret === false) { return; } // skip broken..
319 if (i==0) { return; } // skip first..
320 if (p.type == 'boolean') {
324 if (p.type == 'number') {
328 if (p.type == 'uint') {
332 ret = false; // invalid!
334 return ret === false ? false : ret.join(',');
337 list.every(function(e) {
340 //print("DEFAULT PACK TEST : " + e.name + " : " +packret);
341 if (packret !== false) {
344 return true; // continue
346 //print("DEFAULT PACK: " + packret);
347 // should we do best match..?
353 getPackingList :function (pname, cname)
355 var funcs = this.getPropertiesFor(pname,'methods');
356 //print("getPackingList : ALL FUNCS");
357 //console.dump(funcs);
360 // let's assume top down...
361 var inherits = [ cname ];
362 inherits.push.apply(inherits, this.getPropertiesFor(cname,'inherits'));
363 funcs.forEach(function(m) {
364 if (m.params.length && (typeof(m.params[0].type) == 'string') &&
365 inherits.indexOf(m.params[0].type) > -1) {