2 // valac -g --pkg gee-1.0 --pkg libxml-2.0 --pkg gobject-introspection-1.0 --pkg json-glib-1.0 Palete/Gir.vala -o /tmp/Gir
4 public static int main (string[] args) {
6 var g = Palete.Gir.factory("Gtk");
7 var test = g.classes.get("ToolButton");
10 var generator = new Json.Generator ();
11 var n = new Json.Node(Json.NodeType.OBJECT);
12 n.set_object(test.toJSON());
13 generator.set_root(n);
15 generator.pretty = true;
17 print(generator.to_data(null));
26 // Gir - is the libvala based version -
29 public class Gir : GirObject {
31 //Gee.Hashmap<string,what> nodes;
33 public Gir (string ns)
39 public string doc(string what)
41 var ar = what.split(".");
42 var cls = this.classes.get(ar[1]);
44 return cls.doctxt != null ? cls.doctxt : "";
46 // return the property.. by default..
47 var pr = cls.props.get(ar[2]);
48 return pr.doctxt != null ? pr.doctxt : "";
54 * == all static below here...
57 public static Gee.HashMap<string,Gir> cache = null;
60 public static Gir? factory(string ns)
63 cache = new Gee.HashMap<string,Gir>();
64 var a = new Palete.VapiParser( );
65 a.create_valac_tree();
69 var ret = cache.get(ns);
72 var add = new Gir(ns);
76 var iter = add.classes.map_iterator();
78 iter.get_value().overlayParent();
80 // loop again and add the ctor properties.
81 iter = add.classes.map_iterator();
83 iter.get_value().overlayCtorProperties();
94 public static GirObject? factoryFqn(string fqn)
96 var bits = fqn.split(".");
97 if (bits.length < 1) {
101 var f = (GirObject)factory(bits[0]);
103 if (bits.length == 1 || f ==null) {
106 return f.fetchByFqn(fqn.substring(bits[0].length+1)); // since classes are stored in fqn format...?
113 * guess the fqn of a type == eg. gboolean or Widget etc...
115 public static string fqtypeLookup(string type, string ns) {
117 if (g.classes.has_key(type)) {
118 return ns + "." + type;
121 if (g.consts.has_key(type)) {
122 return ns + "." + type;
126 // look at includes..
127 var iter = g.includes.map_iterator();
129 // skip empty namespaces on include..?
130 if ( iter.get_key() == "") {
133 var ret = fqtypeLookup(type, iter.get_key());
144 // needed still - where's it called form..
145 public static string guessDefaultValueForType(string type) {
146 //print("guessDefaultValueForType: %s\n", type);
147 if (type.length < 1 || type.contains(".")) {
158 return "?"+ type + "?";