Examples of FromNativeConverter


Examples of com.sun.jna.FromNativeConverter

  ToNativeConverter converter = new ObjCObjectTypeConverter(ObjCObject.class);
        assertEquals(null, converter.toNative(null, null));
    }
   
    @Test public void convertsReturnedIDToNSObjectSubclass() {
        FromNativeConverter converter = new ObjCObjectTypeConverter(NSNumber.class);
            // returning is based on declared type, see RococoaTypeMapper

  NSNumber number = Rococoa.create("NSNumber", NSNumber.class, "numberWithInt:", 45);

        // We can cope with 64 bits on 64 and 32
        Number nativeValue = new Long(number.id().longValue());
        NSNumber converted = (NSNumber) converter.fromNative(nativeValue, null);
        assertEquals(converted.id(), number.id());
        assertEquals(45, converted.intValue());       

        // We must cope with 32 bits on 32-bit
        if (NativeLong.SIZE == 4) {
            nativeValue = new Integer(number.id().intValue());
            converted = (NSNumber) converter.fromNative(nativeValue, null);
            assertEquals(45, converted.intValue());       
        }   
    }
View Full Code Here

Examples of com.sun.jna.FromNativeConverter

        }   
    }
   
    @Test public void convertsReturnedNilToNull() {
  // Again I'm not sure that this is desirable, but it is what happens.
        FromNativeConverter converter = new ObjCObjectTypeConverter(NSNumber.class);
        Number nativeValue = new Long(0);
        assertNull(converter.fromNative(nativeValue, null));
    }
View Full Code Here

Examples of com.sun.jna.FromNativeConverter

        Number nativeValue = new Long(0);
        assertNull(converter.fromNative(nativeValue, null));
    }
   
    @Test public void returnedNSObjectIsNormallyRetained() {
        FromNativeConverter converter = new ObjCObjectTypeConverter(NSNumber.class);

  NSNumber number = Rococoa.create("NSNumber", NSNumber.class, "numberWithInt:", 45);
  assertRetainCount(2, number); // one for the pool, one for Java

        NSNumber converted = (NSNumber) converter.fromNative(new Long(number.id().longValue()), null);
  assertRetainCount(3, converted); // now we have another Java alias
  assertRetainCount(3, number);
    }
View Full Code Here

Examples of jnr.ffi.mapper.FromNativeConverter

        }
    }

    static void emitFromNativeConversion(AsmBuilder builder, SkinnyMethodAdapter mv, FromNativeType fromNativeType, Class nativeClass) {
        // If there is a result converter, retrieve it and put on the stack
        FromNativeConverter fromNativeConverter = fromNativeType.fromNativeConverter;
        if (fromNativeConverter != null) {
            convertPrimitive(mv, nativeClass, unboxedType(fromNativeConverter.nativeType()), fromNativeType.nativeType);
            boxValue(builder, mv, fromNativeConverter.nativeType(), nativeClass);

            Method fromNativeMethod = getFromNativeMethod(fromNativeType, builder.getClassLoader());
            getfield(mv, builder, builder.getFromNativeConverterField(fromNativeConverter));
            mv.swap();
            if (fromNativeType.fromNativeContext != null) {
View Full Code Here

Examples of jnr.ffi.mapper.FromNativeConverter

        }
    }


    static Method getFromNativeMethod(FromNativeType fromNativeType, AsmClassLoader classLoader) {
        FromNativeConverter fromNativeConverter = fromNativeType.fromNativeConverter;
        if (fromNativeConverter == null) {
            return null;
        }

        try {
            Class<? extends FromNativeConverter> fromNativeConverterClass = fromNativeConverter.getClass();
            if (Modifier.isPublic(fromNativeConverterClass.getModifiers())) {
                for (Method method : fromNativeConverterClass.getMethods()) {
                    if (!method.getName().equals("fromNative")) continue;
                    Class[] methodParameterTypes = method.getParameterTypes();
                    Class javaType = fromNativeType.getDeclaredType().isPrimitive()
                            ? boxedType(fromNativeType.getDeclaredType())
                            : fromNativeType.getDeclaredType();
                    if (javaType.isAssignableFrom(method.getReturnType())
                            && methodParameterTypes.length == 2
                            && methodParameterTypes[0].isAssignableFrom(fromNativeConverter.nativeType())
                            && methodParameterTypes[1] == FromNativeContext.class
                            && methodIsAccessible(method)
                            && classIsVisible(classLoader, method.getDeclaringClass())) {
                        return method;
                    }
View Full Code Here

Examples of jnr.ffi.mapper.FromNativeConverter

    }

    static FromNativeType getParameterType(NativeRuntime runtime, Method m, int idx, TypeMapper typeMapper) {
        Annotation[] annotations = m.getParameterAnnotations()[idx];
        Class declaredJavaClass = m.getParameterTypes()[idx];
        FromNativeConverter converter = getFromNativeConverter(declaredJavaClass, annotations, typeMapper);
        Class javaClass = converter != null ? converter.nativeType() : declaredJavaClass;
        NativeType nativeType = InvokerUtil.getNativeType(runtime, javaClass, annotations);
        return new FromNativeType(declaredJavaClass, nativeType, annotations, converter);
    }
View Full Code Here

Examples of jnr.ffi.mapper.FromNativeConverter

        Class javaClass = converter != null ? converter.nativeType() : m.getReturnType();
        return jffiType(InvokerUtil.getNativeType(runtime, m.getReturnType(), m.getAnnotations()));
    }

    static com.kenai.jffi.Type getNativeParameterType(NativeRuntime runtime, Method m, int idx, TypeMapper typeMapper) {
        FromNativeConverter converter = getFromNativeConverter(m.getParameterTypes()[idx], m.getParameterAnnotations()[idx], typeMapper);
        Class javaClass = converter != null ? converter.nativeType() : m.getReturnType();
        return jffiType(InvokerUtil.getNativeType(runtime, m.getParameterTypes()[idx], m.getParameterAnnotations()[idx]));
    }
View Full Code Here

Examples of jnr.ffi.mapper.FromNativeConverter

        return jffiType(InvokerUtil.getNativeType(runtime, m.getParameterTypes()[idx], m.getParameterAnnotations()[idx]));
    }

    @SuppressWarnings("unchecked")
    static FromNativeConverter getFromNativeConverter(Class javaClass, Annotation[] annotations, TypeMapper typeMapper) {
        FromNativeConverter conv = typeMapper.getFromNativeConverter(javaClass);
        if (conv != null) {
            return conv;

        } else if (Enum.class.isAssignableFrom(javaClass)) {
            return EnumMapper.getInstance(javaClass.asSubclass(Enum.class));
View Full Code Here

Examples of jnr.ffi.mapper.FromNativeConverter

            }
        }

        String invokeMethod ;
        Class nativeReturnType;
        FromNativeConverter resultConverter = resultType.fromNativeConverter;
        Class javaReturnType = resultConverter != null
                ? resultConverter.nativeType() : resultType.getDeclaredType();

        if (NativeType.SCHAR == resultType.nativeType || NativeType.UCHAR == resultType.nativeType
            || NativeType.SSHORT== resultType.nativeType || NativeType.USHORT == resultType.nativeType
            || NativeType.SINT == resultType.nativeType || NativeType.UINT == resultType.nativeType
            || NativeType.VOID == resultType.nativeType) {
View Full Code Here

Examples of jnr.ffi.mapper.FromNativeConverter

            } else {
                convertPrimitive(mv, nativeParameterClasses[i], parameterClass, parameterType.nativeType);
            }

            // If there is a parameter converter, use it to convert the parameter to its java form
            FromNativeConverter fromNativeConverter = parameterTypes[i].fromNativeConverter;
            if (fromNativeConverter != null) {
                if (parameterClass.isPrimitive()) {
                    boxValue(mv, boxedType(parameterClass), parameterClass);
                }
                mv.aload(0);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.