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;
55 // this is the function default.
56 prop.sig = o.has_member("sig") ? o.get_string_member("sig") : "";
58 if (o.has_member("optvals") ) {
59 var oar = o.get_array_member("optvals");
61 for (var oi = 0; oi < oar.get_length(); oi++) {
62 prop.optvalues.add(oar.get_string_element(oi));
67 //print(type + ":" + name +"\n");
74 public override void load () {
76 if (this.classes != null) {
79 // this.loadUsageFile(BuilderApplication.configDirectory() + "/resources/RooUsage.txt");
80 this.classes = new Gee.HashMap<string,GirObject>();
81 var add_to = new Gee.HashMap<string,Gee.ArrayList<string>>();
83 var pa = new Json.Parser();
84 pa.load_from_file(BuilderApplication.configDirectory() + "/resources/roodata.json");
85 var node = pa.get_root();
87 var clist = node.get_object(); /// was in data... .get_object_member("data");
88 clist.foreach_member((o , key, value) => {
89 //print("cls:" + key+"\n");
91 var cls = new GirObject("class", key);
92 cls.props = this.propsFromJSONArray("prop", value.get_object().get_array_member("props"),cls);
93 cls.signals = this.propsFromJSONArray("signal", value.get_object().get_array_member("events"),cls);
96 if (value.get_object().has_member("methods")) {
97 cls.methods = this.propsFromJSONArray("method", value.get_object().get_array_member("methods"),cls);
99 if (value.get_object().has_member("implementations")) {
100 var vcn = value.get_object().get_array_member("implementations");
101 for (var i =0 ; i < vcn.get_length(); i++) {
102 cls.implementations.add(vcn.get_string_element(i));
108 if (value.get_object().has_member("tree_children")) {
109 var vcn = value.get_object().get_array_member("tree_children");
110 for (var i =0 ; i < vcn.get_length(); i++) {
111 var ad_c = vcn.get_string_element(i);
112 if (!cls.valid_cn.contains(ad_c)) {
113 cls.valid_cn.add( ad_c );
115 if (!add_to.has_key(ad_c)) {
116 add_to.set(ad_c, new Gee.ArrayList<string>());
118 if (!add_to.get(ad_c).contains(cls.name)) {
119 add_to.get(ad_c).add(cls.name);
129 if (value.get_object().has_member("tree_parent")) {
130 var vcn = value.get_object().get_array_member("tree_parent");
131 for (var i =0 ; i < vcn.get_length(); i++) {
132 if ("builder" == vcn.get_string_element(i)) {
133 // this class can be added to the top level.
134 GLib.debug("Add %s to *top", cls.name);
136 this.top_classes.add(cls.name);
143 this.classes.set(key, cls);
146 // look for properties of classes, that are atually clasess
147 // eg. Roo.data.Store has proxy and reader..
150 foreach(var cls in this.classes.values) {
151 foreach(var gir_obj in cls.props.values) {
152 var types = gir_obj.type.split("|");
153 for(var i =0; i < types.length; i++) {
156 if (/^Roo\./.match(type) && classes.has_key(type)) {
159 cls.valid_cn.add(type + ":" + gir_obj.name );
160 // Roo.bootstrap.panel.Content:east
161 // also means that Roo.bootstrap.panel.Grid:east works
162 var prop_type = classes.get(type);
163 foreach(var imp_str in prop_type.implementations) {
164 //GLib.debug("addChild for %s - child= %s:%s", cls.name, imp_str, gir_obj.name);
165 cls.valid_cn.add(imp_str + ":" + gir_obj.name);
166 if (!add_to.has_key(imp_str)) {
167 add_to.set( imp_str, new Gee.ArrayList<string>());
169 if (!add_to.get( imp_str).contains(cls.name)) {
170 add_to.get( imp_str ).add(cls.name );
176 if (!add_to.has_key( type)) {
177 add_to.set( type, new Gee.ArrayList<string>());
179 if (!add_to.get(type).contains(cls.name)) {
180 add_to.get( type ).add(cls.name );
187 foreach(var cls in this.classes.values) {
188 if (add_to.has_key(cls.name)) {
189 cls.can_drop_onto = add_to.get(cls.name);
196 public string doc(string what) {
198 /*var ns = what.split(".")[0];
203 var gir = Gir.factory(ns);
204 return gir.doc(what);
207 //return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
210 // does not handle implements...
211 public override GirObject? getClass(string ename)
214 return this.classes.get(ename);
218 public override Gee.HashMap<string,GirObject> getPropertiesFor(string ename, JsRender.NodePropType ptype)
220 //print("Loading for " + ename);
224 // if (typeof(this.proplist[ename]) != 'undefined') {
225 //print("using cache");
226 // return this.proplist[ename][type];
228 // use introspection to get lists..
231 var cls = this.classes.get(ename);
232 var ret = new Gee.HashMap<string,GirObject>();
234 print("could not find class: %s\n", ename);
236 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
241 //cls.parseSignals(); // ?? needed for add handler..
242 //cls.parseMethods(); // ?? needed for ??..
243 //cls.parseConstructors(); // ?? needed for ??..
245 //cls.overlayParent();
250 case JsRender.NodePropType.PROP:
252 case JsRender.NodePropType.LISTENER:
254 case JsRender.NodePropType.METHOD:
256 case JsRender.NodePropType.CTOR:
259 throw new Error.INVALID_VALUE( "getPropertiesFor called with: " + ptype.to_string());
260 //var ret = new Gee.HashMap<string,GirObject>();
266 //cls.overlayInterfaces(gir);
271 public string[] getInheritsFor(string ename)
274 var es = ename.split(".");
275 var gir = Gir.factory(null, es[0]);
277 var cls = gir.classes.get(es[1]);
281 return cls.inheritsToStringArray();
287 public override void fillPack(JsRender.Node node,JsRender.Node parent)
293 * Pulldown options for type
295 public override bool typeOptions(string fqn, string key, string type, out string[] opts)
298 print("get typeOptions %s (%s)%s", fqn, type, key);
299 if (type.up() == "BOOL" || type.up() == "BOOLEAN") {
300 opts = { "true", "false" };
304 var props = this.getPropertiesFor(fqn, JsRender.NodePropType.PROP);
305 if (!props.has_key(key)) {
306 print("prop %s does not have key %s\n", fqn, key);
309 var pr = props.get(key);
310 if (pr.optvalues.size < 1) {
311 print("prop %s no optvalues for %s\n", fqn, key);
315 for(var i = 0; i < pr.optvalues.size; i++) {
316 ret += pr.optvalues.get(i);
319 print("prop %s returning optvalues for %s\n", fqn, key);
323 public override List<SourceCompletionItem> suggestComplete(
324 JsRender.JsRender file,
326 JsRender.NodeProp? xxprop,
327 string complete_string
330 var ret = new List<SourceCompletionItem>();
331 // completion rules??
335 // this. (based on the node type)
336 // this.xxx // Node and any determination...
338 if (complete_string.index_of(".",0) < 0) {
339 // string does not have a '.'
340 // offer up this / Roo / javascript keywords... / look for var string = .. in the code..
341 for(var i = 0; i < JsRender.Lang.match_strings.size ; i++) {
342 var str = JsRender.Lang.match_strings.get(i);
343 if (complete_string != str && str.index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
344 ret.append(new SourceCompletionItem (str, str, null, "javascript : " + str));
349 if (complete_string != "Roo" && "Roo".index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
350 ret.append(new SourceCompletionItem ("Roo - A Roo class", "Roo", null, "Roo library"));
352 if (complete_string != "_this" && "_this".index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
353 ret.append(new SourceCompletionItem ("_this - the top level element", "_this", null, "Top level element"));
357 // got at least one ".".
358 var parts = complete_string.split(".");
360 var cur_instance = false;
361 if (parts[0] == "this") {
362 // work out from the node, what the type is...
364 print("node is empty - no return\n");
365 return ret; // no idea..
367 curtype = node.fqn();
370 if (parts[0] == "Roo") {
372 cur_instance = false;
375 var prevbits = parts[0] + ".";
376 for(var i =1; i < parts.length; i++) {
377 print("matching %d/%d\n", i, parts.length);
378 var is_last = i == parts.length -1;
380 // look up all the properties of the type...
381 var cls = this.getClass(curtype);
383 print("could not get class of curtype %s\n", curtype);
389 // only exact matches from here on...
391 if (cls.props.has_key(parts[i])) {
392 var prop = cls.props.get(parts[i]);
393 if (prop.type.index_of(".",0) > -1) {
394 // type is another roo object..
396 prevbits += parts[i] + ".";
404 // check methods?? - we do not export that at present..
405 return ret; //no idea...
409 //look for child classes.
410 var citer = this.classes.map_iterator();
412 while (citer.next()) {
413 var scls = citer.get_key();
414 var look = prevbits + parts[i];
415 if (scls.index_of(look,0) != 0) {
418 // got a starting match..
420 cur_instance = false;
427 prevbits += parts[i] + ".";
430 // got to the last element..
431 print("Got last element\n");
432 if (curtype == "") { // should not happen.. we would have returned already..
435 print("Got last element type %s\n",curtype);
437 print("matching instance");
438 // it's a static reference..
439 var citer = this.classes.map_iterator();
440 while (citer.next()) {
441 var scls = citer.get_key();
442 var look = prevbits + parts[i];
443 if (parts[i].length > 0 && scls.index_of(look,0) != 0) {
446 // got a starting match..
447 ret.append(new SourceCompletionItem (
455 print("matching property");
459 var citer = cls.methods.map_iterator();
460 while (citer.next()) {
461 var prop = citer.get_value();
462 // does the name start with ...
463 if (parts[i].length > 0 && prop.name.index_of(parts[i],0) != 0) {
466 // got a matching property...
468 ret.append(new SourceCompletionItem (
469 prop.name + prop.sig + " : ("+ prop.propertyof + ")",
470 prevbits + prop.name + "(",
475 // get the properties / methods and subclasses.. of cls..
476 // we have cls.. - see if the string matches any of the properties..
477 citer = cls.props.map_iterator();
478 while (citer.next()) {
479 var prop = citer.get_value();
480 // does the name start with ...
481 if (parts[i].length > 0 && prop.name.index_of(parts[i],0) != 0) {
484 // got a matching property...
486 ret.append(new SourceCompletionItem (
487 prop.name + " : " + prop.type + " ("+ prop.propertyof + ")",
488 prevbits + prop.name,
509 public override string[] getChildList(string in_rval)
511 if (this.top_classes.size < 1) {
517 var ar = this.top_classes;
518 if (in_rval != "*top") {
519 if (this.classes.has_key(in_rval)) {
520 // some of these children will be eg: Roo.bootstrap.layout.Region:center
521 ar = this.classes.get(in_rval).valid_cn;
523 ar = new Gee.ArrayList<string>();
527 foreach(var str in ar) {
530 GLib.debug("getChildList for %s returns %s", in_rval, string.joinv(", ", ret));
533 //return this.original_getChildList( in_rval);
535 public override string[] getDropList(string rval)
537 // we might be dragging Roo.bootstrap.layout.Region:center
538 // in which case we need to lookup Roo.bootstrap.layout.Region
539 // and see if it's has can_drop_onto
541 var cls = this.classes.get(rval);
543 if (cls == null && rval.contains(":")) {
544 var rr = rval.substring(0,rval.index_of(":"));
545 GLib.debug("Converted classname to %s", rr);
546 cls = this.classes.get(rr);
549 return ret; //nothing..
552 foreach(var str in cls.can_drop_onto) {
556 GLib.debug("getDropList for %s return[] %s", rval, string.joinv(", ", ret));
561 //return this.default_getDropList(rval);