6 public class UsageMap : Object
8 Gee.HashMap<string,Gee.ArrayList<string>> implementors;
9 Gee.HashMap<string,string> childType;
10 Gee.HashMap<string,int> no_children;
11 Gee.HashMap<string,bool> is_abstract;
12 Gee.HashMap<string,Gee.ArrayList<string>> extends;
16 this.implementors = new Gee.HashMap<string,Gee.ArrayList<string>>();
17 this.extends = new Gee.HashMap<string,Gee.ArrayList<string>>();
18 this.childType = new Gee.HashMap<string,string>();
19 this.no_children = new Gee.HashMap<string,int>();
20 this.is_abstract = new Gee.HashMap<string,bool>();
21 var pa = new Json.Parser();
22 pa.load_from_file(BuilderApplication.configDirectory() + "/resources/flutter_tree.json");
24 var node = pa.get_root();
25 this.addArray(node.get_array());
27 this.removeNonChild();
31 private void addArray(Json.Array ar)
33 for(var i=0;i< ar.get_length(); i++) {
34 this.addObject(ar.get_object_element(i));
37 private void addObject(Json.Object o)
40 this.addArray(o.get_array_member("cn"));
42 var name = o.get_string_member("name");
43 if (!o.get_boolean_member("is_class")) {
46 if (o.get_array_member("implementors").get_length() > 0) {
47 this.implementors.set(name , this.jsonStringArray(o.get_array_member("implementors")));
49 if (o.get_array_member("extends").get_length() > 0) {
50 this.extends.set(name , this.jsonStringArray(o.get_array_member("extends")));
52 if (o.get_string_member("childtype").length > 0) {
53 this.childType.set( name, o.get_string_member("childtype"));
54 this.no_children.set( name, (int) o.get_int_member("childtypes"));
58 private Gee.ArrayList<string> jsonStringArray(Json.Array ar)
60 var ret = new Gee.ArrayList<string>();
61 for(var i=0;i< ar.get_length(); i++) {
62 ret.add(ar.get_string_element(i));
66 public void removeNonChild()
68 // do we need to clean this up?
69 // remove all the unrelated objects?
71 public Gee.ArrayList<string> possibleChildrenOf(string n)
73 GLib.debug("possibleChildrenOf %s", n);
74 var ret = new Gee.ArrayList<string>();
75 if (!this.childType.has_key(n)) {
79 var ch = this.childType.get(n);
80 GLib.debug("childType %s", ch);
82 if (this.is_abstract.has_key(ch) && !this.is_abstract.get(ch)) {
83 GLib.debug("add Implementor (self) %s", ch);
84 ret.add(ch); // it's not abstract...
87 if (!this.implementors.has_key(ch)) {
90 foreach(var k in this.implementors.get(ch)) {
91 GLib.debug("add Implementor %s", k);
96 public Gee.ArrayList<string> possibleParentsOf(string n)
99 // basically a list of all the types that accept this type, or it's parents..
100 // find a list of parents.
102 var ret = new Gee.ArrayList<string>();
103 if (!this.extends.has_key(n)) {
106 var ch = this.extends.get(n);
108 foreach(var k in this.childType.keys) {
109 if (ch.contains(this.childType.get(k))) {
118 public Gee.ArrayList<string> implementorsOf(string n)
120 var ret = new Gee.ArrayList<string>();
121 foreach(var k in this.implementors.get(n)) {
127 public bool is_a(string cls, string subclass) {
128 return this.extends.get(cls).contains(subclass);
133 foreach (var k in this.implementors.keys) {
134 GLib.debug("cls: %s : imps: %d", k, this.implementors.get(k).size);
136 foreach (var k in this.childType.keys) {
137 GLib.debug("cls: %s : child: %s", k, this.childType.get(k));
139 foreach (var k in this.extends.keys) {
141 foreach(var v in this.extends.get(k)) {
144 GLib.debug("cls: %s : extends: %s", k,s);
151 public class Flutter : Palete {
153 //public Gee.ArrayList<string> package_cache;
154 static UsageMap usagemap = null;
156 public Flutter(Project.Flutter project)
159 this.name = "Flutter";
160 //var context = new Vala.CodeContext ();
162 //this.package_cache = this.loadPackages(Path.get_dirname (context.get_vapi_path("glib-2.0")));
163 //this.package_cache.add_all(
164 // this.loadPackages(Path.get_dirname (context.get_vapi_path("gee-0.8")))
167 // various loader methods..
170 //this.proplist = {};
171 //this.comments = { };
172 if (Flutter.usagemap == null) {
173 Flutter.usagemap = new UsageMap();
177 public override void load () {
178 // in Roo & Gtk, usage is loaded here.. but it;s already called in the Ctor.??
179 //GLib.error("should not get here?");
182 public override GirObject? getClass(string ename)
185 GLib.error("not supported");
190 public override Gee.HashMap<string,GirObject> getPropertiesFor( string ename, string type)
193 GLib.error("not supported");
195 return new Gee.HashMap<string,GirObject>();
198 public override void fillPack(JsRender.Node node,JsRender.Node parent)
200 return; // flutter does not have pack...
202 public override bool typeOptions(string fqn, string key, string type, out string[] opts)
204 GLib.error("not supported");
208 public override List<SourceCompletionItem> suggestComplete(
209 JsRender.JsRender file,
213 string complete_string
215 return new List<SourceCompletionItem>();
217 Gee.HashMap<string,Gee.ArrayList<string>> implementors;
218 void loadFlutterUsageFile()
220 this.usagemap = new UsageMap();
223 public override string[] getChildList(string in_rval)
225 GLib.debug("getChildlist %s", in_rval);
227 // StatelessWidget (or a generic 'statefull_myname extends State<myname>')
228 //both have a single child that is a widget
229 if (in_rval == "*top") {
230 return { "widgets.StatelessWidget" , "widgets.StatefullWidget" };
232 Gee.ArrayList<string> ar = new Gee.ArrayList<string>();
233 if (in_rval == "widgets.StatelessWidget" || in_rval == "widgets.StatefullWidget") {
234 ar = this.usagemap.implementorsOf("widgets.Widget");
237 ar = this.usagemap.possibleChildrenOf(in_rval);
240 foreach(var k in ar) {
246 public override string[] getDropList(string rval)
248 var ar = this.usagemap.possibleParentsOf(rval);
249 if (this.usagemap.is_a(rval, "widgets.Widget")) {
250 ar.add("widgets.StatelessWidget");
251 ar.add( "widgets.StatefullWidget");
255 foreach(var k in ar) {
262 public void dumpusage()
264 this.usagemap.dump();