java-gobject-introspection r116 - trunk/src/org/gnome/gir/gobject
- From: walters svn gnome org
- To: svn-commits-list gnome org
- Subject: java-gobject-introspection r116 - trunk/src/org/gnome/gir/gobject
- Date: Sat, 15 Nov 2008 22:21:21 +0000 (UTC)
Author: walters
Date: Sat Nov 15 22:21:20 2008
New Revision: 116
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=116&view=rev
Log:
Clean up GType API a bit, support GValue from object
Modified:
trunk/src/org/gnome/gir/gobject/BoxedStructure.java
trunk/src/org/gnome/gir/gobject/BoxedUnion.java
trunk/src/org/gnome/gir/gobject/GBoxed.java
trunk/src/org/gnome/gir/gobject/GType.java
trunk/src/org/gnome/gir/gobject/GValue.java
Modified: trunk/src/org/gnome/gir/gobject/BoxedStructure.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/BoxedStructure.java (original)
+++ trunk/src/org/gnome/gir/gobject/BoxedStructure.java Sat Nov 15 22:21:20 2008
@@ -23,6 +23,13 @@
isNative = true;
}
+ /**
+ * Return the GType associated with this boxed. Not intended for public use.
+ */
+ GType getGType() {
+ return gtype;
+ }
+
protected void free() {
GBoxedAPI.gboxed.g_boxed_free(gtype, this.getPointer());
}
Modified: trunk/src/org/gnome/gir/gobject/BoxedUnion.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/BoxedUnion.java (original)
+++ trunk/src/org/gnome/gir/gobject/BoxedUnion.java Sat Nov 15 22:21:20 2008
@@ -22,6 +22,13 @@
this.gtype = gtype;
isNative = true;
}
+
+ /**
+ * Return the GType associated with this boxed. Not intended for public use.
+ */
+ GType getGType() {
+ return gtype;
+ }
protected void free() {
GBoxedAPI.gboxed.g_boxed_free(gtype, this.getPointer());
Modified: trunk/src/org/gnome/gir/gobject/GBoxed.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/GBoxed.java (original)
+++ trunk/src/org/gnome/gir/gobject/GBoxed.java Sat Nov 15 22:21:20 2008
@@ -20,6 +20,13 @@
GBoxedAPI.gboxed.g_boxed_free(gtype, this.getPointer());
}
+ /**
+ * Return the GType associated with this boxed. Not intended for public use.
+ */
+ GType getGType() {
+ return gtype;
+ }
+
@Override
public void finalize() throws Throwable {
free();
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 Sat Nov 15 22:21:20 2008
@@ -45,7 +45,6 @@
package org.gnome.gir.gobject;
-import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@@ -200,20 +199,6 @@
return lookupProxyClass(gtype);
};
- /**
- * Find the associated GType of a class.
- * @param klass
- * @return
- */
- public static final <T extends RegisteredType> GType of(Class<T> klass) {
- try {
- Method m = klass.getMethod("getGType", new Class<?>[] {});
- return (GType) m.invoke(null, new Object[] {});
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
public static final void init() {
GObjectAPI.gobj.g_type_init();
}
@@ -262,22 +247,29 @@
}
return new GType(value);
}
- public static GType valueOf(Class<?> javaType) {
- if (Integer.class == javaType || int.class == javaType) {
+
+ public static GType fromInstance(Object obj) {
+ if (obj instanceof Integer) {
return INT;
- } else if (Long.class == javaType || long.class == javaType) {
+ } else if (obj instanceof Long) {
return INT64;
- } else if (Float.class == javaType || float.class == javaType) {
+ } else if (obj instanceof Float) {
return FLOAT;
- } else if (Double.class == javaType || double.class == javaType) {
+ } else if (obj instanceof Double) {
return DOUBLE;
- } else if (String.class == javaType) {
+ } else if (obj instanceof String) {
return STRING;
- } else if (GObject.class.isAssignableFrom(javaType)
- || GObject.GObjectProxy.class.isAssignableFrom(javaType)) {
- return OBJECT;
+ } else if (obj instanceof GObject
+ || obj instanceof GObject.GObjectProxy) {
+ 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 {
- throw new IllegalArgumentException("No GType for " + javaType);
+ 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 Sat Nov 15 22:21:20 2008
@@ -77,6 +77,10 @@
set(object);
}
+ public GValue(Object object) {
+ this(GType.fromInstance(object), object);
+ }
+
public void unset() {
GValueAPI.gvalue.g_value_unset(this.getPointer());
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]