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));
23 public abstract class GirBase : GirObject {
25 public abstract void load();
27 public string doc(string what)
29 var ar = what.split(".");
30 var cls = this.classes.get(ar[1]);
32 return cls.doctxt != null ? cls.doctxt : "";
34 // return the property.. by default..
35 var pr = cls.props.get(ar[2]);
36 return pr.doctxt != null ? pr.doctxt : "";
42 // Gir - is the libvala based version -
45 public class Gir : GirBase {
47 //Gee.Hashmap<string,what> nodes;
49 public Gir (string ns)
58 * == all static below here...
61 public static Gee.HashMap<string,Gir> cache = null;
64 public static GirBase? factory(string ns)
67 cache = new Gee.HashMap<string,Gir>();
68 var a = new Palete.VapiParser( );
69 a.create_valac_tree();
73 var ret = cache.get(ns);
76 var add = new Gir(ns);
80 var iter = add.classes.map_iterator();
82 iter.get_value().overlayParent();
84 // loop again and add the ctor properties.
85 iter = add.classes.map_iterator();
87 iter.get_value().overlayCtorProperties();
98 public static GirObject? factoryFqn(string fqn)
100 var bits = fqn.split(".");
101 if (bits.length < 1) {
105 var f = (GirObject)factory(bits[0]);
107 if (bits.length == 1 || f ==null) {
110 return f.fetchByFqn(fqn.substring(bits[0].length+1)); // since classes are stored in fqn format...?
117 * guess the fqn of a type == eg. gboolean or Widget etc...
119 public static string fqtypeLookup(string type, string ns) {
121 if (g.classes.has_key(type)) {
122 return ns + "." + type;
125 if (g.consts.has_key(type)) {
126 return ns + "." + type;
130 // look at includes..
131 var iter = g.includes.map_iterator();
133 // skip empty namespaces on include..?
134 if ( iter.get_key() == "") {
137 var ret = fqtypeLookup(type, iter.get_key());
148 // needed still - where's it called form..
149 public static string guessDefaultValueForType(string type) {
150 //print("guessDefaultValueForType: %s\n", type);
151 if (type.length < 1 || type.contains(".")) {
162 return "?"+ type + "?";