java-gobject-introspection r6 - in trunk/src/org/gnome/gir: compiler gobject
- From: walters svn gnome org
- To: svn-commits-list gnome org
- Subject: java-gobject-introspection r6 - in trunk/src/org/gnome/gir: compiler gobject
- Date: Sun, 31 Aug 2008 19:21:54 +0000 (UTC)
Author: walters
Date: Sun Aug 31 19:21:54 2008
New Revision: 6
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=6&view=rev
Log:
Rework object construction a bit, turned out not to be the bug though
Modified:
trunk/src/org/gnome/gir/compiler/Test.java
trunk/src/org/gnome/gir/gobject/GObject.java
trunk/src/org/gnome/gir/gobject/GObjectAPI.java
Modified: trunk/src/org/gnome/gir/compiler/Test.java
==============================================================================
--- trunk/src/org/gnome/gir/compiler/Test.java (original)
+++ trunk/src/org/gnome/gir/compiler/Test.java Sun Aug 31 19:21:54 2008
@@ -127,4 +127,17 @@
Object[] args = new Object[] { GTypeInstance.peekInterface(this.handle(), Test.getGType()), blah };
f.invoke(Void.class, args, Internals.invocationOptions);
}
+
+ private static Object[] afoo(boolean foo, Object...args) {
+ return args;
+ }
+
+ private static int bar(String baz, Object...args) {
+ return args.length;
+ }
+
+ public static final void main(String... args) {
+ Object[] o = new Object[] { "hello", "world"};
+ System.out.printf("%d", bar("Moo", afoo(true, o)));
+ }
}
Modified: trunk/src/org/gnome/gir/gobject/GObject.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/GObject.java (original)
+++ trunk/src/org/gnome/gir/gobject/GObject.java Sun Aug 31 19:21:54 2008
@@ -48,6 +48,7 @@
import java.lang.reflect.Method;
import java.net.URI;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -83,38 +84,50 @@
}
}
- private static Object[] extendInitArgs(Object[] args) {
- Object[] ret;
- if (args == null) {
- ret = new Object[1];
- ret[0] = null;
- } else {
+ private static Initializer getInitializer(GType gtype, Object[] args) {
+ Object[] newArgs;
+ String firstProp = null;
+ if (args != null && args.length > 0) {
if ((args.length % 2) != 0)
throw new IllegalArgumentException("Number of construct parameters must be even");
- ret = new Object[args.length+1];
- System.arraycopy(args, 0, ret, 0, args.length);
- ret[args.length] = null;
+ firstProp = (String) args[0];
+ newArgs = new Object[args.length];
+ System.arraycopy(args, 1, newArgs, 0, args.length);
+ newArgs[args.length-1] = null;
+ } else {
+ newArgs = new Object[1];
+ newArgs[0] = null;
}
- return ret;
+ return new Initializer(GObjectAPI.gobj.g_object_new(gtype, firstProp, newArgs));
}
protected GObject(GType gtype, Object[] args) {
- this(new Initializer(GObjectAPI.gobj.g_object_new(gtype, extendInitArgs(args))));
+ this(getInitializer(gtype, args));
}
- private static Object[] initMapToObjectArray(Map<String,Object> args) {
- Object[] ret = new Object[args.size()*2];
+ private static Initializer getInitializer(GType gtype, Map<String,Object> args) {
+ String firstProp = null;
+ Object[] newArgs = new Object[args.size()*2];
int i = 0;
- for (Map.Entry<String, Object> arg : args.entrySet()) {
- ret[i] = arg.getKey();
- ret[i+1] = arg.getValue();
+ Iterator<Map.Entry<String, Object>> it = args.entrySet().iterator();
+ if (it.hasNext()) {
+ Map.Entry<String, Object> entry = it.next();
+ firstProp = entry.getKey();
+ newArgs[i] = entry.getValue();
+ i++;
+ }
+ while (it.hasNext()) {
+ Map.Entry<String, Object> entry = it.next();
+ newArgs[i] = entry.getKey();
+ newArgs[i+1] = entry.getValue();
i += 2;
}
- return ret;
+ newArgs[i] = null;
+ return new Initializer(GObjectAPI.gobj.g_object_new(gtype, firstProp, newArgs));
}
protected GObject(GType gtype, Map<String,Object> args) {
- this(gtype, initMapToObjectArray(args));
+ this(getInitializer(gtype, args));
}
GType getType(Class<?> klass) {
Modified: trunk/src/org/gnome/gir/gobject/GObjectAPI.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/GObjectAPI.java (original)
+++ trunk/src/org/gnome/gir/gobject/GObjectAPI.java Sun Aug 31 19:21:54 2008
@@ -68,7 +68,7 @@
void g_object_get_property(GObject obj, String property, GValue data);
void g_object_set(GObject obj, String propertyName, Object... data);
void g_object_get(GObject obj, String propertyName, Object... data);
- Pointer g_object_new(GType object_type, Object... args);
+ Pointer g_object_new(GType object_type, String firstParam, Object... args);
interface GClosureNotify extends Callback {
void callback(Pointer data, Pointer closure);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]