// t = coclass*
ICoClassDecl classdecl = comp.queryInterface(ICoClassDecl.class);
if(classdecl!=null) {
// bind to its default interface
ITypeDecl di = g.getDefaultInterface(classdecl);
if(di==null)
// no primary interface known. treat it as IUnknown
return new TypeBinding(Com4jObject.class, NativeType.ComObject, true);
else
return new TypeBinding( g.getTypeName(di), NativeType.ComObject, true );
}
IPrimitiveType compPrim = comp.queryInterface(IPrimitiveType.class);
if( compPrim!=null ) {
// T = PRIMITIVE*
if( compPrim.getVarType()== VarType.VT_VARIANT ) {
// T = VARIANT*
return new TypeBinding(Object.class, NativeType.VARIANT_ByRef, true);
}
if( compPrim.getVarType()==VarType.VT_VOID ) {
// T = void*
return new TypeBinding(Buffer.class, NativeType.PVOID, true );
}
if( compPrim.getVarType()==VarType.VT_UI2 ) {
// T = ushort*
if( isPsz(nameHint) )
// this is a common mistake
return new TypeBinding( String.class, NativeType.Unicode, false );
}
if( compPrim.getVarType()==VarType.VT_BOOL ) {
return new TypeBinding("Holder<Boolean>", NativeType.VariantBool_ByRef, true );
}
}
// a few other random checks
String name = getTypeString(ptrt);
if( name.equals("_RemotableHandle*") ) {
// marshal as the raw pointer value
return new TypeBinding( Integer.TYPE, NativeType.Int32, true );
}
if(name.equals("GUID*")) {
return new TypeBinding( "GUID", NativeType.GUID, true );
}
// otherwise use a holder
TypeBinding b = bind(g,comp,null);
if(b!=null && b.nativeType.byRef()!=null )
return b.createByRef();
}
ISafeArrayType at = t.queryInterface(ISafeArrayType.class);
if(at!=null) {
// T=SAFEARRAY(...)
IType comp = at.getComponentType();
IPrimitiveType compPrim = comp.queryInterface(IPrimitiveType.class);
if( compPrim!=null ) {
TypeBinding r = primitiveTypeBindings.get(compPrim.getVarType());
if(r!=null) {
return new TypeBinding(r.javaType+"[]", NativeType.SafeArray, true );
}
}
}
// T = typedef
ITypedefDecl typedef = t.queryInterface(ITypedefDecl.class);
if(typedef!=null) {
return bind(g,typedef.getDefinition(),nameHint);
}
// T = enum
IEnumDecl enumdef = t.queryInterface(IEnumDecl.class);
if(enumdef!=null) {
// TODO: we should probably check the size of the enum.
// there's no guarantee it's 32 bit.
return new TypeBinding( g.getTypeName(enumdef), NativeType.Int32, true );
}
// a few other random checks
String name = getTypeString(t);
if(name.equals("GUID")) {
return new TypeBinding( "GUID", NativeType.GUID, true );
}
ITypeDecl declt = t.queryInterface(ITypeDecl.class);
if(declt!=null) {
// TODO: not clear how we should handle this
throw new BindingException(Messages.UNSUPPORTED_TYPE.format(getTypeString(t)));
}