java-gobject-introspection r137 - in trunk/src/org/gnome/gir: compiler gobject
- From: walters svn gnome org
- To: svn-commits-list gnome org
- Subject: java-gobject-introspection r137 - in trunk/src/org/gnome/gir: compiler gobject
- Date: Fri, 28 Nov 2008 02:36:24 +0000 (UTC)
Author: walters
Date: Fri Nov 28 02:36:24 2008
New Revision: 137
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=137&view=rev
Log:
Write out a static getGType method for boxeds
We need this in order to at runtime, determine the GType for a boxed
class. This comes up when we want to pass a boxed, say a Clutter.Color
as a GValue. If the boxed was constructed natively, we have to pass
the right GType to the GValue constructor.
Modified:
trunk/src/org/gnome/gir/compiler/CodeFactory.java
trunk/src/org/gnome/gir/gobject/GType.java
trunk/src/org/gnome/gir/gobject/GValue.java
Modified: trunk/src/org/gnome/gir/compiler/CodeFactory.java
==============================================================================
--- trunk/src/org/gnome/gir/compiler/CodeFactory.java (original)
+++ trunk/src/org/gnome/gir/compiler/CodeFactory.java Fri Nov 28 02:36:24 2008
@@ -1435,7 +1435,8 @@
mv.visitLocalVariable("mapper", Type.getDescriptor(TypeMapper.class), null, l0, l1, 0);
mv.visitMaxs(0, 0);
mv.visitEnd();
-
+
+ writeGetGType(info, compilation);
}
if (hasFields) {
Modified: trunk/src/org/gnome/gir/gobject/GType.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/GType.java (original)
+++ trunk/src/org/gnome/gir/gobject/GType.java Fri Nov 28 02:36:24 2008
@@ -45,6 +45,7 @@
package org.gnome.gir.gobject;
+import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
@@ -249,6 +250,14 @@
return new GType(value);
}
+ private static GType invokeGetGType(Class<?> klass) {
+ try {
+ return (GType) klass.getDeclaredMethod("getGType", new Class<?>[] {}).invoke(null, new Object[] {});
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
public static GType fromInstance(Object obj) {
if (obj instanceof Integer) {
return INT;
@@ -265,10 +274,16 @@
return objectPeekType(((GObject) obj).getNativeAddress());
} else if (obj instanceof GBoxed) {
return ((GBoxed) obj).getGType();
- } else if (obj instanceof BoxedStructure) {
- return ((BoxedStructure) obj).getGType();
- } else if (obj instanceof BoxedUnion) {
- return ((BoxedUnion) obj).getGType();
+ } else if (obj instanceof BoxedStructure || obj instanceof BoxedUnion) {
+ GType type;
+ if (obj instanceof BoxedStructure)
+ type = ((BoxedStructure) obj).getGType();
+ else
+ type = ((BoxedUnion) obj).getGType();
+ if (type.equals(GType.INVALID)) {
+ type = invokeGetGType(obj.getClass());
+ }
+ return type;
} else {
throw new IllegalArgumentException(String.format("Unhandled GType lookup for object %s", obj));
}
Modified: trunk/src/org/gnome/gir/gobject/GValue.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/GValue.java (original)
+++ trunk/src/org/gnome/gir/gobject/GValue.java Fri Nov 28 02:36:24 2008
@@ -70,6 +70,7 @@
throw new NullPointerException();
g_type = GType.INVALID;
GValueAPI.gvalue.g_value_init(this, type);
+ read();
}
public GValue(GType expected, Object object) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]