public Class[] getValidAnnotationTypes(Class type) { Class[] valid_types; if ( Buffer.class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) ) valid_types = getValidBufferTypes(type); else if ( type.isPrimitive() ) valid_types = getValidPrimitiveTypes(type); else if ( String.class.equals(type) ) valid_types = new Class[] { cl_byte.class }; else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) ) valid_types = new Class[] { PointerWrapper.class }; else if ( ByteBuffer[].class == type ) valid_types = new Class[] { cl_char.class, cl_uchar.class }; else if ( void.class.equals(type) ) valid_types = new Class[] { GLreturn.class }; else valid_types = new Class[] { }; return valid_types; }
public static String getMethodReturnType(MethodDeclaration method, GLreturn return_annotation, boolean buffer) { ParameterDeclaration return_param = null; for ( ParameterDeclaration param : method.getParameters() ) { if ( param.getSimpleName().equals(return_annotation.value()) ) { return_param = param; break; } } if ( return_param == null ) throw new RuntimeException("The @GLreturn parameter \"" + return_annotation.value() + "\" could not be found in method: " + method); PrimitiveType.Kind kind = NativeTypeTranslator.getPrimitiveKindFromBufferClass(Utils.getJavaType(return_param.getType())); if ( return_param.getAnnotation(GLboolean.class) != null ) kind = PrimitiveType.Kind.BOOLEAN; if ( kind == PrimitiveType.Kind.BYTE && (return_param.getAnnotation(GLchar.class) != null || return_param.getAnnotation(GLcharARB.class) != null) ) return "String"; else { final String type = JavaTypeTranslator.getPrimitiveClassFromKind(kind).getName(); return buffer ? Character.toUpperCase(type.charAt(0)) + type.substring(1) : type; } }
static boolean isReturnParameter(MethodDeclaration method, ParameterDeclaration param) { GLreturn string_annotation = method.getAnnotation(GLreturn.class); if ( string_annotation == null || !string_annotation.value().equals(param.getSimpleName()) ) return false; if ( param.getAnnotation(OutParameter.class) == null ) throw new RuntimeException("The parameter specified in @GLreturn is not annotated with @OutParameter in method: " + method); if ( param.getAnnotation(Check.class) != null ) throw new RuntimeException("The parameter specified in @GLreturn is annotated with @Check in method: " + method); if ( param.getAnnotation(GLchar.class) != null && Utils.getJavaType(param.getType()).equals(ByteBuffer.class) && string_annotation.maxLength().length() == 0 ) throw new RuntimeException("The @GLreturn annotation is missing a maxLength parameter in method: " + method); return true; }
static void printGLReturnPost(PrintWriter writer, MethodDeclaration method, GLreturn return_annotation, TypeMap type_map) { final String return_type = getMethodReturnType(method, return_annotation, true); if ( "String".equals(return_type) ) { writer.print("\t\t" + return_annotation.value() + ".limit("); final String offset = getStringOffset(method, null); if ( offset != null ) writer.print(offset + " + "); if ( return_annotation.forceMaxLength() ) writer.print(return_annotation.maxLength()); else writer.print(return_annotation.value() + "_length.get(0)"); writer.println(");"); writer.println("\t\treturn APIUtil.getString(" + type_map.getAPIUtilParam(true) + return_annotation.value() + ");"); } else { writer.print("\t\treturn " + return_annotation.value() + ".get(0)"); if ( "Boolean".equals(return_type) ) writer.print(" == 1"); writer.println(";"); } }
private static String getResultType(MethodDeclaration method, boolean native_stub) { if ( native_stub && method.getAnnotation(PointerWrapper.class) != null ) return "long"; else if ( !native_stub && method.getAnnotation(GLreturn.class) != null ) return Utils.getMethodReturnType(method, method.getAnnotation(GLreturn.class), false); else return Utils.getJavaType(Utils.getMethodReturnType(method)).getSimpleName(); }
static void printGLReturnPre(PrintWriter writer, MethodDeclaration method, GLreturn return_annotation, TypeMap type_map) { final String return_type = getMethodReturnType(method, return_annotation, true); if ( "String".equals(return_type) ) { if ( !return_annotation.forceMaxLength() ) { writer.println("IntBuffer " + return_annotation.value() + "_length = APIUtil.getLengths(" + type_map.getAPIUtilParam(false) + ");"); writer.print("\t\t"); } writer.print("ByteBuffer " + return_annotation.value() + " = APIUtil.getBufferByte(" + type_map.getAPIUtilParam(true) + return_annotation.maxLength()); /* Params that use the return buffer will advance its position while filling it. When we return, the position will be at the right spot for grabbing the returned string bytes. We only have to make sure that the original buffer was large enough to hold everything, so that no re-allocations happen while filling. */ final String offset = getStringOffset(method, null); if ( offset != null ) writer.print(" + " + offset); writer.println(");"); } else { final String buffer_type = "Boolean".equals(return_type) ? "Byte" : return_type; writer.print(buffer_type + "Buffer " + return_annotation.value() + " = APIUtil.getBuffer" + buffer_type + "(" + type_map.getAPIUtilParam(false)); if ( "Byte".equals(buffer_type) ) writer.print((type_map.getAPIUtilParam(false).length() > 0 ? ", " : "") + "1"); writer.println(");"); } final Code code_annotation = method.getAnnotation(Code.class); if ( code_annotation != null && code_annotation.tryBlock() ) { writer.println("\t\ttry {"); writer.print("\t\t\t"); } else writer.print("\t\t"); }
/** @deprecated Will be removed in 3.0. Use {@link #glGetQueryiARB} instead. */ @Alternate("glGetQueryivARB") @GLreturn("params") @StripPostfix("params") @Reuse(value = "ARBOcclusionQuery", method = "glGetQueryiARB") @Deprecated void glGetQueryivARB2(@GLenum int target, @GLenum int pname, @OutParameter IntBuffer params);
/** @deprecated Will be removed in 3.0. Use {@link #glGetRenderbufferParameteriEXT} instead. */ @Alternate("glGetRenderbufferParameterivEXT") @GLreturn("params") @StripPostfix("params") @Reuse(value = "EXTFramebufferObject", method = "glGetRenderbufferParameteriEXT") @Deprecated void glGetRenderbufferParameterivEXT2(@GLenum int target, @GLenum int pname, @OutParameter IntBuffer params);
/** @deprecated Will be removed in 3.0. Use {@link #glGetFramebufferAttachmentParameteriEXT} instead. */ @Alternate("glGetFramebufferAttachmentParameterivEXT") @GLreturn("params") @StripPostfix("params") @Reuse(value = "EXTFramebufferObject", method = "glGetFramebufferAttachmentParameteriEXT") @Deprecated void glGetFramebufferAttachmentParameterivEXT2(@GLenum int target, @GLenum int attachment, @GLenum int pname, @OutParameter IntBuffer params);
/** @deprecated Will be removed in 3.0. Use {@link #glGetFramebufferAttachmentParameteriOES} instead. */ @Alternate("glGetFramebufferAttachmentParameterivOES") @GLreturn("params") @StripPostfix("params") @Reuse(value = "OESFramebufferObject", method = "glGetFramebufferAttachmentParameteriOES") @Deprecated void glGetFramebufferAttachmentParameterivOES2(@GLenum int target, @GLenum int attachment, @GLenum int pname, @OutParameter IntBuffer params);
/** @deprecated Will be removed in 3.0. Use {@link #glGetRenderbufferParameteriOES} instead. */ @Alternate("glGetRenderbufferParameterivOES") @GLreturn("params") @StripPostfix("params") @Reuse(value = "OESFramebufferObject", method = "glGetRenderbufferParameteriOES") @Deprecated void glGetRenderbufferParameterivOES2(@GLenum int target, @GLenum int pname, @OutParameter IntBuffer params);
@Alternate("glGetCombinerInputParameterfvNV") @GLreturn("params") @StripPostfix(value = "params", postfix = "v") void glGetCombinerInputParameterfvNV2(@GLenum int stage, @GLenum int portion, @GLenum int variable, @GLenum int pname, @OutParameter FloatBuffer params);
@Alternate("glGetCombinerInputParameterivNV") @GLreturn("params") @StripPostfix(value = "params", postfix = "v") void glGetCombinerInputParameterivNV2(@GLenum int stage, @GLenum int portion, @GLenum int variable, @GLenum int pname, @OutParameter IntBuffer params);
@Alternate("glGetCombinerOutputParameterfvNV") @GLreturn("params") @StripPostfix(value = "params", postfix = "v") void glGetCombinerOutputParameterfvNV2(@GLenum int stage, @GLenum int portion, @GLenum int pname, @OutParameter FloatBuffer params);
@Alternate("glGetCombinerOutputParameterivNV") @GLreturn("params") @StripPostfix(value = "params", postfix = "v") void glGetCombinerOutputParameterivNV2(@GLenum int stage, @GLenum int portion, @GLenum int pname, @OutParameter IntBuffer params);
@Alternate("glGetFinalCombinerInputParameterfvNV") @GLreturn("params") @StripPostfix(value = "params", postfix = "v") void glGetFinalCombinerInputParameterfvNV2(@GLenum int variable, @GLenum int pname, @OutParameter FloatBuffer params);
@Alternate("glGetFinalCombinerInputParameterivNV") @GLreturn("params") @StripPostfix(value = "params", postfix = "v") void glGetFinalCombinerInputParameterivNV2(@GLenum int variable, @GLenum int pname, @OutParameter IntBuffer params);