public Object toNative(Object arg, ToNativeContext context) { if (arg == null) { return null; } Pointer ptr = ((NativeObject) arg).handle(); // // Deal with any adjustments to the proxy neccessitated by gstreamer // breaking their reference-counting idiom with special cases // if (context instanceof MethodParameterContext) { MethodParameterContext mcontext = (MethodParameterContext) context; Method method = mcontext.getMethod(); int index = mcontext.getParameterIndex(); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); if (index < parameterAnnotations.length) { Annotation[] annotations = parameterAnnotations[index]; for (int i = 0; i < annotations.length; ++i) { if (annotations[i] instanceof Invalidate) { ((Handle) arg).invalidate(); break; } else if (annotations[i] instanceof IncRef) { ((RefCountedObject) arg).ref(); break; } } } } return ptr; }