java-gobject-introspection r156 - trunk/src/gobject/internals



Author: walters
Date: Sun Jan  4 01:32:49 2009
New Revision: 156
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=156&view=rev

Log:
Peek at the gtype of interfaces as well as GObjects

If we do know about the concrete class implementing an interface
return type, return that instead of always returning an Anon.

This makes Gio.FileInfo.getIcon work sanely (you can instanceof
ThemedIcon etc.).

Modified:
   trunk/src/gobject/internals/NativeObject.java

Modified: trunk/src/gobject/internals/NativeObject.java
==============================================================================
--- trunk/src/gobject/internals/NativeObject.java	(original)
+++ trunk/src/gobject/internals/NativeObject.java	Sun Jan  4 01:32:49 2009
@@ -190,20 +190,15 @@
 	        		throw new RuntimeException(String.format("returned obj %s (%s) not instanceof %s", obj, obj.getClass(), cls));	        	
 	            return cls.cast(obj);
 	        }
-	       
-	        /* Special-case GObject.GObjectProxy here - these are interface values
-	         * for which we don't know of a current concrete class.
-	         */
-	        if (cls.isInterface() && GObject.GObjectProxy.class.isAssignableFrom(cls)) {
-	    		cls = (Class<T>) Internals.getStubClassFor(cls);        	
-	        }
-	        /* For GObject, read the g_class field to find
-	         * the most exact class match
-	         */        	
-	        else if (peekGType && GObject.class.isAssignableFrom(cls)) {
+	        
+	        boolean expectedGObject = GObject.class.isAssignableFrom(cls);
+	        boolean expectedGInterface = GObject.GObjectProxy.class.isAssignableFrom(cls);
+	         	
+	        if (peekGType && (expectedGObject || expectedGInterface)) {
+		        /* Read the g_class field to find the most exact class match */	
 	        	cls = classFor(ptr, cls);
-	        	/* If it's abstract, pull out the stub */
-	        	if ((cls.getModifiers() & Modifier.ABSTRACT) != 0)
+	        	/* If it's abstract or an interface, pull out the stub. */
+	        	if (cls.isInterface() || ((cls.getModifiers() & Modifier.ABSTRACT) != 0))
 	        		cls = (Class<T>) Internals.getStubClassFor(cls);
 	        }        
 	        /* Ok, let's try to find an Initializer constructor



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