9 public class Introspect.El : Object
23 public class Roo : Palete {
36 Gee.HashMap<string,GirObject> propsFromJSONArray(string type, Json.Array ar, GirObject cls)
39 var ret = new Gee.HashMap<string,GirObject>();
41 for (var i =0 ; i < ar.get_length(); i++) {
42 var o = ar.get_object_element(i);
43 var name = o.get_string_member("name");
44 var prop = new GirObject(type, name );
46 prop.type = o.get_string_member("type");
47 prop.doctxt = o.get_string_member("desc");
48 prop.propertyof = o.has_member("memberOf") ? o.get_string_member("memberOf") : "";
49 if (prop.propertyof.length < 1) {
50 prop.propertyof = cls.name;
52 prop.sig = o.has_member("sig") ? o.get_string_member("sig") : "";
54 if (o.has_member("optvals") ) {
55 var oar = o.get_array_member("optvals");
57 for (var oi = 0; oi < oar.get_length(); oi++) {
58 prop.optvalues.add(oar.get_string_element(oi));
65 //print(type + ":" + name +"\n");
71 public override void load () {
73 if (this.classes != null) {
76 this.loadUsageFile(BuilderApplication.configDirectory() + "/resources/RooUsage.txt");
77 this.classes = new Gee.HashMap<string,GirObject>();
80 var pa = new Json.Parser();
81 pa.load_from_file(BuilderApplication.configDirectory() + "/resources/roodata.json");
82 var node = pa.get_root();
84 var clist = node.get_object().get_object_member("data");
85 clist.foreach_member((o , key, value) => {
86 //print("cls:" + key+"\n");
88 var cls = new GirObject("class", key);
89 cls.props = this.propsFromJSONArray("prop", value.get_object().get_array_member("props"),cls);
90 cls.signals = this.propsFromJSONArray("signal", value.get_object().get_array_member("events"),cls);
91 if (value.get_object().has_member("methods")) {
92 cls.methods = this.propsFromJSONArray("method", value.get_object().get_array_member("methods"),cls);
95 this.classes.set(key, cls);
104 public string doc(string what) {
106 /*var ns = what.split(".")[0];
111 var gir = Gir.factory(ns);
112 return gir.doc(what);
115 //return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
118 // does not handle implements...
119 public override GirObject? getClass(string ename)
122 return this.classes.get(ename);
126 public override Gee.HashMap<string,GirObject> getPropertiesFor(string ename, string type)
128 //print("Loading for " + ename);
132 // if (typeof(this.proplist[ename]) != 'undefined') {
133 //print("using cache");
134 // return this.proplist[ename][type];
136 // use introspection to get lists..
139 var cls = this.classes.get(ename);
140 var ret = new Gee.HashMap<string,GirObject>();
142 print("could not find class: %s\n", ename);
144 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
149 //cls.parseSignals(); // ?? needed for add handler..
150 //cls.parseMethods(); // ?? needed for ??..
151 //cls.parseConstructors(); // ?? needed for ??..
153 //cls.overlayParent();
167 throw new Error.INVALID_VALUE( "getPropertiesFor called with: " + type);
168 //var ret = new Gee.HashMap<string,GirObject>();
174 //cls.overlayInterfaces(gir);
179 public string[] getInheritsFor(string ename)
182 var es = ename.split(".");
183 var gir = Gir.factory(es[0]);
185 var cls = gir.classes.get(es[1]);
189 return cls.inheritsToStringArray();
195 public override void fillPack(JsRender.Node node,JsRender.Node parent)
201 * Pulldown options for type
203 public override bool typeOptions(string fqn, string key, string type, out string[] opts)
206 print("get typeOptions %s (%s)%s", fqn, type, key);
207 if (type.up() == "BOOL" || type.up() == "BOOLEAN") {
208 opts = { "true", "false" };
212 var props = this.getPropertiesFor(fqn, "props");
213 if (!props.has_key(key)) {
214 print("prop %s does not have key %s\n", fqn, key);
217 var pr = props.get(key);
218 if (pr.optvalues.size < 1) {
219 print("prop %s no optvalues for %s\n", fqn, key);
223 for(var i = 0; i < pr.optvalues.size; i++) {
224 ret += pr.optvalues.get(i);
227 print("prop %s returning optvalues for %s\n", fqn, key);
231 public override List<SourceCompletionItem> suggestComplete(
232 JsRender.JsRender file,
236 string complete_string
239 var ret = new List<SourceCompletionItem>();
240 // completion rules??
244 // this. (based on the node type)
245 // this.xxx // Node and any determination...
247 if (complete_string.index_of(".",0) < 0) {
248 // string does not have a '.'
249 // offer up this / Roo / javascript keywords... / look for var string = .. in the code..
250 for(var i = 0; i < JsRender.Lang.match_strings.size ; i++) {
251 var str = JsRender.Lang.match_strings.get(i);
252 if (complete_string != str && str.index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
253 ret.append(new SourceCompletionItem (str, str, null, "javascript : " + str));
258 if (complete_string != "Roo" && "Roo".index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
259 ret.append(new SourceCompletionItem ("Roo - A Roo class", "Roo", null, "Roo library"));
261 if (complete_string != "_this" && "_this".index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
262 ret.append(new SourceCompletionItem ("_this - the top level element", "_this", null, "Top level element"));
266 // got at least one ".".
267 var parts = complete_string.split(".");
269 var cur_instance = false;
270 if (parts[0] == "this") {
271 // work out from the node, what the type is...
273 print("node is empty - no return\n");
274 return ret; // no idea..
276 curtype = node.fqn();
279 if (parts[0] == "Roo") {
281 cur_instance = false;
284 var prevbits = parts[0] + ".";
285 for(var i =1; i < parts.length; i++) {
286 print("matching %d/%d\n", i, parts.length);
287 var is_last = i == parts.length -1;
289 // look up all the properties of the type...
290 var cls = this.getClass(curtype);
292 print("could not get class of curtype %s\n", curtype);
298 // only exact matches from here on...
300 if (cls.props.has_key(parts[i])) {
301 var prop = cls.props.get(parts[i]);
302 if (prop.type.index_of(".",0) > -1) {
303 // type is another roo object..
305 prevbits += parts[i] + ".";
313 // check methods?? - we do not export that at present..
314 return ret; //no idea...
318 //look for child classes.
319 var citer = this.classes.map_iterator();
321 while (citer.next()) {
322 var scls = citer.get_key();
323 var look = prevbits + parts[i];
324 if (scls.index_of(look,0) != 0) {
327 // got a starting match..
329 cur_instance = false;
336 prevbits += parts[i] + ".";
339 // got to the last element..
340 print("Got last element\n");
341 if (curtype == "") { // should not happen.. we would have returned already..
344 print("Got last element type %s\n",curtype);
346 print("matching instance");
347 // it's a static reference..
348 var citer = this.classes.map_iterator();
349 while (citer.next()) {
350 var scls = citer.get_key();
351 var look = prevbits + parts[i];
352 if (parts[i].length > 0 && scls.index_of(look,0) != 0) {
355 // got a starting match..
356 ret.append(new SourceCompletionItem (
364 print("matching property");
368 var citer = cls.methods.map_iterator();
369 while (citer.next()) {
370 var prop = citer.get_value();
371 // does the name start with ...
372 if (parts[i].length > 0 && prop.name.index_of(parts[i],0) != 0) {
375 // got a matching property...
377 ret.append(new SourceCompletionItem (
378 prop.name + prop.sig + " : ("+ prop.propertyof + ")",
379 prevbits + prop.name + "(",
384 // get the properties / methods and subclasses.. of cls..
385 // we have cls.. - see if the string matches any of the properties..
386 citer = cls.props.map_iterator();
387 while (citer.next()) {
388 var prop = citer.get_value();
389 // does the name start with ...
390 if (parts[i].length > 0 && prop.name.index_of(parts[i],0) != 0) {
393 // got a matching property...
395 ret.append(new SourceCompletionItem (
396 prop.name + " : " + prop.type + " ("+ prop.propertyof + ")",
397 prevbits + prop.name,