< prev index next >

src/java.base/share/classes/jdk/internal/foreign/Util.java

Print this page




 108         return Struct.class.isAssignableFrom(clz) &&
 109                 clz.isAnnotationPresent(NativeStruct.class);
 110     }
 111 
 112     public static boolean isCLibrary(Class<?> clz) {
 113         return clz.isAnnotationPresent(NativeHeader.class);
 114     }
 115 
 116     public static Class<?>[] resolutionContextFor(Class<?> clz) {
 117         if (isCallback(clz)) {
 118             return clz.getAnnotation(NativeCallback.class).resolutionContext();
 119         } else if (isCStruct(clz)) {
 120             return clz.getAnnotation(NativeStruct.class).resolutionContext();
 121         } else if (isCLibrary(clz)) {
 122             return clz.getAnnotation(NativeHeader.class).resolutionContext();
 123         } else {
 124             return null;
 125         }
 126     }
 127 
 128     public static Layout variadicLayout(Class<?> c) {
 129         c = (Class<?>)unboxIfNeeded(c);
 130         if (c == char.class || c == byte.class || c == short.class || c == int.class || c == long.class) {
 131             //it is ok to approximate with a machine word here; numerics arguments in a prototype-less
 132             //function call are always rounded up to a register size anyway.
 133             return Types.INT64;
 134         } else if (c == float.class || c == double.class) {
 135             return Types.DOUBLE;
 136         } else if (Pointer.class.isAssignableFrom(c)) {
 137             return Types.POINTER;
 138         } else if (isCallback(c)) {
 139             return Types.POINTER;
 140         } else if (isCStruct(c)) {
 141             return layoutof(c);
 142         } else {
 143             throw new IllegalArgumentException("Unhandled variadic argument class: " + c);
 144         }
 145     }
 146 
 147     public static Layout layoutof(Class<?> c) {
 148         String layout;
 149         if (c.isAnnotationPresent(NativeStruct.class)) {
 150             layout = c.getAnnotation(NativeStruct.class).value();
 151         } else {
 152             throw new IllegalArgumentException("@NativeStruct or @NativeType expected: " + c);
 153         }
 154         return new DescriptorParser(layout).parseLayout();
 155     }
 156 
 157     public static Function functionof(Class<?> c) {
 158         if (! c.isAnnotationPresent(NativeCallback.class)) {
 159             throw new IllegalArgumentException("@NativeCallback expected: " + c);
 160         }
 161         NativeCallback nc = c.getAnnotation(NativeCallback.class);
 162         return new DescriptorParser(nc.value()).parseFunction();
 163     }
 164 
 165     static MethodType methodTypeFor(Method method) {
 166         return MethodType.methodType(method.getReturnType(), method.getParameterTypes());




 108         return Struct.class.isAssignableFrom(clz) &&
 109                 clz.isAnnotationPresent(NativeStruct.class);
 110     }
 111 
 112     public static boolean isCLibrary(Class<?> clz) {
 113         return clz.isAnnotationPresent(NativeHeader.class);
 114     }
 115 
 116     public static Class<?>[] resolutionContextFor(Class<?> clz) {
 117         if (isCallback(clz)) {
 118             return clz.getAnnotation(NativeCallback.class).resolutionContext();
 119         } else if (isCStruct(clz)) {
 120             return clz.getAnnotation(NativeStruct.class).resolutionContext();
 121         } else if (isCLibrary(clz)) {
 122             return clz.getAnnotation(NativeHeader.class).resolutionContext();
 123         } else {
 124             return null;
 125         }
 126     }
 127 



















 128     public static Layout layoutof(Class<?> c) {
 129         String layout;
 130         if (c.isAnnotationPresent(NativeStruct.class)) {
 131             layout = c.getAnnotation(NativeStruct.class).value();
 132         } else {
 133             throw new IllegalArgumentException("@NativeStruct or @NativeType expected: " + c);
 134         }
 135         return new DescriptorParser(layout).parseLayout();
 136     }
 137 
 138     public static Function functionof(Class<?> c) {
 139         if (! c.isAnnotationPresent(NativeCallback.class)) {
 140             throw new IllegalArgumentException("@NativeCallback expected: " + c);
 141         }
 142         NativeCallback nc = c.getAnnotation(NativeCallback.class);
 143         return new DescriptorParser(nc.value()).parseFunction();
 144     }
 145 
 146     static MethodType methodTypeFor(Method method) {
 147         return MethodType.methodType(method.getReturnType(), method.getParameterTypes());


< prev index next >