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 : "";
51 public void loadOverrides(bool force = false)
57 * == all static below here...
60 public static Gee.HashMap<string,Gir> cache = null;
63 public static Gir? factory(string ns)
66 cache = new Gee.HashMap<string,Gir>();
67 var a = new VapiParser( );
68 a.create_valac_tree();
72 var ret = cache.get(ns);
78 var add = new Gir(ns);
82 var iter = add.classes.map_iterator();
84 iter.get_value().overlayParent();
86 // loop again and add the ctor properties.
87 iter = add.classes.map_iterator();
89 iter.get_value().overlayCtorProperties();
96 if (ret != null && !ret.is_overlaid) {
97 var iter = ret.classes.map_iterator();
99 iter.get_value().overlayParent();
101 // loop again and add the ctor properties.
102 iter = ret.classes.map_iterator();
104 iter.get_value().overlayCtorProperties();
116 public static GirObject? factoryFqn(string fqn)
118 var bits = fqn.split(".");
119 if (bits.length < 1) {
123 var f = (GirObject)factory(bits[0]);
125 if (bits.length == 1 || f ==null) {
128 return f.fetchByFqn(fqn.substring(bits[0].length+1)); // since classes are stored in fqn format...?
135 * guess the fqn of a type == eg. gboolean or Widget etc...
137 public static string fqtypeLookup(string type, string ns) {
139 if (g.classes.has_key(type)) {
140 return ns + "." + type;
143 if (g.consts.has_key(type)) {
144 return ns + "." + type;
148 // look at includes..
149 var iter = g.includes.map_iterator();
151 // skip empty namespaces on include..?
152 if ( iter.get_key() == "") {
155 var ret = fqtypeLookup(type, iter.get_key());
166 // needed still - where's it called form..
167 public static string guessDefaultValueForType(string type) {
168 //print("guessDefaultValueForType: %s\n", type);
169 if (type.length < 1 || type.contains(".")) {
180 return "?"+ type + "?";