public Object fromNative(Object result, FromNativeContext context) { if (result == null) { return null; } if (context instanceof MethodResultContext) { MethodResultContext functionContext = (MethodResultContext) context; Method method = functionContext.getMethod(); Pointer ptr = (Pointer) result; String s = ptr.getString(0); if (method.isAnnotationPresent(FreeReturnValue.class) || method.isAnnotationPresent(CallerOwnsReturn.class)) { GlibAPI.GLIB_API.g_free(ptr); } return s; } else { return ((Pointer) result).getString(0); } }
@SuppressWarnings(value = "unchecked") public Object fromNative(Object result, FromNativeContext context) { if (result == null) { return null; } if (context instanceof FunctionResultContext) { return NativeObject.Internals.objectFor((Pointer) result, context.getTargetType(), true); } if (context instanceof CallbackParameterContext || context instanceof StructureReadContext) { return NativeObject.Internals.objectFor((Pointer) result, context.getTargetType(), false); } if (context instanceof MethodResultContext) { throw new RuntimeException("Got illegal MethodResultContext in GTypeMapper"); } throw new IllegalStateException("Cannot convert to NativeObject from " + context); }