9 public class Introspect.El : Object
23 public class Roo : Palete {
25 Gee.ArrayList<string> top_classes;
28 public Roo(Project.Project project)
35 this.top_classes = new Gee.ArrayList<string>();
38 Gee.HashMap<string,GirObject> propsFromJSONArray(string type, Json.Array ar, GirObject cls)
41 var ret = new Gee.HashMap<string,GirObject>();
43 for (var i =0 ; i < ar.get_length(); i++) {
44 var o = ar.get_object_element(i);
45 var name = o.get_string_member("name");
46 var prop = new GirObject(type, name );
48 prop.type = o.get_string_member("type");
49 prop.doctxt = o.get_string_member("desc");
50 prop.propertyof = o.has_member("memberOf") ? o.get_string_member("memberOf") : "";
51 if (prop.propertyof.length < 1) {
52 prop.propertyof = cls.name;
54 prop.sig = o.has_member("sig") ? o.get_string_member("sig") : "";
56 if (o.has_member("optvals") ) {
57 var oar = o.get_array_member("optvals");
59 for (var oi = 0; oi < oar.get_length(); oi++) {
60 prop.optvalues.add(oar.get_string_element(oi));
65 //print(type + ":" + name +"\n");
72 public override void load () {
74 if (this.classes != null) {
77 // this.loadUsageFile(BuilderApplication.configDirectory() + "/resources/RooUsage.txt");
78 this.classes = new Gee.HashMap<string,GirObject>();
79 var add_to = new Gee.HashMap<string,Gee.ArrayList<string>>();
81 var pa = new Json.Parser();
82 pa.load_from_file(BuilderApplication.configDirectory() + "/resources/roodata.json");
83 var node = pa.get_root();
85 var clist = node.get_object(); /// was in data... .get_object_member("data");
86 clist.foreach_member((o , key, value) => {
87 //print("cls:" + key+"\n");
89 var cls = new GirObject("class", key);
90 cls.props = this.propsFromJSONArray("prop", value.get_object().get_array_member("props"),cls);
91 cls.signals = this.propsFromJSONArray("signal", value.get_object().get_array_member("events"),cls);
94 if (value.get_object().has_member("methods")) {
95 cls.methods = this.propsFromJSONArray("method", value.get_object().get_array_member("methods"),cls);
97 if (value.get_object().has_member("implementations")) {
98 var vcn = value.get_object().get_array_member("implementations");
99 for (var i =0 ; i < vcn.get_length(); i++) {
100 cls.implementations.add(vcn.get_string_element(i));
106 if (value.get_object().has_member("tree_children")) {
107 var vcn = value.get_object().get_array_member("tree_children");
108 for (var i =0 ; i < vcn.get_length(); i++) {
109 var ad_c = vcn.get_string_element(i);
110 if (!cls.valid_cn.contains(ad_c)) {
111 cls.valid_cn.add( ad_c );
113 if (!add_to.has_key(ad_c)) {
114 add_to.set(ad_c, new Gee.ArrayList<string>());
116 if (!add_to.get(ad_c).contains(cls.name)) {
117 add_to.get(ad_c).add(cls.name);
127 if (value.get_object().has_member("tree_parent")) {
128 var vcn = value.get_object().get_array_member("tree_parent");
129 for (var i =0 ; i < vcn.get_length(); i++) {
130 if ("builder" == vcn.get_string_element(i)) {
131 // this class can be added to the top level.
132 GLib.debug("Add %s to *top", cls.name);
134 this.top_classes.add(cls.name);
141 this.classes.set(key, cls);
144 // look for properties of classes, that are atually clasess
145 // eg. Roo.data.Store has proxy and reader..
148 foreach(var cls in this.classes.values) {
149 foreach(var gir_obj in cls.props.values) {
150 var types = gir_obj.type.split("|");
151 for(var i =0; i < types.length; i++) {
154 if (/^Roo\./.match(type) && classes.has_key(type)) {
157 cls.valid_cn.add(type + ":" + gir_obj.name );
158 // Roo.bootstrap.panel.Content:east
159 // also means that Roo.bootstrap.panel.Grid:east works
160 var prop_type = classes.get(type);
161 foreach(var imp_str in prop_type.implementations) {
162 //GLib.debug("addChild for %s - child= %s:%s", cls.name, imp_str, gir_obj.name);
163 cls.valid_cn.add(imp_str + ":" + gir_obj.name);
164 if (!add_to.has_key(imp_str)) {
165 add_to.set( imp_str, new Gee.ArrayList<string>());
167 if (!add_to.get( imp_str).contains(cls.name)) {
168 add_to.get( imp_str ).add(cls.name );
174 if (!add_to.has_key( type)) {
175 add_to.set( type, new Gee.ArrayList<string>());
177 if (!add_to.get(type).contains(cls.name)) {
178 add_to.get( type ).add(cls.name );
185 foreach(var cls in this.classes.values) {
186 if (add_to.has_key(cls.name)) {
187 cls.can_drop_onto = add_to.get(cls.name);
194 public string doc(string what) {
196 /*var ns = what.split(".")[0];
201 var gir = Gir.factory(ns);
202 return gir.doc(what);
205 //return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
208 // does not handle implements...
209 public override GirObject? getClass(string ename)
212 return this.classes.get(ename);
216 public override Gee.HashMap<string,GirObject> getPropertiesFor(string ename, string type)
218 //print("Loading for " + ename);
222 // if (typeof(this.proplist[ename]) != 'undefined') {
223 //print("using cache");
224 // return this.proplist[ename][type];
226 // use introspection to get lists..
229 var cls = this.classes.get(ename);
230 var ret = new Gee.HashMap<string,GirObject>();
232 print("could not find class: %s\n", ename);
234 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
239 //cls.parseSignals(); // ?? needed for add handler..
240 //cls.parseMethods(); // ?? needed for ??..
241 //cls.parseConstructors(); // ?? needed for ??..
243 //cls.overlayParent();
257 throw new Error.INVALID_VALUE( "getPropertiesFor called with: " + type);
258 //var ret = new Gee.HashMap<string,GirObject>();
264 //cls.overlayInterfaces(gir);
269 public string[] getInheritsFor(string ename)
272 var es = ename.split(".");
273 var gir = Gir.factory(null, es[0]);
275 var cls = gir.classes.get(es[1]);
279 return cls.inheritsToStringArray();
285 public override void fillPack(JsRender.Node node,JsRender.Node parent)
291 * Pulldown options for type
293 public override bool typeOptions(string fqn, string key, string type, out string[] opts)
296 print("get typeOptions %s (%s)%s", fqn, type, key);
297 if (type.up() == "BOOL" || type.up() == "BOOLEAN") {
298 opts = { "true", "false" };
302 var props = this.getPropertiesFor(fqn, "props");
303 if (!props.has_key(key)) {
304 print("prop %s does not have key %s\n", fqn, key);
307 var pr = props.get(key);
308 if (pr.optvalues.size < 1) {
309 print("prop %s no optvalues for %s\n", fqn, key);
313 for(var i = 0; i < pr.optvalues.size; i++) {
314 ret += pr.optvalues.get(i);
317 print("prop %s returning optvalues for %s\n", fqn, key);
321 public override List<SourceCompletionItem> suggestComplete(
322 JsRender.JsRender file,
326 string complete_string
329 var ret = new List<SourceCompletionItem>();
330 // completion rules??
334 // this. (based on the node type)
335 // this.xxx // Node and any determination...
337 if (complete_string.index_of(".",0) < 0) {
338 // string does not have a '.'
339 // offer up this / Roo / javascript keywords... / look for var string = .. in the code..
340 for(var i = 0; i < JsRender.Lang.match_strings.size ; i++) {
341 var str = JsRender.Lang.match_strings.get(i);
342 if (complete_string != str && str.index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
343 ret.append(new SourceCompletionItem (str, str, null, "javascript : " + str));
348 if (complete_string != "Roo" && "Roo".index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
349 ret.append(new SourceCompletionItem ("Roo - A Roo class", "Roo", null, "Roo library"));
351 if (complete_string != "_this" && "_this".index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
352 ret.append(new SourceCompletionItem ("_this - the top level element", "_this", null, "Top level element"));
356 // got at least one ".".
357 var parts = complete_string.split(".");
359 var cur_instance = false;
360 if (parts[0] == "this") {
361 // work out from the node, what the type is...
363 print("node is empty - no return\n");
364 return ret; // no idea..
366 curtype = node.fqn();
369 if (parts[0] == "Roo") {
371 cur_instance = false;
374 var prevbits = parts[0] + ".";
375 for(var i =1; i < parts.length; i++) {
376 print("matching %d/%d\n", i, parts.length);
377 var is_last = i == parts.length -1;
379 // look up all the properties of the type...
380 var cls = this.getClass(curtype);
382 print("could not get class of curtype %s\n", curtype);
388 // only exact matches from here on...
390 if (cls.props.has_key(parts[i])) {
391 var prop = cls.props.get(parts[i]);
392 if (prop.type.index_of(".",0) > -1) {
393 // type is another roo object..
395 prevbits += parts[i] + ".";
403 // check methods?? - we do not export that at present..
404 return ret; //no idea...
408 //look for child classes.
409 var citer = this.classes.map_iterator();
411 while (citer.next()) {
412 var scls = citer.get_key();
413 var look = prevbits + parts[i];
414 if (scls.index_of(look,0) != 0) {
417 // got a starting match..
419 cur_instance = false;
426 prevbits += parts[i] + ".";
429 // got to the last element..
430 print("Got last element\n");
431 if (curtype == "") { // should not happen.. we would have returned already..
434 print("Got last element type %s\n",curtype);
436 print("matching instance");
437 // it's a static reference..
438 var citer = this.classes.map_iterator();
439 while (citer.next()) {
440 var scls = citer.get_key();
441 var look = prevbits + parts[i];
442 if (parts[i].length > 0 && scls.index_of(look,0) != 0) {
445 // got a starting match..
446 ret.append(new SourceCompletionItem (
454 print("matching property");
458 var citer = cls.methods.map_iterator();
459 while (citer.next()) {
460 var prop = citer.get_value();
461 // does the name start with ...
462 if (parts[i].length > 0 && prop.name.index_of(parts[i],0) != 0) {
465 // got a matching property...
467 ret.append(new SourceCompletionItem (
468 prop.name + prop.sig + " : ("+ prop.propertyof + ")",
469 prevbits + prop.name + "(",
474 // get the properties / methods and subclasses.. of cls..
475 // we have cls.. - see if the string matches any of the properties..
476 citer = cls.props.map_iterator();
477 while (citer.next()) {
478 var prop = citer.get_value();
479 // does the name start with ...
480 if (parts[i].length > 0 && prop.name.index_of(parts[i],0) != 0) {
483 // got a matching property...
485 ret.append(new SourceCompletionItem (
486 prop.name + " : " + prop.type + " ("+ prop.propertyof + ")",
487 prevbits + prop.name,
508 public override string[] getChildList(string in_rval)
510 if (this.top_classes.size < 1) {
516 var ar = this.top_classes;
517 if (in_rval != "*top") {
518 if (this.classes.has_key(in_rval)) {
519 // some of these children will be eg: Roo.bootstrap.layout.Region:center
520 ar = this.classes.get(in_rval).valid_cn;
522 ar = new Gee.ArrayList<string>();
526 foreach(var str in ar) {
529 GLib.debug("getChildList for %s returns %s", in_rval, string.joinv(", ", ret));
532 //return this.original_getChildList( in_rval);
534 public override string[] getDropList(string rval)
536 // we might be dragging Roo.bootstrap.layout.Region:center
537 // in which case we need to lookup Roo.bootstrap.layout.Region
538 // and see if it's has can_drop_onto
540 var cls = this.classes.get(rval);
542 if (cls == null && rval.contains(":")) {
543 var rr = rval.substring(0,rval.index_of(":"));
544 GLib.debug("Converted classname to %s", rr);
545 cls = this.classes.get(rr);
548 return ret; //nothing..
551 foreach(var str in cls.can_drop_onto) {
555 GLib.debug("getDropList for %s return[] %s", rval, string.joinv(", ", ret));
560 //return this.default_getDropList(rval);