java-gobject-introspection r4 - in trunk/src/org/gnome/gir: compiler gobject



Author: walters
Date: Sun Aug 31 17:47:00 2008
New Revision: 4
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=4&view=rev

Log:
Support using Map<String,Object> for constructors


Modified:
   trunk/src/org/gnome/gir/compiler/CodeFactory.java
   trunk/src/org/gnome/gir/compiler/Test.java
   trunk/src/org/gnome/gir/gobject/GObject.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	Sun Aug 31 17:47:00 2008
@@ -229,6 +229,9 @@
 	
 	private Type typeFromInfo(BaseInfo info) {
 		requireNamespaceOf(info);
+		/* Unfortunately, flags are best mapped as plain Integer  for now */
+		if (info instanceof FlagsInfo)
+			return Type.getObjectType("java/lang/Integer");
 		return Type.getObjectType(getInternalNameMapped(info.getNamespace(), info.getName()));		
 	}
 	
@@ -644,6 +647,25 @@
 		mv.visitMaxs(3, 2);
 		mv.visitEnd();
 		
+		mv = compilation.peer.writer.visitMethod(ACC_PUBLIC, "<init>", "(Ljava/util/Map;)V", 
+				"(Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;)V", null);
+		mv.visitCode();
+		l0 = new Label();
+		mv.visitLabel(l0);
+		mv.visitVarInsn(ALOAD, 0);
+		mv.visitMethodInsn(INVOKESTATIC, compilation.peer.internalName, "getGType", "()Lorg/gnome/gir/gobject/GType;");
+		mv.visitVarInsn(ALOAD, 1);
+		mv.visitMethodInsn(INVOKESPECIAL, parentInternalType, "<init>", "(Lorg/gnome/gir/gobject/GType;Ljava/util/Map;)V");
+		l1 = new Label();
+		mv.visitLabel(l1);
+		mv.visitInsn(RETURN);
+		l2 = new Label();
+		mv.visitLabel(l2);
+		mv.visitLocalVariable("this", "L"+ compilation.peer.internalName + ";", null, l0, l2, 0);
+		mv.visitLocalVariable("args", "Ljava/util/Map;", "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;)V", l0, l2, 1);
+		mv.visitMaxs(3, 2);
+		mv.visitEnd();		
+		
 		mv = compilation.peer.writer.visitMethod(ACC_PROTECTED, "<init>", "(Lorg/gnome/gir/gobject/GType;[Ljava/lang/Object;)V", null, null);
 		mv.visitCode();
 		l0 = new Label();
@@ -662,6 +684,26 @@
 		mv.visitLocalVariable("args", "[Ljava/lang/Object;", null, l0, l2, 2);
 		mv.visitMaxs(3, 3);
 		mv.visitEnd();
+		
+		mv = compilation.peer.writer.visitMethod(ACC_PROTECTED, "<init>", "(Lorg/gnome/gir/gobject/GType;Ljava/util/Map;)V", 
+				"(Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;)V", null);
+		mv.visitCode();
+		l0 = new Label();
+		mv.visitLabel(l0);
+		mv.visitVarInsn(ALOAD, 0);
+		mv.visitVarInsn(ALOAD, 1);
+		mv.visitVarInsn(ALOAD, 2);
+		mv.visitMethodInsn(INVOKESPECIAL, parentInternalType, "<init>", "(Lorg/gnome/gir/gobject/GType;Ljava/util/Map;)V");
+		l1 = new Label();
+		mv.visitLabel(l1);
+		mv.visitInsn(RETURN);
+		l2 = new Label();
+		mv.visitLabel(l2);
+		mv.visitLocalVariable("this", "L"+ compilation.peer.internalName + ";", null, l0, l2, 0);
+		mv.visitLocalVariable("gtype", "Lorg/gnome/gir/gobject/GType;", null, l0, l2, 1);		
+		mv.visitLocalVariable("args", "Ljava/util/Map;", "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;)V", l0, l2, 2);
+		mv.visitMaxs(3, 3);
+		mv.visitEnd();		
 	}
 	
 	private void compileStaticConstructor(ObjectInfo info, InfoCompilation compilation, FunctionInfo fi) {	

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 17:47:00 2008
@@ -66,12 +66,16 @@
 	}
 	
 	public Test() {
-		super(getGType(), null);
+		super(getGType(), (Object[])null);
 	}
 	
 	public Test(Object[] args) {
 		super(getGType(), args);
 	}
+	
+	public Test(Map<String,Object> args) {
+		super(getGType(), args);
+	}
 
     protected Test(Initializer init) { 
     	super(init);

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 17:47:00 2008
@@ -102,6 +102,21 @@
     	this(new Initializer(GObjectAPI.gobj.g_object_new(gtype, extendInitArgs(args))));
     }
     
+    private static Object[] initMapToObjectArray(Map<String,Object> args) {
+    	Object[] ret = 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();
+    		i += 2;
+    	}
+    	return ret;
+    }
+    
+    protected GObject(GType gtype, Map<String,Object> args) {
+    	this(gtype, initMapToObjectArray(args));
+    }
+    
     GType getType(Class<?> klass) {
     	return GType.OBJECT;
     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]