Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to find an java-gnome type baed on an Introspection type?
/**
* Try to guess the real type for a given type with a name that is not
* enough for us.
*
* @param type
* the type to inspect.
* @param module
* the namespace currently inspected.
* @return a usable type.
*/
private static final String guessUsableType(String type, String module) {
String usable;
if (type.startsWith("GList-") || type.startsWith("GSList-")) {
return type.split("-")[0] + "-" + guessUsableType(type.split("-")[1], module);
}
if ((type.length() > 0) && !Character.isUpperCase(type.charAt(0))) {
/*
* Not a GObject thing.
*/
return type;
}
if (type.equals("GObject.Object") || type.equals("GObject.InitiallyUnowned")) {
/*
* This is a basic GObject.
*/
return "GObject";
}
if (type.equals("GdkPixbuf.Pixbuf")) {
/*
* This is a basic GdkPixbuf object.
*/
return "GdkPixbuf";
}
if (type.startsWith("GObject.")) {
return type.replace("GObject.", "G");
}
if (type.startsWith("Gio.")) {
return type.replace("Gio.", "G");
}
for (String m : modules) {
if (type.startsWith(m)) {
return type;
}
}
usable = new String(type);
if (usable.contains(".")) {
/*
* The type is in another module (but there are exceptions to
* handle).
*/
if (usable.startsWith("Gio.")) {
return type.replace("Gio.", "G");
} else {
return type.replace(".", "");
}
}
if (!usable.contains(".")) {
/*
* The type is in the same module so we append the module name.
*/
if (module.equals("GdkPixbuf")) {
usable = "Gdk" + type;
} else {
usable = module + type;
}
} else {
usable = type;
}
return usable;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment