9 public class Introspect.El : Object
23 public class Roo : Palete {
36 Gee.HashMap<string,GirObject> propsFromJSONArray(string type, Json.Array ar)
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 prop.sig = o.has_member("sig") ? o.get_string_member("sig") : "";
51 if (o.has_member("optvals") ) {
52 var oar = o.get_array_member("optvals");
54 for (var oi = 0; oi < oar.get_length(); oi++) {
55 prop.optvalues.add(oar.get_string_element(oi));
62 //print(type + ":" + name +"\n");
68 public override void load () {
70 if (this.classes != null) {
73 this.loadUsageFile(BuilderApplication.configDirectory() + "/resources/RooUsage.txt");
74 this.classes = new Gee.HashMap<string,GirObject>();
77 var pa = new Json.Parser();
78 pa.load_from_file(BuilderApplication.configDirectory() + "/resources/roodata.json");
79 var node = pa.get_root();
81 var clist = node.get_object().get_object_member("data");
82 clist.foreach_member((o , key, value) => {
83 //print("cls:" + key+"\n");
85 var cls = new GirObject("class", key);
86 cls.props = this.propsFromJSONArray("prop", value.get_object().get_array_member("props"));
87 cls.signals = this.propsFromJSONArray("signal", value.get_object().get_array_member("events"));
89 this.classes.set(key, cls);
98 public string doc(string what) {
100 /*var ns = what.split(".")[0];
105 var gir = Gir.factory(ns);
106 return gir.doc(what);
109 //return typeof(this.comments[ns][what]) == 'undefined' ? '' : this.comments[ns][what];
112 // does not handle implements...
113 public override GirObject? getClass(string ename)
116 return this.classes.get(ename);
120 public override Gee.HashMap<string,GirObject> getPropertiesFor(string ename, string type)
122 //print("Loading for " + ename);
126 // if (typeof(this.proplist[ename]) != 'undefined') {
127 //print("using cache");
128 // return this.proplist[ename][type];
130 // use introspection to get lists..
133 var cls = this.classes.get(ename);
134 var ret = new Gee.HashMap<string,GirObject>();
136 print("could not find class: %s\n", ename);
138 //throw new Error.INVALID_VALUE( "Could not find class: " + ename);
143 //cls.parseSignals(); // ?? needed for add handler..
144 //cls.parseMethods(); // ?? needed for ??..
145 //cls.parseConstructors(); // ?? needed for ??..
147 //cls.overlayParent();
161 throw new Error.INVALID_VALUE( "getPropertiesFor called with: " + type);
162 //var ret = new Gee.HashMap<string,GirObject>();
168 //cls.overlayInterfaces(gir);
173 public string[] getInheritsFor(string ename)
176 var es = ename.split(".");
177 var gir = Gir.factory(es[0]);
179 var cls = gir.classes.get(es[1]);
183 return cls.inheritsToStringArray();
189 public override void fillPack(JsRender.Node node,JsRender.Node parent)
195 * Pulldown options for type
197 public override bool typeOptions(string fqn, string key, string type, out string[] opts)
200 print("get typeOptions %s (%s)%s", fqn, type, key);
201 if (type.up() == "BOOL" || type.up() == "BOOLEAN") {
202 opts = { "true", "false" };
206 var props = this.getPropertiesFor(fqn, "props");
207 if (!props.has_key(key)) {
208 print("prop %s does not have key %s\n", fqn, key);
211 var pr = props.get(key);
212 if (pr.optvalues.size < 1) {
213 print("prop %s no optvalues for %s\n", fqn, key);
217 for(var i = 0; i < pr.optvalues.size; i++) {
218 ret += pr.optvalues.get(i);
221 print("prop %s returning optvalues for %s\n", fqn, key);
225 public override List<SourceCompletionItem> suggestComplete(
226 JsRender.JsRender file,
230 string complete_string
233 var ret = new List<SourceCompletionItem>();
234 // completion rules??
238 // this. (based on the node type)
239 // this.xxx // Node and any determination...
241 if (complete_string.index_of(".",0) < 0) {
242 // string does not have a '.'
243 // offer up this / Roo / javascript keywords... / look for var string = .. in the code..
244 for(var i = 0; i < JsRender.Lang.match_strings.size ; i++) {
245 var str = JsRender.Lang.match_strings.get(i);
246 if (complete_string != str && str.index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
247 ret.append(new SourceCompletionItem (str, str, null, "javascript : " + str));
252 if (complete_string != "Roo" && "Roo".index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
253 ret.append(new SourceCompletionItem ("Roo", "Roo", null, "Roo library"));
258 // got at least one ".".
259 var parts = complete_string.split(".");
261 var cur_instance = false;
262 if (parts[0] == "this") {
263 // work out from the node, what the type is...
265 return ret; // no idea..
267 curtype = node.fqn();
270 if (parts[0] == "Roo") {
275 var prevbits = parts[0] + ".";
276 for(var i =0; i < parts.length; i++) {
277 var is_last = i == parts.length -1;
279 // look up all the properties of the type...
280 var cls = this.getClass(curtype);
289 // get the properties / methods and subclasses.. of cls..
295 // only exact matches from here on...
297 if (cls.props.has_key(parts[i])) {
298 var prop = cls.props.get(parts[i]);
299 if (prop.type.index_of(".",0) > -1) {
300 // type is another roo object..
301 currtype = prop.type;
306 // check methods?? - we do not export that at present..
307 return ret; //no idea...