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 var ret = new Gee.HashMap<string,GirObject>();
127 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
132 //cls.parseSignals(); // ?? needed for add handler..
133 //cls.parseMethods(); // ?? needed for ??..
134 //cls.parseConstructors(); // ?? needed for ??..
148 var ret = new Gee.HashMap<string,GirObject>();
154 //cls.overlayInterfaces(gir);
159 public string[] getInheritsFor(string ename)
162 var es = ename.split(".");
163 var gir = Gir.factory(es[0]);
165 var cls = gir.classes.get(es[1]);
169 return cls.inheritsToStringArray();
174 genParams: function(sig, meth)
178 meth.ret_type = this.typeToName(GIRepository.callable_info_get_return_type(sig));
179 // might be a numbeR??
181 for(var a_i =0; a_i < GIRepository.callable_info_get_n_args(sig); a_i++) {
182 var arg = GIRepository.callable_info_get_arg(sig, a_i);
185 name : arg.get_name(),
186 type : this.typeToName(arg.get_type(), true)
194 genSkel: function(sig) // should really use genParams...
198 var ret_type = this.typeToName(GIRepository.callable_info_get_return_type(sig));
199 // might be a numbeR??
200 if (ret_type == 'boolean') {
201 ret = " return false;\n";
203 for(var a_i =0; a_i < GIRepository.callable_info_get_n_args(sig); a_i++) {
204 var arg = GIRepository.callable_info_get_arg(sig, a_i);
206 args.push(arg.get_name());
208 return 'function (' + args.join(', ') + ") {\n" + ret + "}";
213 typeToName : function (type_info, allow_iface) // find type for properties or arguments.
215 var ty = GIRepository.type_tag_to_string( GIRepository.type_info_get_tag(type_info));
217 if ((ty == 'void') && GIRepository.type_info_is_pointer(type_info)) {
221 return false; // unspported
223 if (ty != 'interface') {
226 // we can accept enum types here..
227 var interface_info = GIRepository.type_info_get_interface(type_info);
228 var interface_type = interface_info.get_type();
230 if (!allow_iface && interface_type != GIRepository.InfoType.ENUM) {
233 return interface_info.get_namespace() + '.' + interface_info.get_name();
237 * merge two proprety arrays' ignoring what's overrriden.
242 overrides : function (top, bottom)
246 return !top.every(function(t) {
247 if (t.name == b.name) {
253 bottom.forEach(function(e) {
265 findType : function (data, prop, value)
268 if ((prop == '|xns') || (prop == 'xtype')) {
272 var qname = this.guessName(data);
273 if (prop[0] == '|') {
274 prop= prop.substring(1);
277 var prs = this.getPropertiesFor(qname, 'props');
279 prs.forEach(function(e) {
283 if (e.name == prop) {
289 return Base.prototype.findType(data, prop,value);
296 findOptions : function(ename)
299 var es = ename.split('.');
301 return Base.prototype.findOptions(ename);
303 var gi = GIRepository.Repository.get_default();
304 var bi = gi.find_by_name(es[0], es[1]);
305 var etype = GIRepository.object_info_get_type(bi);
306 if (etype != GIRepository.InfoType.ENUM) {
307 console.log("Options not handled yet!!!");
311 // got an enum.. let's return the values..
312 for(var i =0; i < bi.get_n_values(); i++) {
314 var prop = bi.get_value(i);
317 ret.push( ename + '.' + prop.get_name().toUpperCase() )
322 * determine the packing types..
324 getDefaultPack: function(pname, cname) {
325 var list = this.getPackingList(pname,cname);
326 // console.dump(list);
329 if (!list.every(function(e) { return e.name != 'add'; })) {
330 return 'add'; // add is in our list..?? what about args..?!?
334 e.params.forEach(function(p,i) {
335 if (ret === false) { return; } // skip broken..
336 if (i==0) { return; } // skip first..
337 if (p.type == 'boolean') {
341 if (p.type == 'number') {
345 if (p.type == 'uint') {
349 ret = false; // invalid!
351 return ret === false ? false : ret.join(',');
354 list.every(function(e) {
357 //print("DEFAULT PACK TEST : " + e.name + " : " +packret);
358 if (packret !== false) {
361 return true; // continue
363 //print("DEFAULT PACK: " + packret);
364 // should we do best match..?
370 getPackingList :function (pname, cname)
372 var funcs = this.getPropertiesFor(pname,'methods');
373 //print("getPackingList : ALL FUNCS");
374 //console.dump(funcs);
377 // let's assume top down...
378 var inherits = [ cname ];
379 inherits.push.apply(inherits, this.getPropertiesFor(cname,'inherits'));
380 funcs.forEach(function(m) {
381 if (m.params.length && (typeof(m.params[0].type) == 'string') &&
382 inherits.indexOf(m.params[0].type) > -1) {
390 public override void fillPack(JsRender.Node node,JsRender.Node parent)
393 string inherits = " " + string.joinv(" ", this.getInheritsFor (node.fqn()) + " ";
394 // parent.fqn() method ( node.fqn()
395 var methods = this.getPropertiesFor (parent.fqn());
397 var map = methods.map_iterator();
399 var n = map.get_key();
400 var meth = map.get_value();
401 if (meth.paramset == null || meth.paramset.params.length() < 1) {
404 var fp = meth.paramset.params.nth_data(0);
405 var type = this.fqtype(fp.type, meth.ns);
406 if (!inherits.contains(" " + type + " ")) {